Opened 9 years ago

Closed 9 years ago

Last modified 9 years 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


As the documentation mentions ( GeoQuerySet.geojson should be available with Spatialite but it is not.

File "C:\Python27\lib\site-packages\django\core\handlers\" in get_response

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

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

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

File "c:\mygeosite\geodjango\ezmapping\" in editShapefile

  1. feature_geoJson = features.geojson()

File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\" 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 Claude Paroz 9 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 9 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

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

comment:2 Changed 9 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 991ce52bc872f827de8e7b5b441e2dfa2185bfd2:

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

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

comment:3 Changed 9 years 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 9 years ago by Claude Paroz

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 9 years ago by burton449geo@…

Version: 1.41.5-rc-1

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


File "C:\python27\lib\site-packages\django\core\handlers\" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\python27\lib\site-packages\django\contrib\auth\" in _wrapped_view
  25.                 return view_func(request, *args, **kwargs)
File "c:\mygeosite\geodjango\ezmapping\" in editShapefile
  59.     bounds = features.geojson()
File "C:\python27\lib\site-packages\django\contrib\gis\db\models\" 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 9 years ago by Claude Paroz (previous) (diff)

comment:6 Changed 9 years ago by Claude Paroz

Could you try this snippet inside your project:

$ python 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 9 years 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 9 years ago by Claude Paroz

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:

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 9 years 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

comment:10 Changed 9 years ago by Claude Paroz

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 9 years ago by Claude Paroz

Attachment: 20252.diff added

comment:11 Changed 9 years ago by burton449geo@…

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

comment:12 Changed 9 years 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