Created
November 9, 2011 18:03
-
-
Save danielsokolowski/1352286 to your computer and use it in GitHub Desktop.
Updated: GeoJSON Serializer for GeoDjango (gis)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Unfortunately the built in Django JSON serialzer encodes GeoDjango GeometyrField as WKT text. This snippet extends django's serializer and adds support for GEOJson format. | |
Built in JSON serializer output: | |
[{"pk": 1, ... "geopoint": "POINT (-76.5060419999999937 44.2337040000000030)" ... }] | |
GeoJSON serializer ouput: | |
[{"pk": 1, ... "geopoint": {"type": "Point", | |
"coordinates": [-76.503296000000006, 44.230956999999997], | |
"__GEOSGeometry__": [ | |
"__init__", | |
[ | |
"SRID=4326;POINT (-75.5129950000000036 44.2442360000000008)" | |
] | |
] | |
}] | |
Note: the "__GEOSGeometry__" is a class hint as defined by JSON-RCP | |
and used during deserilization. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment