Error when doing distance calculation

14 views
Skip to first unread message

ckgoo...@gmail.com

unread,
Sep 29, 2024, 12:46:06 PMSep 29
to spatiali...@googlegroups.com

Hi, in my C++ application I  make many calls to my Spatialite database and then all work fine.  I use prepared statements and bind values, call Step, and go through the results.  All great.

But I have the following statement which is giving me a “No database context” error which I don’t really know what it means.  But I know the database is fine and working as other calls work okay.

The statement is:

SELECT ST_Distance( ST_Transform( MakePoint( ?,?, 4326), 32631), ST_Transform( MakePoint( ?, ?, 4326), 32631) ) / 1000 AS distance;

 

This statement runs fine in the command line interface.  The prepare works without error.  It just doesn’t like it at run-time.

Does anyone have thoughts on what might be the problem?

It is just doing a calculation and not retrieving any data but does that make a difference?

Best, Chris

 

a.fu...@lqt.it

unread,
Sep 29, 2024, 1:14:08 PMSep 29
to spatiali...@googlegroups.com
Hi Chris,

I assume that you are working in Windows and that you are using
a recent version of libproj.
This library is used internally by ST_Transform() to calculate all
the transformations of the coordinates between different reference
systems.

Modern versions of libproj require access to their SQLite DB where
all the numerous geodetic parameters are recorded.
If such auxiliary DB is not reachable then libproj fails and emits
an error message, which is exactly what is happening to you.

You can learn more about this topic by reading here:
https://www.gaia-gis.it/fossil/libspatialite/wiki?name=PROJ.6

Note: everything works perfectly on Linux, but unfortunately on
Windows it can be decidedly mangy.

The simplest and most direct solution is to copy the libproj DB
directly into the same folder where your C++ EXE is located.
You should find a copy of the libproj DB inside the folder where
the command line EXE is installed.
The file is named "proj.db" and has a size of approximately 8 MB

I wish you good luck,
Sandro

ckgoo...@gmail.com

unread,
Sep 29, 2024, 3:28:20 PMSep 29
to spatiali...@googlegroups.com
Hi Sandro,
Thanks for your quick reply and your quick solution works. I copied the *Mb proj.db into my folder with my .exe and it does the calculation fine. Many thanks.

On reading the page you linked to, it says an attempt to connect to proj.db is made via the same folder as spatialite.exe. This This folder is where I copied the proj.db file from so surprised it isn't picking it up. Is it a surprise to you? Perhaps I unwittingly have more than one spatialite.exe on my system.

Many thanks, Chris
--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spatialite-users/c4067b8885b19f802e63775afbb44f7a%40lqt.it.

a.fu...@lqt.it

unread,
Sep 29, 2024, 3:51:30 PMSep 29
to spatiali...@googlegroups.com
On Sun, 29 Sep 2024 19:39:23 +0100, ckgoo...@gmail.com wrote:
> On reading the page you linked to, it says an attempt to connect to
> proj.db is made via the same folder as spatialite.exe. This This
> folder is where I copied the proj.db file from so surprised it isn't
> picking it up. Is it a surprise to you? Perhaps I unwittingly have
> more than one spatialite.exe on my system.
>

Hi Chris,

I'm sorry for any possible misunderstunding.

The rule on Windows simply states that libproj will first look
for its geodetic DB in the same folder from where the EXE
itself was loaded. The name of the EXE is completely
irrelevant.

In that example we were talking about spatialite.exe
and it came natural to me to quote the name in full;
but then again, the name means nothing and
spatialite.exe has nothing special about it;
for Windows it's simply an EXE like any other.

bye Sandro

ckgoo...@gmail.com

unread,
Sep 29, 2024, 5:24:33 PMSep 29
to spatiali...@googlegroups.com
Hi, I understand. It works from the Spatialite command line because proj.db is in the same folder as it.
By putting it in my own application's folder it also works.
So if I ever redistribute my application I've have to include this proj.db also.
Thanks, Chris

-----Original Message-----
From: spatiali...@googlegroups.com <spatiali...@googlegroups.com> On Behalf Of a.fu...@lqt.it
--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spatialite-users/1c6cc09ff70bd55363563bba8ebeb4e6%40lqt.it.

Reply all
Reply to author
Forward
0 new messages