more performance improvements (no ordereddict, directly access geojson)

This commit is contained in:
Laura Klünder 2018-12-23 00:04:43 +01:00
parent 05dab8acb5
commit b406cb2d13
4 changed files with 29 additions and 40 deletions

View file

@ -1,5 +1,4 @@
import json
from collections import OrderedDict
from django.core.serializers.json import DjangoJSONEncoder
@ -39,14 +38,14 @@ def json_encoder_reindent(method, data, *args, **kwargs):
def format_geojson(data, round=True):
coordinates = data.get('coordinates', None)
if coordinates is not None:
return OrderedDict((
('type', data['type']),
('coordinates', round_coordinates(data['coordinates']) if round else data['coordinates']),
))
return OrderedDict((
('type', data['type']),
('geometries', [format_geojson(geometry, round=round) for geometry in data['geometries']]),
))
return {
'type': data['type'],
'coordinates': round_coordinates(data['coordinates']) if round else data['coordinates'],
}
return {
'type': data['type'],
'geometries': [format_geojson(geometry, round=round) for geometry in data['geometries']],
}
def round_coordinates(data):