On Sun, 28 Jul 2024 21:30:17 +0100,
ckgoo...@gmail.com wrote:
> Thanks Sandro. I'll stick with the simpler one that works.
>
> I'm now starting my journey to discover how Spatialite works by
> reading the tutorial. I am a C++ programmer and I've done SQL in
> the
> past so I hope it will be not too difficult. I need to learn how to
> convert the OSM water polygon shapefiles into Spatialite so I can
> quickly test if a coordinate is in the sea or not. Other things I
> will
> want to do are to convert OSM data into Spatialite and query what
> admin area I am in, what town or cities are nearby to my user's
> coordinates and I am sure lots of other things. Quite a long road
> but
> I think Spatialite is the right tool for me.
>
Hi Chris,
just a few very general suggestions to make your way easier.
1. force yourself to get into the habit of writing as much
of SQL code and as little C++ as possible
2. ideally the C++ code should be limited to being a thread
that stitches the various SQL queries together
3. Typical tasks to do in C++:
* generating the text of SQL queries
* executing such queries fetching data from the
returned resultset.
* displaying the results on the screen
4. Prepared Statements should be studied very well because
they are a truly powerful tool.
https://www.sqlite.org/c3ref/stmt.html
5. Don't neglect Parametric Queries and the sqlite3_bind_xxx()
C-APIs because they are absolutely fundamental for
efficiently embedding easily reusable SQL queries
in the body of C++ functions.
6. take all the time you need to familiarize yourself with
the over 500 SQL Spatial functions supported by SpatiaLite.
https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.1.0.html
The last and most fundamental of all pieces of advice.
Never give in to the temptation to write your SQL queries
directly inside your C/C++ code, because then debugging
could easily turn out to be a real nightmare.
Instead, get into the healthy habit of testing every single
query in a pure SQL environment, and then embed your SQL code
in C/C++ only after having thoroughly tested and tuned it.
Finally, just a few words on how to obtain fast and snappy
applications.
Writing overly complex SQL queries is always a recipe
for disaster.
Breaking a complex problem into many small, very simple
elementary problems is always the secret of speed.
Learn to intelligently use TEMPORARY TABLES as a parking
area where storing partial results and then assemble
everything together only in the last final step.
Good luck, and above all have fun :-D
bye Sandro