I’m trying to integrate GeoDjango and Leaflet using GeoJSON as the intermediate data format. I’m running into an issue when I try and pass the serialized output from GeoDjangos’s GeoJSON serializer where Leaflet says the GeoJSON is invalid.
I’m serializing the data with:
serializers.serialize("geojson", queryset, geometry_field="location", fields=[])
The output from the serializer looks like:
{"type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "EPSG:4326"}}, "features": [{"type": "Feature", "id": 809, "properties": {}, "geometry": {"type": "Point", "coordinates": [-62.64746180749695, 46.15809714964139]}}]}
When I run that through https://geojsonlint.com I get the following message about the “crs” member not being recommended:
Line 1: old-style crs member is not recommended
When I remove the “crs” from the GeoJSON so it looks like the following, everything works as expected.
{"type": "FeatureCollection", "features": [{"type": "Feature", "id": 809, "properties": {}, "geometry": {"type": "Point", "coordinates": [-62.64746180749695, 46.15809714964139]}}]}
I’m not familiar with the GeoJSON spec at all, but from what I can tell it looks like the “crs” section has been removed from the spec entirely (and I’m not the first one to run into this problem).
ref: Invalid object when adding geoJSON data on a Leaflet map with Django serializer - Stack Overflow
It looks like this is just hard coded right now, should we add an option to disable adding “crs”? Remove it entirely? Mark it for deprecation somehow?