Opened 2 years ago
Closed 2 years ago
#33742 closed New feature (fixed)
GeoJSON serializer doesn't provide a mechanism to include the ID of a feature
Reported by: | Samir Shah | Owned by: | Samir Shah |
---|---|---|---|
Component: | GIS | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Claude Paroz | 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 GeoJSON specification says:
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:
- Django defaults to using the object PK as the
id
for the feature.
- 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.
Change History (5)
comment:1 by , 2 years ago
Cc: | added |
---|---|
Type: | Bug → New feature |
comment:2 by , 2 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 2 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Sure, a patch would be welcome!