图形数据后台管理
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 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.
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.
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 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’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 [
Contains
,Crosses
,Disjoint
,Intersects
,Overlaps
,Touches
,Within
] 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.
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.
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 Type | PostGIS | Oracle | MySQL [6] | SpatiaLite | PGRaster |
---|---|---|---|---|---|
bbcontains | X | X | X | N | |
bboverlaps | X | X | X | N | |
contained | X | X | X | N | |
contains | X | X | X | X | B |
contains_properly | X | B | |||
coveredby | X | X | B | ||
covers | X | X | B | ||
crosses | X | X | C | ||
disjoint | X | X | X | X | B |
distance_gt | X | X | X | N | |
distance_gte | X | X | X | N | |
distance_lt | X | X | X | N | |
distance_lte | X | X | X | N | |
dwithin | X | X | X | B | |
equals | X | X | X | X | C |
exact | X | X | X | X | B |
intersects | X | X | X | X | B |
isvalid | X | X | X (≥ 5.7.5) | X (LWGEOM) | |
overlaps | X | X | X | X | B |
relate | X | X | X | C | |
same_as | X | X | X | X | B |
touches | X | X | X | X | B |
within | X | X | X | X | B |
left | X | C | |||
right | X | C | |||
overlaps_left | X | B | |||
overlaps_right | X | B | |||
overlaps_above | X | C | |||
overlaps_below | X | C | |||
strictly_above | X | C | |||
strictly_below | X | C |
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.