---
title: "地理 Feed"
version: 5.2
locale: zh-hans
source: https://docs.djangoproject.com/zh-hans/5.2/ref/contrib/gis/feeds/
canonical: https://djangodocs.dev/zh-hans/5.2/ref/contrib/gis/feeds/
---
# 地理 Feed

GeoDjango 拥有自己的 [`Feed`](#django.contrib.gis.feeds.Feed) 子类，可以根据 [Simple GeoRSS](https://www.ogc.org/standard/georss/) 或 [W3C Geo](https://www.w3.org/2003/01/geo/) 标准格式化的 RSS/Atom 源中嵌入位置信息。由于 GeoDjango 的聚合 API 是 Django 的超集，请查阅 [Django的聚合文档](/zh-hans/5.2/ref/contrib/syndication/) 以获取一般使用的详细信息。

## 例如

## API 参考

### `Feed` 子类

#### `class Feed`

除了 [`django.contrib.syndication.views.Feed`](/zh-hans/5.2/ref/contrib/syndication/#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)`

将此设置为返回 *feed* 中每个 *item* 的几何形状。这可以是一个 `GEOSGeometry` 实例，或者是表示点坐标或边界框的元组。例如：

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

### `SyndicationFeed` 子类

以下是可用的 [`django.utils.feedgenerator.SyndicationFeed`](/zh-hans/5.2/ref/utils/#django.utils.feedgenerator.SyndicationFeed) 子类：

#### `class GeoRSSFeed`

#### `class GeoAtom1Feed`

#### `class W3CGeoFeed`

> **Note**
>
> [W3C Geo](https://www.w3.org/2003/01/geo/) 格式的 feeds 仅支持 [`PointField`](/zh-hans/5.2/ref/contrib/gis/model-api/#django.contrib.gis.db.models.PointField) 几何形状。
