mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Fixed #35989 -- Removed crs from GeoJSON serializer.
Specification of coordinate reference systems (crs) was removed from the GeoJSON spec in 2016. https://datatracker.ietf.org/doc/html/rfc7946#appendix-B.1
This commit is contained in:
parent
5e998d717f
commit
918e7a2c76
@ -25,11 +25,7 @@ class Serializer(JSONSerializer):
|
|||||||
def start_serialization(self):
|
def start_serialization(self):
|
||||||
self._init_options()
|
self._init_options()
|
||||||
self._cts = {} # cache of CoordTransform's
|
self._cts = {} # cache of CoordTransform's
|
||||||
self.stream.write(
|
self.stream.write('{"type": "FeatureCollection", "features": [')
|
||||||
'{"type": "FeatureCollection", '
|
|
||||||
'"crs": {"type": "name", "properties": {"name": "EPSG:%d"}},'
|
|
||||||
' "features": [' % self.srid
|
|
||||||
)
|
|
||||||
|
|
||||||
def end_serialization(self):
|
def end_serialization(self):
|
||||||
self.stream.write("]}")
|
self.stream.write("]}")
|
||||||
|
@ -46,7 +46,6 @@ Would output::
|
|||||||
|
|
||||||
{
|
{
|
||||||
"type": "FeatureCollection",
|
"type": "FeatureCollection",
|
||||||
"crs": {"type": "name", "properties": {"name": "EPSG:4326"}},
|
|
||||||
"features": [
|
"features": [
|
||||||
{
|
{
|
||||||
"type": "Feature",
|
"type": "Feature",
|
||||||
|
@ -23,6 +23,8 @@ class GeoJSONSerializerTests(TestCase):
|
|||||||
def test_serialization_base(self):
|
def test_serialization_base(self):
|
||||||
geojson = serializers.serialize("geojson", City.objects.order_by("name"))
|
geojson = serializers.serialize("geojson", City.objects.order_by("name"))
|
||||||
geodata = json.loads(geojson)
|
geodata = json.loads(geojson)
|
||||||
|
self.assertEqual(list(geodata.keys()), ["type", "features"])
|
||||||
|
self.assertEqual(geodata["type"], "FeatureCollection")
|
||||||
self.assertEqual(len(geodata["features"]), len(City.objects.all()))
|
self.assertEqual(len(geodata["features"]), len(City.objects.all()))
|
||||||
self.assertEqual(geodata["features"][0]["geometry"]["type"], "Point")
|
self.assertEqual(geodata["features"][0]["geometry"]["type"], "Point")
|
||||||
self.assertEqual(geodata["features"][0]["properties"]["name"], "Chicago")
|
self.assertEqual(geodata["features"][0]["properties"]["name"], "Chicago")
|
||||||
|
Loading…
Reference in New Issue
Block a user