2010-03-26 20:14:53 +00:00
|
|
|
================
|
|
|
|
Geographic Feeds
|
|
|
|
================
|
|
|
|
|
|
|
|
.. module:: django.contrib.gis.feeds
|
2016-02-19 07:31:25 +00:00
|
|
|
:synopsis: GeoDjango's framework for generating spatial feeds.
|
2010-03-26 20:14:53 +00:00
|
|
|
|
|
|
|
GeoDjango has its own :class:`Feed` subclass that may embed location information
|
2010-08-19 19:27:44 +00:00
|
|
|
in RSS/Atom feeds formatted according to either the `Simple GeoRSS`__ or
|
2010-03-26 20:14:53 +00:00
|
|
|
`W3C Geo`_ standards. Because GeoDjango's syndication API is a superset of
|
2010-08-19 19:27:44 +00:00
|
|
|
Django's, please consult :doc:`Django's syndication documentation
|
|
|
|
</ref/contrib/syndication>` for details on general usage.
|
2010-03-26 20:14:53 +00:00
|
|
|
|
2018-01-07 13:28:41 +00:00
|
|
|
.. _W3C Geo: https://www.w3.org/2003/01/geo/
|
2010-03-26 20:14:53 +00:00
|
|
|
|
2023-05-17 10:13:10 +00:00
|
|
|
__ https://www.ogc.org/standard/georss/
|
2010-03-26 20:14:53 +00:00
|
|
|
|
|
|
|
Example
|
|
|
|
=======
|
|
|
|
|
|
|
|
API Reference
|
|
|
|
=============
|
|
|
|
|
|
|
|
``Feed`` Subclass
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
.. class:: Feed
|
|
|
|
|
2016-02-19 07:31:25 +00:00
|
|
|
In addition to methods provided by the
|
|
|
|
:class:`django.contrib.syndication.views.Feed` base class, GeoDjango's
|
|
|
|
``Feed`` class provides the following overrides. Note that these overrides
|
|
|
|
may be done in multiple ways::
|
2010-03-26 20:14:53 +00:00
|
|
|
|
2016-02-19 09:11:01 +00:00
|
|
|
from django.contrib.gis.feeds import Feed
|
2010-03-26 20:14:53 +00:00
|
|
|
|
|
|
|
|
2016-02-19 09:11:01 +00:00
|
|
|
class MyFeed(Feed):
|
2010-03-26 20:14:53 +00:00
|
|
|
# First, as a class attribute.
|
|
|
|
geometry = ...
|
|
|
|
item_geometry = ...
|
|
|
|
|
|
|
|
# Also a function with no arguments
|
|
|
|
def geometry(self):
|
|
|
|
...
|
|
|
|
|
|
|
|
def item_geometry(self):
|
|
|
|
...
|
|
|
|
|
|
|
|
# And as a function with a single argument
|
|
|
|
def geometry(self, obj):
|
|
|
|
...
|
|
|
|
|
|
|
|
def item_geometry(self, item):
|
|
|
|
...
|
|
|
|
|
2016-02-19 07:31:25 +00:00
|
|
|
.. method:: geometry(obj)
|
2010-03-26 20:14:53 +00:00
|
|
|
|
2016-02-19 07:31:25 +00:00
|
|
|
Takes the object returned by ``get_object()`` and returns the *feed's*
|
|
|
|
geometry. Typically this is a ``GEOSGeometry`` instance, or can be a tuple
|
|
|
|
to represent a point or a box. For example::
|
2010-03-26 20:14:53 +00:00
|
|
|
|
2016-02-19 07:31:25 +00:00
|
|
|
class ZipcodeFeed(Feed):
|
|
|
|
def geometry(self, obj):
|
|
|
|
# Can also return: `obj.poly`, and `obj.poly.centroid`.
|
|
|
|
return obj.poly.extent # tuple like: (X0, Y0, X1, Y1).
|
2010-03-26 20:14:53 +00:00
|
|
|
|
2016-02-19 07:31:25 +00:00
|
|
|
.. method:: item_geometry(item)
|
2010-03-26 20:14:53 +00:00
|
|
|
|
2016-02-19 07:31:25 +00:00
|
|
|
Set this to return the geometry for each *item* in the feed. This can be a
|
|
|
|
``GEOSGeometry`` instance, or a tuple that represents a point coordinate or
|
|
|
|
bounding box. For example::
|
2010-03-26 20:14:53 +00:00
|
|
|
|
2013-01-01 13:12:42 +00:00
|
|
|
class ZipcodeFeed(Feed):
|
|
|
|
def item_geometry(self, obj):
|
|
|
|
# Returns the polygon.
|
|
|
|
return obj.poly
|
2010-03-26 20:14:53 +00:00
|
|
|
|
|
|
|
``SyndicationFeed`` Subclasses
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
The following :class:`django.utils.feedgenerator.SyndicationFeed` subclasses
|
|
|
|
are available:
|
|
|
|
|
|
|
|
.. class:: GeoRSSFeed
|
|
|
|
|
|
|
|
.. class:: GeoAtom1Feed
|
|
|
|
|
|
|
|
.. class:: W3CGeoFeed
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
`W3C Geo`_ formatted feeds only support
|
|
|
|
:class:`~django.contrib.gis.db.models.PointField` geometries.
|