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).
これをセットすると、フィードの各 アイテム のジオメトリを返します。これは GEOSGeometry のインスタンス、 あるいは点座標やバウンディングボックスを表すタプルとなります。たとえば次のようになります:
class ZipcodeFeed(Feed):
def item_geometry(self, obj):
# Returns the polygon.
return obj.poly
12月 04, 2025