If a Feature has a commonly used identifier, that identifier SHOULD be
included as a member of the Feature object with the name "id", and the
value of this member is either a JSON string or number.
Thus it should be possible to generate a GeoJSON object which looks like
this:
{{{
{
"type": "Feature",
"id": 24
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [8.11, 52.11]
}
}
}}}
`django.contrib.gis.serializers.geojson.Serializer` doesn't support this -
it's not possible to add an `id` key to a feature without overriding the
`get_dump_object()` method of the class. If you specify `pk` in the
fields, then this gets added to the `properties` of the feature, but not a
top level `id` field. Having an ID is important for a number of use cases
- particularly when GeoJSON data is made editable via an API, for which
many client libraries use the `id` to uniquely identify features.
Given that the specification says an `id` SHOULD be present if available,
I would like to propose one of the following:
1. Django defaults to using the object PK as the `id` for the feature.
2. Or, if (1) is considered a backwards-incompatible change, then a
mechanism is provided to instruct the class to include an ID (which I
guess may not always be the the primary key)
I'm happy to contribute a PR for this if you can give me guidance on what
the preferred approach would be. Personally I think Django should include
the ID by default.
--
Ticket URL: <https://code.djangoproject.com/ticket/33742>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Claude Paroz (added)
* type: Bug => New feature
--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:1>
* stage: Unreviewed => Accepted
Comment:
Sure, a patch would be welcome!
--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:2>
* owner: nobody => Samir Shah
* status: new => assigned
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/15740 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"6f73eb9d90cfec684529aab48d517e3d6449ba8c" 6f73eb9]:
{{{
#!CommitTicketReference repository=""
revision="6f73eb9d90cfec684529aab48d517e3d6449ba8c"
Fixed #33742 -- Added id to GeoJSON serializer.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33742#comment:5>