GeoDjango with SpatialLite on Windows 10

84 views
Skip to first unread message

Tugg Speedman

unread,
Aug 12, 2021, 9:42:58 AM8/12/21
to Django users

Hello everyone,

I'm new to GeoDjango and therefore I tried to follow the tutorial (https://docs.djangoproject.com/en/3.2/ref/contrib/gis/tutorial/) first. But the problem is, it doesn't work with SQLite a.k.a SpatialLite. When I try to build the migrations, a Windows error pops up (see picture below). It's german and says there is no entry point in gdal301.dll.

So why do I post this problem here in Django mailing list? Because the Tutorial is very fuzzy for Spatial & Windows. It basically just says download the SQLite files from here: https://www.gaia-gis.it/gaia-sins/

But what to do with this files? Can I put them wherever I want? Do I have to add them on System/Python path?

I would really appreciate any help
Thank youerror.png

Michael Ross

unread,
Aug 12, 2021, 6:51:02 PM8/12/21
to django...@googlegroups.com, Tugg Speedman
Maybe this helps:

https://stackoverflow.com/questions/53682315/error-on-libcurl-dll-when-using-gdal-of-osgeo4w-in-django

TLDR: IntelliJ loads wrong sqlite3.dll?

--
Michael Ross <g...@ross.cx>

Tugg Speedman

unread,
Aug 13, 2021, 12:41:22 PM8/13/21
to Django users
Ah OK, this was helpful. I never thought about this, but as it turns out on Windows, Python ships with it's own compiled version of SQLite (see picture below). This is problematic. If i just swap this DLL with another one, I would change every other Python Script on my machine. Hmm..., is it possible to change some environment Paths in a venv and just point to another DLL? I have to look this up. Thanks a lot Micheal.

sqlite.png

Tugg Speedman

unread,
Aug 15, 2021, 6:08:08 PM8/15/21
to Django users
OK, I got it.

As it turns out, GDAL has everything you need, including the SQLite database. There is only one important fact, you have to load the DLL prior Django loads his SQLite. Because Django loads the one from Python it self. Therefore i did put the necessary code into the settings.py. Because Django has first to load the settings, before it can load the correct database middleware (SQLite, PostgreSQL, MariaDB,...). The code is in the Picture below.

P.S.: The Tutorial is not quiet accurate. The Geographic Model from there (https://docs.djangoproject.com/en/3.2/ref/contrib/gis/tutorial/#defining-a-geographic-model) should allow NULL for the polygon field:
mpoly = models.MultiPolygonField(null=True)
This is neccessary because the ZIP you offer there has incomplete data. At least good old England (to be precise: United Kingdom) has no pylogon data, maybe some more countries. I didn't check further. Therefore you can't load the "TM_WORLD_BORDERS-0.3.shp" as instructed (https://docs.djangoproject.com/en/3.2/ref/contrib/gis/tutorial/#layermapping).

Should I open a ticket for this, or is this mailing list enough?
settings.png
Reply all
Reply to author
Forward
0 new messages