GeoDjango provides a specific serializer for the GeoJSON format. The GDAL library is required for this serializer. See Serializing Django objects for more information on serialization.
The geojson serializer is not meant for round-tripping data, as it has no deserializer equivalent. For example, you cannot use loaddata to reload the output produced by this serializer. If you plan to reload the outputted data, use the plain json serializer instead.
In addition to the options of the json serializer, the geojson serializer accepts the following additional option when it is called by serializers.serialize():
The fields option can be used to limit fields that will be present in the properties key, as it works with all other serializers.
Example:
from django.core.serializers import serialize
from my_app.models import City
serialize('geojson', City.objects.all(),
geometry_field='point',
fields=('name',))
Would output:
{
'type': 'FeatureCollection',
'crs': {
'type': 'name',
'properties': {'name': 'EPSG:4326'}
},
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-87.650175, 41.850385]
},
'properties': {
'name': 'Chicago'
}
}
]
}
Jun 02, 2016