“Django/docs/3.0.x/ref/contrib/gis/feeds”的版本间差异

来自菜鸟教程
Django/docs/3.0.x/ref/contrib/gis/feeds
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:地理信息源 — Django 文档}}
 
<div id="module-django.contrib.gis.feeds" class="section">
 
<div id="module-django.contrib.gis.feeds" class="section">
  
 
<span id="geographic-feeds"></span>
 
<span id="geographic-feeds"></span>
= Geographic Feeds =
+
= 地理提要 =
  
GeoDjango has its own [[#django.contrib.gis.feeds.Feed|<code>Feed</code>]] subclass that may embed location information
+
GeoDjango 有自己的 [[#django.contrib.gis.feeds.Feed|Feed]] 子类,可以将位置信息嵌入到根据 [http://georss.org/simple.html Simple GeoRSS] [https://www.w3.org/2003/01/geo/ W3C Geo] 标准格式化的 RSS/Atom 提要中。 由于 GeoDjango 的联合 API Django 的超集,请参阅 [[../../syndication|Django 的联合文档]] 了解一般用法的详细信息。
in RSS/Atom feeds formatted according to either the [http://georss.org/simple.html Simple GeoRSS] or
 
[https://www.w3.org/2003/01/geo/ W3C Geo] standards. Because GeoDjango's syndication API is a superset of
 
Django's, please consult [[../../syndication|<span class="doc">Django's syndication documentation</span>]] for details on general usage.
 
  
 
<div id="example" class="section">
 
<div id="example" class="section">
  
== 例如 ==
+
== 示例 ==
  
  
第17行: 第15行:
 
<div id="api-reference" class="section">
 
<div id="api-reference" class="section">
  
== API参考 ==
+
== API 参考 ==
  
 
<div id="feed-subclass" class="section">
 
<div id="feed-subclass" class="section">
  
=== <code>Feed</code> Subclass ===
+
=== Feed 子类 ===
  
 
<dl>
 
<dl>
<dt>''class'' <code>Feed</code></dt>
+
<dt>''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">Feed</span></span></dt>
<dd><p>In addition to methods provided by the
+
<dd><p>除了 [[../../syndication#django.contrib.syndication.views|django.contrib.syndication.views.Feed]] 基类提供的方法之外,GeoDjango 的 <code>Feed</code> 类提供以下覆盖。 请注意,这些覆盖可以通过多种方式完成:</p>
[[../../syndication#django.contrib.syndication.views|<code>django.contrib.syndication.views.Feed</code>]] base class, GeoDjango's
 
<code>Feed</code> class provides the following overrides. Note that these overrides
 
may be done in multiple ways:</p>
 
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
  
 
<div class="highlight">
 
<div class="highlight">
  
<pre>from django.contrib.gis.feeds import Feed
+
<syntaxhighlight lang="python">from django.contrib.gis.feeds import Feed
  
 
class MyFeed(Feed):
 
class MyFeed(Feed):
第53行: 第48行:
  
 
     def item_geometry(self, item):
 
     def item_geometry(self, item):
         ...</pre>
+
         ...</syntaxhighlight>
  
 
</div>
 
</div>
第59行: 第54行:
 
</div>
 
</div>
 
<dl>
 
<dl>
<dt><code>geometry</code><span class="sig-paren">(</span>''<span class="n">obj</span>''<span class="sig-paren">)</span></dt>
+
<dt><span class="sig-name descname"><span class="pre">geometry</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">obj</span></span>''<span class="sig-paren">)</span></dt>
 
<dd></dd></dl>
 
<dd></dd></dl>
  
<p>Takes the object returned by <code>get_object()</code> and returns the ''feed's''
+
<p>获取由 <code>get_object()</code> 返回的对象并返回 ''馈送的'' 几何体。 通常这是一个 <code>GEOSGeometry</code> 实例,或者可以是一个元组来表示一个点或一个框。 例如:</p>
geometry. Typically this is a <code>GEOSGeometry</code> instance, or can be a tuple
 
to represent a point or a box. For example:</p>
 
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
  
 
<div class="highlight">
 
<div class="highlight">
  
<pre>class ZipcodeFeed(Feed):
+
<syntaxhighlight lang="python">class ZipcodeFeed(Feed):
  
 
     def geometry(self, obj):
 
     def geometry(self, obj):
 
         # Can also return: `obj.poly`, and `obj.poly.centroid`.
 
         # Can also return: `obj.poly`, and `obj.poly.centroid`.
         return obj.poly.extent # tuple like: (X0, Y0, X1, Y1).</pre>
+
         return obj.poly.extent # tuple like: (X0, Y0, X1, Y1).</syntaxhighlight>
  
 
</div>
 
</div>
第79行: 第72行:
 
</div>
 
</div>
 
<dl>
 
<dl>
<dt><code>item_geometry</code><span class="sig-paren">(</span>''<span class="n">item</span>''<span class="sig-paren">)</span></dt>
+
<dt><span class="sig-name descname"><span class="pre">item_geometry</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">item</span></span>''<span class="sig-paren">)</span></dt>
 
<dd></dd></dl>
 
<dd></dd></dl>
  
<p>Set this to return the geometry for each ''item'' in the feed. This can be a
+
<p>设置此项以返回提要中每个 ''项目'' 的几何图形。 这可以是 <code>GEOSGeometry</code> 实例,也可以是表示点坐标或边界框的元组。 例如:</p>
<code>GEOSGeometry</code> instance, or a tuple that represents a point coordinate or
 
bounding box. For example:</p>
 
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
  
 
<div class="highlight">
 
<div class="highlight">
  
<pre>class ZipcodeFeed(Feed):
+
<syntaxhighlight lang="python">class ZipcodeFeed(Feed):
  
 
     def item_geometry(self, obj):
 
     def item_geometry(self, obj):
 
         # Returns the polygon.
 
         # Returns the polygon.
         return obj.poly</pre>
+
         return obj.poly</syntaxhighlight>
  
 
</div>
 
</div>
第103行: 第94行:
 
<div id="syndicationfeed-subclasses" class="section">
 
<div id="syndicationfeed-subclasses" class="section">
  
=== <code>SyndicationFeed</code> Subclasses ===
+
=== SyndicationFeed 子类 ===
  
The following [[../../../utils#django.utils.feedgenerator|<code>django.utils.feedgenerator.SyndicationFeed</code>]] subclasses
+
以下 [[../../../utils#django.utils.feedgenerator|django.utils.feedgenerator.SyndicationFeed]] 子类可用:
are available:
 
  
; ''class'' <code>GeoRSSFeed</code>
+
; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">GeoRSSFeed</span></span>
 
:  
 
:  
  
; ''class'' <code>GeoAtom1Feed</code>
+
; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">GeoAtom1Feed</span></span>
 
:  
 
:  
  
; ''class'' <code>W3CGeoFeed</code>
+
; ''<span class="pre">class</span>'' <span class="sig-name descname"><span class="pre">W3CGeoFeed</span></span>
 
:  
 
:  
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
[https://www.w3.org/2003/01/geo/ W3C Geo] formatted feeds only support
+
[https://www.w3.org/2003/01/geo/ W3C Geo] 格式的提要仅支持 [[../model-api#django.contrib.gis.db.models|PointField]] 几何图形。
[[../model-api#django.contrib.gis.db.models|<code>PointField</code>]] geometries.
 
  
  
第132行: 第121行:
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Django 3.0.x 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Django 3.0.x 文档]]

2021年10月31日 (日) 04:09的最新版本

地理提要

GeoDjango 有自己的 Feed 子类,可以将位置信息嵌入到根据 Simple GeoRSSW3C Geo 标准格式化的 RSS/Atom 提要中。 由于 GeoDjango 的联合 API 是 Django 的超集,请参阅 Django 的联合文档 了解一般用法的详细信息。

示例

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() 返回的对象并返回 馈送的 几何体。 通常这是一个 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 几何图形。