地理 Feed

GeoDjango has its own 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 Django’s syndication documentation for details on general usage.

例如

API 参考

Feed 子类

class Feed

In addition to methods provided by the 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:

  1. from django.contrib.gis.feeds import Feed
  2. class MyFeed(Feed):
  3. # First, as a class attribute.
  4. geometry = ...
  5. item_geometry = ...
  6. # Also a function with no arguments
  7. def geometry(self):
  8. ...
  9. def item_geometry(self):
  10. ...
  11. # And as a function with a single argument
  12. def geometry(self, obj):
  13. ...
  14. def item_geometry(self, item):
  15. ...
  • 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:

  1. class ZipcodeFeed(Feed):
  2. def geometry(self, obj):
  3. # Can also return: `obj.poly`, and `obj.poly.centroid`.
  4. return obj.poly.extent # tuple like: (X0, Y0, X1, Y1).
  • 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:

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

SyndicationFeed 子类

The following django.utils.feedgenerator.SyndicationFeed subclasses are available:

class GeoRSSFeed

class GeoAtom1Feed

class W3CGeoFeed

备注

W3C Geo formatted feeds only support PointField geometries.