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.
Feed 子类¶除了 django.contrib.syndication.views.Feed 基类提供的方法之外,GeoDjango 的 Feed 类还提供了以下覆盖方法。请注意,可以以多种方式进行这些覆盖操作:
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): ...
使用 get_object() 返回的对象,并返回 feed 的几何形状。通常情况下,这是一个 GEOSGeometry 实例,或者可以是一个表示点或矩形框的元组。例如:
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).
将此设置为返回 feed 中每个 item 的几何形状。这可以是一个 GEOSGeometry 实例,或者是表示点坐标或边界框的元组。例如:
class ZipcodeFeed(Feed):
def item_geometry(self, obj):
# Returns the polygon.
return obj.poly
12月 22, 2025