Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-11

Spatialite (a GIS extension to Sqlite) & SQLite Load_extension

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Hi all,

I'm looking into getting road, vegetation, building etc. data from OpenStreetmap and generating a map for the Rigs of Rods truck/driving/flight/boat simulator.... using FPC/Lazarus if possible.

I've found Spatialite [1], an extension to the SQLite database engine, that allows e.g. easy import of Openstreetmap data, routing, and coordinate conversion (I intend to convert the WGS 84 coordinates into a flat coordinate system).

1. Has anybody used spatialite within FreePascal/Lazarus? Any hints/tips/example programs I can stea... use?

2. You can apparently load the spatialite (and dependencies) dll/so as an extension to SQLite, with a statement like [3]
select load_extension('libspatialite-4.dll');
However, it seems you have to enable the extension load mechanism first using the C API [2]:
int sqlite3_enable_load_extension(sqlite3 *db, int onoff); (onoff==1 to turn extension loading on)
Is there support for this within FPC?
I found sqlite3_enable_load_extension within
packages/sqlite/src/sqlite3.inc, but it doesn't seem to be used... Would I need to edit sqlite3conn.pp to add support for loading extensions?

Thanks,
Reinier

[1] http://www.gaia-gis.it/spatialite/index.html
[2] http://www.sqlite.org/c3ref/enable_load_extension.html [3] http://www.sqlite.org/lang_corefunc.html#load_extension

Reply by email

Reinier Olislagers
to Reinier Olislagers
Reinier Olislagers wrote 7 lines
2. You can apparently load the spatialite (and dependencies) dll/so as an extension to SQLite, with a statement like [3] select load_extension('libspatialite-4.dll'); However, it seems you have to enable the extension load mechanism first using the C API [2]: int sqlite3_enable_load_extension(sqlite3 *db, int onoff); (onoff==1 to turn extension loading on)
Attached diff (against fixes_2_6) seems to work for letting SQLite load
the libspatialite extension, e.g. using this in my Lazarus FormCreate event:
// Try to load extensions
DBConnection.DatabaseName:='osm.sqlite';
DBConnection.Open;
DBConnection.LoadExtension('libspatialite-4.dll');
//Note: we need an open db before doing this

Now I'm getting an error message saying that libfreexl-1.dll can't be found, apparently an Excel reader library required by spatialite... I'm going to ask the spatialite guys for clarification on this...

I'll upload the diff as a patch unless somebody has objections/a better implementation...

Thanks,

Reinier

Reply by email

Unknown author
to Reinier Olislagers
Reinier Olislagers wrote 23 lines
On 7-11-2011 8:23, Reinier Olislagers wrote: > 2. You can apparently load the spatialite (and dependencies) dll/so as > an extension to SQLite, with a statement like [3] > select load_extension('libspatialite-4.dll'); > However, it seems you have to enable the extension load mechanism first > using the C API [2]: > int sqlite3_enable_load_extension(sqlite3 *db, int onoff); > (onoff==1 to turn extension loading on) Attached diff (against fixes_2_6) seems to work for letting SQLite load the libspatialite extension, e.g. using this in my Lazarus FormCreate event: // Try to load extensions DBConnection.DatabaseName:='osm.sqlite'; DBConnection.Open; DBConnection.LoadExtension('libspatialite-4.dll'); //Note: we need an open db before doing this Now I'm getting an error message saying that libfreexl-1.dll can't be found, apparently an Excel reader library required by spatialite... I'm going to ask the spatialite guys for clarification on this... I'll upload the diff as a patch unless somebody has objections/a better implementation...

Uploading the diff should be fine.

Michael.

Reply by email

Reinier Olislagers
to Unknown author
On Mon, 7 Nov 2011, Reinier Olislagers wrote: > On 7-11-2011 8:23, Reinier Olislagers wrote: > Attached diff (against fixes_2_6) seems to work for letting SQLite load > the libspatialite extension

<snip>

Show quoted text 6 lines
> I'll upload the diff as a patch unless somebody has objections/a better > implementation... Uploading the diff should be fine. Michael.

Thanks, Michael, issue 20640.

Reply by email