GeoDjango フォーム APILink to this heading
GeoDjango はジオローカライズされたデータを地図上に視覚的に表示・編集するために、いくつかの特殊なフォームフィールドとウィジェットを提供します。デフォルトでは、 NASA が提供する WMS レイヤーをベースとした OpenLayers を利用した地図を使います。
フィールドの引数Link to this heading
通常の フォームフィールドの引数 に加えて、 GeoDjango のフォームフィールドは以下のオプションの引数を取ります。
sridLink to this heading
- Field.sridLink to this definition
これはフィールドの値を変換するSRIDコードです。例えば、マップウィジェットのSRIDがアプリケーションやデータベースで一般的に使われるSRIDと異なる場合、フィールドは入力値を自動的にそのSRIDに変換します。
geom_typeLink to this heading
- Field.geom_typeLink to this definition
通常、その属性を設定または変更する必要はありません。この属性はフィールドクラスに応じて設定されるべきです。これはOpenGIS標準のジオメトリ名に一致します。
max_geom_collectionsLink to this heading
- Field.max_geom_collectionsLink to this definition
-
The maximum number of geometry collections the field accepts before refusing to parse the input and raising a
ValidationError. This guards against crashes in the underlying GEOS library when parsing deeply nestedGEOMETRYCOLLECTIONinput. It defaults to198.The limit is applied differently depending on the input format: for well-known text (WKT) it bounds the nesting depth, while for well-known binary (WKB and hex-encoded WKB) it bounds the total number of geometry collections (both breadth and depth). As a result, the same value may accept a wide, shallow collection as WKT but reject it as WKB. For GeoJSON, the limit is not applied at all, since GDAL parses that input type instead.
Increase this value (or set to
None) only if you must accept legitimately deep geometries, since doing so reduces protection against fatal errors.
フォームフィールド クラスLink to this heading
GeometryFieldLink to this heading
- class GeometryFieldLink to this definition
PointFieldLink to this heading
- class PointFieldLink to this definition
LineStringFieldLink to this heading
- class LineStringFieldLink to this definition
PolygonFieldLink to this heading
- class PolygonFieldLink to this definition
MultiPointFieldLink to this heading
- class MultiPointFieldLink to this definition
MultiLineStringFieldLink to this heading
- class MultiLineStringFieldLink to this definition
MultiPolygonFieldLink to this heading
- class MultiPolygonFieldLink to this definition
GeometryCollectionFieldLink to this heading
- class GeometryCollectionFieldLink to this definition
フォームウィジェットLink to this heading
GeoDjango のフォームウィジェットを使うと、ビジュアルマップ上に地理情報を表示したり編集したりできます。現在利用可能なウィジェットはどれも 3D ジオメトリをサポートしていないので、 ジオメトリフィールドは Textarea ウィジェットを使ってフォールバックします。
ウィジェットの属性Link to this heading
GeoDjango ウィジェットはテンプレートベースなので、その属性のほとんどは他の Django ウィジェットの属性と異なります。
- BaseGeometryWidget.base_layerLink to this definition
-
対応する JavaScript のマップウィジェットで使用されるデフォルトのベースマップレイヤーの識別子を指定する文字列です。これはレンダリング時にウィジェットのオプションの一部として渡され、
MapWidgetが初期化するマップタイルプロバイダーまたはベースレイヤーを判断できるようにします(デフォルトはNoneです)。
- BaseGeometryWidget.geom_typeLink to this definition
OpenGIS ジオメトリタイプ。通常、フォームフィールドによって設定されます。
- BaseGeometryWidget.map_sridLink to this definition
地図で使用されるSRIDコード (デフォルトは4326)。
- BaseGeometryWidget.display_rawLink to this definition
主にデバッグのために、現在のジオメトリのシリアライズされた表現を示すテキストエリア入力を表示するかどうかを指定するブール値 (デフォルトは
False).
- BaseGeometryWidget.supports_3dLink to this definition
ウィジェットが3Dデータの編集をサポートしているかどうかを示します (デフォルトは
Falseです) 。
- BaseGeometryWidget.template_nameLink to this definition
地図ウィジェットのレンダリングに使用されるテンプレート。
ウィジェットの属性は、他のDjangoウィジェットと同じように渡すことができます。例えば、次のようにします:
from django.contrib.gis import forms
class MyGeoForm(forms.Form):
point = forms.PointField(widget=forms.OSMWidget(attrs={"display_raw": True}))
Widget クラスLink to this heading
BaseGeometryWidget
- class BaseGeometryWidgetLink to this definition
これは、サブクラスが必要とするロジックを含む抽象ベースウィジェットです。このウィジェットを直接ジオメトリフィールドに使うことはできません。GeoDjango ウィジェットのレンダリングは
base_layerクラス属性で識別されるベースレイヤー名に基づいていることに注意してください。
OpenLayersWidget
- class OpenLayersWidgetLink to this definition
これはすべての GeoDjango フォームフィールドで使用されるデフォルトウィジェットです。属性は以下の通りです。
- base_layerLink to this definition
-
nasaWorldview
- template_nameLink to this definition
gis/openlayers.html.
- map_sridLink to this definition
3857
OpenLayersWidgetおよびOSMWidgetは、コンテンツ配信ネットワークcdn.jsdelivr.net上でホストされているol.jsおよびol.cssファイルを読み込みます。これらのファイルは、ウィジェットをサブクラス化し、内部のMediaクラスのjsおよびcssプロパティを設定することで上書きできます(定数として定義されたアセット を参照)。
OSMWidget
- class OSMWidgetLink to this definition
This widget specialized
OpenLayersWidgetand uses an OpenStreetMap base layer to display geographic objects on. Attributes are:- base_layerLink to this definition
-
osm
- default_latLink to this definition
- default_lonLink to this definition
デフォルトの中心緯度と経度はそれぞれ
47と5で、フランス東部の位置です。
- default_zoomLink to this definition
デフォルトの地図の縮尺は
12です。
The
OpenLayersWidgetnote about using external assets also applies here. See also this FAQ answer abouthttpsaccess to map tiles.
Customizing the base layer used in OpenLayers-based widgetsLink to this heading
To customize the base layer displayed in OpenLayers-based geometry widgets, define a new layer builder in a custom JavaScript file. For example:
path-to-file.js MapWidget.layerBuilder.custom_layer_name = function () {
// Return an OpenLayers layer instance.
return new ol.layer.Tile({source: new ol.source.<ChosenSource>()});
};
Then, subclass a standard geometry widget and set the base_layer:
from django.contrib.gis.forms.widgets import OpenLayersWidget
class YourCustomWidget(OpenLayersWidget):
base_layer = "custom_layer_name"
class Media:
js = ["path-to-file.js"]