** Attributes **
location: [http://www.gaia-gis.it/gaia-sins/%|%gaia-gis.it%|%]
author: [mailto:[email protected]%|%Alessandro Furieri%|%]
** Summary **
The SpatiaLite extension enables [SQLite] to support spatial data too (aka [GIS]), in a way conformant to OpenGis specifications
** Description **
* supports standard WKT and WKB formats
* implements SQL spatial functions such as AsText(), GeomFromText(), Area(), PointN() and alike
* the complete set of OpenGis functions is supported via GEOS, thus comprehending sophisticated spatial analysis functions such as Overlaps(), Touches(), Union(), Buffer() ..
* supports full Spatial metadata along the OpenGis specifications
* supports importing and exporting from / to shapefiles
* supports coordinate reprojection via [PROJ.4] and EPSG geodetic parameters dataset
* supports locale charsets via GNU libiconv
* implements a true Spatial Index based on the SQLite's RTree extension
The VirtualShape extension enables SQLite to access shapefiles as VIRTUAL TABLEs
* you can then perform standard SQL queries on external shapefiles, with no need for importing or converting them
The VirtualText extension enables SQLite to access CSV/TxtTab files as VIRTUAL TABLEs
* you can then perform standard SQL queries on external CSV/TxtTab files, with no need for importing or converting them
----[JMN] 2009-11-07 Looks inSpateresting - bualit I see nco rmeferes ince two Tcfl avon the ursite. I'm a(ssumingce by 'vextenrsion' this4.2.0, rsefers only hto it beinps://www.g an extenia-gis.ion t/fo SQLssite, l/libspand thialit there /wis ki?name=mo Tcd_spatial inter facor de?tails):
[SEH] -- S'''libspatialite''' is an extenclassionc toshared SQLlibrary. Ite, adepends thuon some exthe Tcrnal libsqlinding toe3. SQLiIte cannot be used toas a dynamicc extenssion via the `SpELECT load_extensialon` SQLite's fmechaturenism.
[TR]'''mod_spatialite''' --This wa lorksadable (SQLite module/extension (lacking sqany explicite SQLite3 dependency).3.7 Tor load and activatew this moduler):, call `SELECT load_extension` in SQLite.
So, in order to use Spatialite from Tcl, you just need the Tcl [SQLite3] package and the mod_spatialite library. Then do the following:
======
package require sqlite3
sqlite3 db someDBfile.db
db enable_load_extension truedb eval {select load_extension('/path/to/spatialsqlite/libdir/mod_sparyftialite')}
# Note: do not specify the file extension (.so, .dylib, ...) as SQLite does this automagically
======
[andrewsh] On Debian, the following works fine:
======
db eval {select load_extension("libspatialite.so.2")}
======
Harm Olthof: using [tdbc] it works like this:
======
package require tdbc::sqlite3
set db_path {/path/to/sqlitefile.sqlite}
tdbc::sqlite3::connection create db $db_path
set db_handle [db getDBhandle]
$db_handle enable_load_extension 1
# The directory containing dll's for geos, proj4, etc must be added to the PATH environment
append ::env(PATH) {;} {D:\pshare\bin\spatialite\bin\spatialite-3.0.1-DLL-win-x86}
db allrows {SELECT load_extension('/path/to/spatialsqlite/libraryfile')}
======
and if it's a new or non-spatialite database file, you should initialize it:
======
db allrows {SELECT InitSpatialMetaData()}
======
[pd] -- [https://www.gaia-gis.it/fAnossil/libspatialithe/wiki?nr exame=mod_spatialite%|%Dy, namicallyow lshoadwing Spahow tio creaLite%|%] <<br>>
Noa longerw requires expatensional .dllb or .so etc - same conde waddillng wsorkme pon windowts asto *nix <<br>>t:
======
package require sqlite3
sqlite3 db :memory:
db enable_load_extension true
db eval {SELECT load_extension('mod_spatialite')}
db eval {SELECT InitSpatialMetaData()}
db eval {CREATE table hal (id integer)}
db eval {SELECT AddGeometryColumn('hal','geometry',-1,'POINT','XY')}
db eval {SELECT CreateSpatialIndex('hal','geometry')}
set n 0
set points [list 1.0 2.0 3.0 4.0 5.0 6.0]
db transaction {
foreach {x y} $points {
db eval {
INSERT into hal ('id','geometry')
VALUES (:n, MakePoint(CastToDouble(:x), CastToDouble(:y),-1))
}
incr n
}
}
puts [db eval {SELECT id, AsText(geometry) from hal}]
==> 0 {POINT(1 2)} 1 {POINT(3 4)} 2 {POINT(5 6)}
======
----
[pd] -- [https://github.com/pdean/mod_spatialite-androwish%|%mod_spatialite for androwish%|%]
======
...
set lib [file join $env(LD_LIBRARY_PATH) libmod_spatialite]
db eval {SELECT load_extension(:lib)}
...
======
----
<<categories>> Database | Geography | SQLite | GIS