feeds.txt 2.5 KB

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