以大地测量为基础的WMS框架
django-wms的Python项目详细描述
django wms框架是一个使构建Web Map Service (WMS)或x-y-zTile Map Service变得容易的工具包。支持矢量和光栅数据格式的渲染。
有关完整文档,请转到http://django-wms.readthedocs.org
要求
django wms中空间数据的处理依赖于MapServer及其python绑定MapScript。光栅数据集成依赖于django-raster包。还需要使用PostGIS作为数据库后端,对于光栅积分postgis>;=2.0,也需要使用(另请参见django光栅包)。
安装
使用pip install django-wms
安装包将“wms”添加到已安装的应用程序设置中,如下所示:
INSTALLED_APPS = ( ... 'wms', )
示例
< P>创建映射服务,将Django WMS层、MAP和View类分为子类,并将它们连接到具有空间域(如Point、多边形或多多边形)的Django中的现有模型。示例wms_config.py模块可以指定如下### wms_config.py # Load django-wms classes from wms import maps, layers, views # Load model with spatial field (Point, Polygon or MultiPolygon) from myapp.models import MySpatialModel # Subclass the WmsVectorLayer class and point it to a spatial model. # Use WmsRasterLayer for rasters class MyWmsLayer(layers.WmsVectorLayer): model = MySpatialModel # Subclass the WmsMap class and add the layer to it class MyWmsMap(maps.WmsMap): layer_classes = [ MyWmsLayer ] # Subclass the WmsView to create a view for the map class MyWmsView(views.WmsView): map_class = MyWmsMap
在wmsview子类就位之后,创建功能映射服务所剩下的唯一工作就是将视图挂接到url中。示例url配置urls.py可以是
### urls.py # Import the wms view from myproject.wms_config import MyWmsView # Add url patterns to setup map services from the view urlpatterns = patterns('', # This creates a WMS endpoint url(r'^wms/$', MyWmsView.as_view(), name='wms'), # This creates a TMS endpoint url(r'^tile/(?P<layers>[^/]+)/(?P<z>[0-9]+)/(?P<x>[0-9]+)/(?P<y>[0-9]+)(?P<format>\.jpg|\.png)$', MyWmsView.as_view(), name='tms'), )
django wms包将自动检测它可以在MySpatialModel中找到的第一个空间字段,并从基于类的视图中创建wms端点。如果在urlpattern中找到了三个参数x、y和z,则视图将充当tms端点。