Opened 23 months ago

Closed 23 months ago

Last modified 23 months ago

#20252 closed Cleanup/optimization (fixed)

GeoDjango - GeoQuerySet.geojson NotImplementedError with Spatialite

Reported by: burton449geo@… Owned by: nobody
Component: GIS Version: 1.5-rc-1
Severity: Normal Keywords: GeoDjango, Spatialite
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As the documentation mentions (https://docs.djangoproject.com/en/dev/ref/contrib/gis/geoquerysets/#django.contrib.gis.db.models.GeoQuerySet.geojson) GeoQuerySet.geojson should be available with Spatialite but it is not.

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response

  1. response = callback(request, *callback_args, callback_kwargs)

File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view

  1. return view_func(request, *args, kwargs)

File "c:\mygeosite\geodjango\ezmapping\views.py" in editShapefile

  1. feature_geoJson = features.geojson()

File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\query.py" in geojson

  1. raise NotImplementedError('Only PostGIS 1.3.4+ supports GeoJSON serialization.')

Exception Type: NotImplementedError at /ezmapping/layer/edit/1
Exception Value: Only PostGIS 1.3.4+ supports GeoJSON serialization.

Attachments (1)

20252.diff (1.1 KB) - added by claudep 23 months ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 23 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization

geojson support for Spatialite has been added in Django 1.5. I'll add the missing notice to the docs.

comment:2 Changed 23 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 991ce52bc872f827de8e7b5b441e2dfa2185bfd2:

[1.5.x] Fixed #20252 -- Mentionned geojson Spatialite support from 1.5

Thanks burton449geo at gmail.com for the report.
Backport of d58e985aa from master.

comment:3 Changed 23 months ago by anonymous

I dont understand, I have updated Django to 1.5.1 and still got an error. Is this function implement with Spatialite 4.0? Thats the version im using.

comment:4 Changed 23 months ago by claudep

For the record, this was added in #19028 - [95f7ea3af185]

If you get an error with 1.5.1, we'll need the traceback, please.

comment:5 Changed 23 months ago by burton449geo@…

  • Version changed from 1.4 to 1.5-rc-1

This error using Django 1.5.1 ans Spatialite 4.0 when calling function GeoQuerySet.geojson()

Traceback:

File "C:\python27\lib\site-packages\django\core\handlers\base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
  25.                 return view_func(request, *args, **kwargs)
File "c:\mygeosite\geodjango\ezmapping\views.py" in editShapefile
  59.     bounds = features.geojson()
File "C:\python27\lib\site-packages\django\contrib\gis\db\models\query.py" in geojson
  149.             raise NotImplementedError('Only PostGIS 1.3.4+ and SpatiaLite 3.0+ '

Exception Type: NotImplementedError at /ezmapping/layer/edit/1
Exception Value: Only PostGIS 1.3.4+ and SpatiaLite 3.0+ support GeoJSON serialization.
Last edited 23 months ago by claudep (previous) (diff)

comment:6 Changed 23 months ago by claudep

Could you try this snippet inside your project:

$ python manage.py shell
>>> from django.db import connection
>>> print(connection.ops.spatial_version)

It may be that your Django instance does not use the expected Spatialite installation.

comment:7 Changed 23 months ago by burton449geo@…

The return is None. I have made a test and re-creating a new spatialite db from spatialite_gui v.4.0, but it still returned None. When I use a PostGIS settings it returns 2.0.3. Do you know what could be the meaning?

comment:8 Changed 23 months ago by claudep

Oh, sorry, spatial_version is a cached property in master, but it is a method in 1.5. So the last snippet line should read print(connection.ops.spatial_version()). Here is the code:
https://github.com/django/django/blob/stable/1.5.x/django/contrib/gis/db/backends/spatialite/operations.py#L246

Basically, this executes the SQL query SELECT spatialite_version(); (you can also try it at the spatialite prompt).
It would also be interesting to get the result of connection.ops.spatialite_version_tuple().

comment:9 Changed 23 months ago by burton449geo@…

In the django project shell: print(connection.ops.spatial_version()) returns 3.0.1 and connection.ops.spatialite_version_tuple() returns (u'3.0.1', 3,0,1)

In spatialite prompt: SELECT spatialite_version(); returns 4.0.0

There is no error on those results, it was done on the same spatilatie db defined in settings.py

comment:10 Changed 23 months ago by claudep

OK, now I see the bug, which has been fixed in master by commit [eb9430fc4be1]. It was unfortunately a bit late to enter the 1.5 branch. I will try to make a more limited patch for the stable branch. Could you test the following patch to see if it resolves your issue?

Changed 23 months ago by claudep

comment:11 Changed 23 months ago by burton449geo@…

I do not have the error anymore with the patch installed. Good job and thank you!

comment:12 Changed 23 months ago by Claude Paroz <claude@…>

In 9176fa70c1541d29d4d1865770d48b174e5dd968:

[1.5.x] Fixed geojson detection with Spatialite

This is a partial backport of commit eb9430fc4be1. Without this,
geojson support is never detected with Spatialite.
Refs #20252 and #19028.

Note: See TracTickets for help on using tickets.
Back to Top