summaryrefslogtreecommitdiff
path: root/docs/ref/contrib/gis/feeds.txt
blob: 9ae9d4f03a4ba1cd5500cb1cf4c74709c6ecfd4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
================
Geographic Feeds
================

.. module:: django.contrib.gis.feeds
    :synopsis: GeoDjango's framework for generating spatial feeds.

GeoDjango has its own :class:`Feed` subclass that may embed location information
in RSS/Atom feeds formatted according to either the `Simple GeoRSS`__ or
`W3C Geo`_ standards.  Because GeoDjango's syndication API is a superset of
Django's, please consult :doc:`Django's syndication documentation
</ref/contrib/syndication>` for details on general usage.

.. _W3C Geo: https://www.w3.org/2003/01/geo/

__ https://www.ogc.org/standard/georss/

Example
=======

API Reference
=============

``Feed`` Subclass
-----------------

.. class:: Feed

    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::

        from django.contrib.gis.feeds import Feed


        class MyFeed(Feed):
            # 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):
                ...

    .. method:: geometry(obj)

    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::

        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).

    .. method:: item_geometry(item)

    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::

        class ZipcodeFeed(Feed):
            def item_geometry(self, obj):
                # Returns the polygon.
                return obj.poly

``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.