﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33742	GeoJSON serializer doesn't provide a mechanism to include the ID of a feature	Samir Shah	Samir Shah	"The [https://datatracker.ietf.org/doc/html/rfc7946#section-3.2 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:

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."	New feature	closed	GIS	dev	Normal	fixed		Claude Paroz	Ready for checkin	1	0	0	0	0	0
