mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Added a new GeoJSON serialization format for GeoDjango
Thanks Reinout van Rees for the review.
This commit is contained in:
parent
c5132382f0
commit
35dac5070b
11 changed files with 245 additions and 4 deletions
69
docs/ref/contrib/gis/serializers.txt
Normal file
69
docs/ref/contrib/gis/serializers.txt
Normal file
|
@ -0,0 +1,69 @@
|
|||
.. _ref-geojson-serializer:
|
||||
|
||||
==================
|
||||
GeoJSON Serializer
|
||||
==================
|
||||
|
||||
.. versionadded:: 1.8
|
||||
|
||||
.. module:: django.contrib.gis.serializers.geojson
|
||||
:synopsis: Serialization of GeoDjango models in the GeoJSON format.
|
||||
|
||||
GeoDjango provides a specific serializer for the `GeoJSON`__ format. The GDAL
|
||||
library is required for this serializer. See :doc:`/topics/serialization` for
|
||||
more information on serialization.
|
||||
|
||||
__ http://geojson.org/
|
||||
|
||||
The ``geojson`` serializer is not meant for round-tripping data, as it has no
|
||||
deserializer equivalent. For example, you cannot use :djadmin:`loaddata` to
|
||||
reload the output produced by this serializer. If you plan to reload the
|
||||
outputted data, use the plain :ref:`json serializer <serialization-formats-json>`
|
||||
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()``:
|
||||
|
||||
* ``geometry_field``: A string containing the name of a geometry field to use
|
||||
for the ``geometry`` key of the GeoJSON feature. This is only needed when you
|
||||
have a model with more than one geometry field and you don't want to use the
|
||||
first defined geometry field (by default, the first geometry field is picked).
|
||||
|
||||
* ``srid``: The SRID to use for the ``geometry`` content. Defaults to 4326
|
||||
(WGS 84).
|
||||
|
||||
The :ref:`fields <subset-of-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'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -15,3 +15,4 @@ useful in creating geospatial Web applications.
|
|||
|
||||
layermapping
|
||||
ogrinspect
|
||||
serializers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue