地理情報フィード

GeoDjango には独自の Feed サブクラスがあり、Simple GeoRSS または W3C Geo 標準に従ってフォーマットされた RSS/Atom フィードに位置情報を埋め込むことができます。GeoDjango の syndication API は Django のスーパーセットなので、 Django の配信 (syndication) フレームワークのドキュメント を参照してください。

カスタマイズ例

API リファレンス

Feed サブクラス

class 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): ...
geometry(obj)

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).
item_geometry(item)

これをセットすると、フィードの各 アイテム のジオメトリを返します。これは GEOSGeometry のインスタンス、 あるいは点座標やバウンディングボックスを表すタプルとなります。たとえば次のようになります:

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

SyndicationFeed サブクラス

以下の django.utils.feedgenerator.SyndicationFeed のサブクラスが利用可能です:

class GeoRSSFeed
class GeoAtom1Feed
class W3CGeoFeed

注釈

W3C Geo フォーマットのフィードでは、PointField ジオメトリのみがサポートされています。

Back to Top