GeoJSON serializer producing invalid output (CRS)

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?

1 Like

(disclaimer: i know next-to-nothing about GeoDjango)

It seems you’re right and the crs attribute was removed from the spec when it was updated in 2016: RFC 7946 - The GeoJSON Format (first item of appendix B1)

I think this is a very strong argument for removing it from Django. Would you mind opening a ticket for that?

Thanks!

1 Like

Done! #35989 (GeoJSON serializer producing invalid output (crs attribute)) – Django

1 Like