GeoDjango原文阅读

Putting your data on the map

Geographic Admin

图形数据后台管理

GeoDjango extends Django’s admin application with support for editing geometry fields.

Basics

GeoDjango also supplements the Django admin by allowing users to create and modify geometries on a JavaScript slippy map (powered by OpenLayers).

Let’s dive right in. Create a file called admin.py inside the world application with the following code:

from django.contrib.gis import admin
from .models import WorldBorder

admin.site.register(WorldBorder, admin.GeoModelAdmin)

Next, edit your urls.py in the geodjango application folder as follows:

from django.contrib.gis import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.site.urls),
]

大致意思是可以采用admin对geo数据进行管理,方式方法和常规的admin类似,不知道支持不支持xadmin。

GeoDjango Forms API

GeoDjango provides some specialized form fields and widgets in order to visually display and edit geolocalized data on a map. By default, they use OpenLayers-powered maps, with a base WMS layer provided by NASA.

Field arguments

In addition to the regular form field arguments, GeoDjango form fields take the following optional arguments.

srid

Field.srid

This is the SRID code that the field value should be transformed to. For example, if the map widget SRID is different from the SRID more generally used by your application or database, the field will automatically convert input values into that SRID.

geom_type

Field.geom_type

You generally shouldn’t have to set or change that attribute which should be setup depending on the field class. It matches the OpenGIS standard geometry name.

Form field classes

GeometryField

class GeometryField

PointField

class PointField

LineStringField

class LineStringField

PolygonField

class PolygonField

MultiPointField

class MultiPointField

MultiLineStringField

class MultiLineStringField

MultiPolygonField

class MultiPolygonField

GeometryCollectionField

class GeometryCollectionField

GeoDjango Database API

Spatial Backends

GeoDjango currently provides the following spatial database backends:

  • django.contrib.gis.db.backends.postgis
  • django.contrib.gis.db.backends.mysql
  • django.contrib.gis.db.backends.oracle
  • django.contrib.gis.db.backends.spatialite

MySQL Spatial Limitations

MySQL’s spatial extensions only support bounding box operations (what MySQL calls minimum bounding rectangles, or MBR). Specifically,MySQL does not conform to the OGC standard:

Currently, MySQL does not implement these functions [ContainsCrossesDisjointIntersectsOverlapsTouchesWithin] according to the specification. Those that are implemented return the same result as the corresponding MBR-based functions.

In other words, while spatial lookups such as contains are available in GeoDjango when using MySQL, the results returned are really equivalent to what would be returned when using bbcontains on a different spatial backend.

Warning

True spatial indexes (R-trees) are only supported with MyISAM tables on MySQL. [5] In other words, when using MySQL spatial extensions you have to choose between fast spatial lookups and the integrity of your data – MyISAM tables do not support transactions or foreign key constraints.

Raster Support

RasterField is currently only implemented for the PostGIS backend. Spatial lookups are available for raster fields, but spatial database functions and aggregates aren’t implemented for raster fields.

Compatibility Tables

Spatial Lookups

The following table provides a summary of what spatial lookups are available for each spatial database backend. The PostGIS Raster (PGRaster) lookups are divided into the three categories described in the raster lookup details: native support N, bilateral native support B, and geometry conversion support C.

Lookup TypePostGISOracleMySQL [6]SpatiaLitePGRaster
bbcontainsX XXN
bboverlapsX XXN
containedX XXN
containsXXXXB
contains_properlyX   B
coveredbyXX  B
coversXX  B
crossesX  XC
disjointXXXXB
distance_gtXX XN
distance_gteXX XN
distance_ltXX XN
distance_lteXX XN
dwithinXX XB
equalsXXXXC
exactXXXXB
intersectsXXXXB
isvalidXXX (≥ 5.7.5)X (LWGEOM) 
overlapsXXXXB
relateXX XC
same_asXXXXB
touchesXXXXB
withinXXXXB
leftX   C
rightX   C
overlaps_leftX   B
overlaps_rightX   B
overlaps_aboveX   C
overlaps_belowX   C
strictly_aboveX   C
strictly_belowX   C

GeoDjango Model API  Spatial Field Types//

Spatial fields consist of a series of geometry field types and one raster field type. Each of the geometry field types correspond to the OpenGIS Simple Features specification [1]. There is no such standard for raster data.

GeometryField

class GeometryField

The base class for geometry fields.

PointField

class PointField

Stores a Point.

LineStringField

class LineStringField

Stores a LineString.

PolygonField

class PolygonField

Stores a Polygon.

MultiPointField

class MultiPointField

Stores a MultiPoint.

MultiLineStringField

class MultiLineStringField

Stores a MultiLineString.

MultiPolygonField

class MultiPolygonField

Stores a MultiPolygon.

GeometryCollectionField

class GeometryCollectionField

Stores a GeometryCollection.

RasterField

class RasterField

Stores a GDALRaster.

RasterField is currently only implemented for the PostGIS backend.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值