Debian Codegraph @

docs/ref/contrib/gis/feeds.txt

raw
1 ================
2 Geographic Feeds
3 ================
4
5 .. module:: django.contrib.gis.feeds
6 :synopsis: GeoDjango's framework for generating spatial feeds.
7
8 GeoDjango has its own :class:`Feed` subclass that may embed location information
9 in RSS/Atom feeds formatted according to either the `Simple GeoRSS`__ or
10 `W3C Geo`_ standards. Because GeoDjango's syndication API is a superset of
11 Django's, please consult :doc:`Django's syndication documentation
12 </ref/contrib/syndication>` for details on general usage.
13
14 .. _W3C Geo: https://www.w3.org/2003/01/geo/
15
16 __ https://www.ogc.org/standard/georss/
17
18 Example
19 =======
20
21 API Reference
22 =============
23
24 ``Feed`` Subclass
25 -----------------
26
27 .. class:: Feed
28
29 In addition to methods provided by the
30 :class:`django.contrib.syndication.views.Feed` base class, GeoDjango's
31 ``Feed`` class provides the following overrides. Note that these overrides
32 may be done in multiple ways::
33
34 from django.contrib.gis.feeds import Feed
35
36
37 class MyFeed(Feed):
38 # First, as a class attribute.
39 geometry = ...
40 item_geometry = ...
41
42 # Also a function with no arguments
43 def geometry(self): ...
44
45 def item_geometry(self): ...
46
47 # And as a function with a single argument
48 def geometry(self, obj): ...
49
50 def item_geometry(self, item): ...
51
52 .. method:: geometry(obj)
53
54 Takes the object returned by ``get_object()`` and returns the *feed's*
55 geometry. Typically this is a ``GEOSGeometry`` instance, or can be a tuple
56 to represent a point or a box. For example::
57
58 class ZipcodeFeed(Feed):
59 def geometry(self, obj):
60 # Can also return: `obj.poly`, and `obj.poly.centroid`.
61 return obj.poly.extent # tuple like: (X0, Y0, X1, Y1).
62
63 .. method:: item_geometry(item)
64
65 Set this to return the geometry for each *item* in the feed. This can be a
66 ``GEOSGeometry`` instance, or a tuple that represents a point coordinate or
67 bounding box. For example::
68
69 class ZipcodeFeed(Feed):
70 def item_geometry(self, obj):
71 # Returns the polygon.
72 return obj.poly
73
74 ``SyndicationFeed`` Subclasses
75 ------------------------------
76
77 The following :class:`django.utils.feedgenerator.SyndicationFeed` subclasses
78 are available:
79
80 .. class:: GeoRSSFeed
81
82 .. class:: GeoAtom1Feed
83
84 .. class:: W3CGeoFeed
85
86 .. note::
87
88 `W3C Geo`_ formatted feeds only support
89 :class:`~django.contrib.gis.db.models.PointField` geometries.