Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#26138 closed Cleanup/optimization (fixed)

GeoJSON Serializer doesn't include geometry_field if it's not in fields

Reported by: Bernd Schlapsi Owned by: Claude Paroz
Component: GIS Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The example in the documentation for GeoJSON Serializer don't work as described.
https://docs.djangoproject.com/es/1.9/ref/contrib/gis/serializers/

The tuple for the fields option is missing the 'point' field

from django.core.serializers import serialize
from my_app.models import City

serialize('geojson', City.objects.all(),
          geometry_field='point',
          fields=('name', 'point'))

If you use the example without the 'point' in the fields tuple the returning geometry property is null

{
  'type': 'FeatureCollection',
  'crs': {
    'type': 'name',
    'properties': {'name': 'EPSG:4326'}
  },
  'features': [
    {
      'type': 'Feature',
      'geometry': null,
      'properties': {
        'name': 'Chicago'
      }
    }
  ]
}

I think there should be a test-case in
https://github.com/django/django/blob/master/tests/gis_tests/geoapp/test_serializers.py
with a call to serialize used with both parameters (geometry_field and fields)

Change History (5)

comment:1 by Claude Paroz, 9 years ago

Owner: changed from nobody to Claude Paroz
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:2 by Claude Paroz, 9 years ago

Has patch: set

comment:3 by Tim Graham, 9 years ago

Summary: Example for GeoJSON Serializer don't work as describedGeoJSON Serializer doesn't include geometry_field if it's not in fields
Triage Stage: AcceptedReady for checkin

comment:4 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 54236a2:

Fixed #26138 -- Ensured geometry_field's geometry is always serialized

Thanks Bernd Schlapsi for the report.

comment:5 by Claude Paroz <claude@…>, 9 years ago

In ca6ab72b:

[1.9.x] Fixed #26138 -- Ensured geometry_field's geometry is always serialized

Thanks Bernd Schlapsi for the report.
Backport of 54236a2c1c from master.

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