Getting GeoDjango + Spatialite running on Windows
Asked Answered
D

2

6

I continue to have problems setting up a GeoDjango installation that uses Spatialite as a backend on a Windows machine.

I used the GeoDjango installer and downloaded the precompiled libraries from http://www.gaia-gis.it/spatialite/binaries.html, and dumped them into my geodjango/bin directory.

I upgraded my pysqlite2 installation to the newest version, so that extensions can be loaded and I specified SPATIALITE_LIBRARY_PATH in my settings file.

When I run manage syncdb I get the following output

C:\stuff>manage.py syncdb
SpatiaLite version ..: 2.3.1    Supported Extensions:
        - 'VirtualShape'        [direct Shapefile access]
        - 'VirtualText'         [direct CSV/TXT access]
        - 'VirtualNetwork       [Dijkstra shortest path]
        - 'RTree'               [Spatial Index - R*Tree]
        - 'MbrCache'            [Spatial Index - MBR cache]
        - 'VirtualFDO'          [FDO-OGR interoperability]
        - 'SpatiaLite'          [Spatial SQL - OGC]
PROJ.4 Rel. 4.6.1, 21 August 2008
GEOS version 3.0.2-CAPI-1.4.2

However, when setting up the indices for the table I get the following message:

...
Installing custom SQL for core.LocationHint model
updateTableTriggers: "no such module: rtree"
...

I tried to ignore the message, however my models would not save correctly.

I am a little baffled, because the Spatialite library seems to be used and has the "RTree" extension enabled, yet I still get the error message. There is not much information about this error available online; I found the RTree Documentation at sqlite.org/rtree.html, however I was under the impression that it is already included in spatialite because it is listet under "supported extensions".

Do I really need to compile my own sqlite library? Can somebody provide a .dll that already has RTree included? Am I doing something completely wrong? Any help is appreciated, thanks!

Dubai answered 25/11, 2009 at 23:11 Comment(1)
Forgot versions: Python 2.6.4 on Windows7 32 Django Trunk Spatialite 2.3.1Dubai
C
1

Hans, spatialite is an extension to SQLITE3.

SQLite3 needs to be specifically compiled with this option, and it is often not. For example the default version on mac does is not compiled with RTREE. However i think sqlite3 should be included though your python installation & pysqlite maybe using the original version of sqlite3 or another version.

you can try, sqlite3.version to see which version is being used by python.

Also note, you have to re-install pysqlite module with the correct config options i.e before running setup.py install, change the setup.cfg:

[build_ext]
#define=
include_dirs=PATH_TO_INCLUDE
library_dirs=PATH_TO_LIBS
libraries=sqlite3
#define=SQLITE_OMIT_LOAD_EXTENSION

http://www.gaia-gis.it/spatialite/install-windows.html

Citron answered 26/11, 2009 at 12:15 Comment(4)
Thanks for the clarification. For some reason I was under the impression that spatialite also contains the standard sqlite library. I downloaded the latest version of pysqlite, changed the setup.cfg according to your suggestion and then tried to run setup.py build_static install (as instructed by the pysqlite readme), and I get the following output: <pre> running build_static running build_py running build_ext Downloading amalgation. Extracting sqlite3.c Extracting sqlite3.h building 'pysqlite2._sqlite' extension error: Unable to find vcvarsall.bat </pre>Dubai
as far as I know this vcvarsall.bat is part of Microsoft's Visual Studio. I don't own this software and have no experience with it so now I looking for precompiled versions of Sqlite that have the rtree extension included. If you hvae such a file, or can provide any help finding one, it will be greatly appreciate.Dubai
Hi Hans, yes i think the pysqlite setup tries to compile sqlite3... and it must require Visual studio. I havent used a windows machine in a while so i cant really help you in that regards. I managed to get spatialite + geodjango setup on ubuntu quite easily (much easier then on a mac)Citron
I have added a link to some details on installation on windows.Citron
D
1

Thanks Issy for pointing me in the right direction.

The problem was indeed, that pysqlite created a sqlite binary, that did not have the R*TREE extension enabled.

I contacted the developers of pysqlite (see link text), who responsed very quickly letting me know, that from version 2.5.6 on, "Future Windows binaries and compilations with --build-static will have RTree support by default."

Problem solved. Thanks all.

Dubai answered 26/11, 2009 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.