|
@@ -9,6 +9,7 @@ import urllib
|
|
|
import urlparse
|
|
import urlparse
|
|
|
import logging
|
|
import logging
|
|
|
from osgeo import ogr
|
|
from osgeo import ogr
|
|
|
|
|
+import pyproj
|
|
|
import os
|
|
import os
|
|
|
import re
|
|
import re
|
|
|
|
|
|
|
@@ -34,17 +35,27 @@ class WFS(OWS):
|
|
|
|
|
|
|
|
self.setMapName(mapobj)
|
|
self.setMapName(mapobj)
|
|
|
|
|
|
|
|
|
|
+ logging.debug(self.capabilities.contents)
|
|
|
|
|
+
|
|
|
|
|
+ srss = []
|
|
|
|
|
+
|
|
|
for name in self.capabilities.contents:
|
|
for name in self.capabilities.contents:
|
|
|
|
|
+
|
|
|
|
|
+ mapobj.setMetaData("wms_srs",self.config.get("MapServer","srs"))
|
|
|
|
|
+ mapobj.setMetaData("wfs_srs",self.config.get("MapServer","srs"))
|
|
|
layer = self.capabilities.contents[name]
|
|
layer = self.capabilities.contents[name]
|
|
|
|
|
|
|
|
logging.debug("Creating layer %s" % name)
|
|
logging.debug("Creating layer %s" % name)
|
|
|
|
|
|
|
|
|
|
+ srss = srss+filter(lambda y: not y in srss,layer.crsOptions)
|
|
|
|
|
+
|
|
|
lyrobj = mapscript.layerObj(mapobj)
|
|
lyrobj = mapscript.layerObj(mapobj)
|
|
|
- lyrobj.name = name.replace(":","_")
|
|
|
|
|
- #lyrobj.name = name
|
|
|
|
|
|
|
+ #lyrobj.name = name.replace(":","_")
|
|
|
|
|
+ lyrobj.name = name
|
|
|
lyrobj.title = layer.title
|
|
lyrobj.title = layer.title
|
|
|
if layer.title:
|
|
if layer.title:
|
|
|
lyrobj.setMetaData("wms_title",layer.title)
|
|
lyrobj.setMetaData("wms_title",layer.title)
|
|
|
|
|
+ lyrobj.setMetaData("wfs_title",layer.title)
|
|
|
#if layer.abstract:
|
|
#if layer.abstract:
|
|
|
# lyrobj.setMetaData("ows_abstract", layer.abstract)
|
|
# lyrobj.setMetaData("ows_abstract", layer.abstract)
|
|
|
lyrobj.setMetaData("wfs_typename", name)
|
|
lyrobj.setMetaData("wfs_typename", name)
|
|
@@ -61,12 +72,15 @@ class WFS(OWS):
|
|
|
if extent:
|
|
if extent:
|
|
|
lyrobj.setMetaData("wms_extent","%s %s %s %s" % \
|
|
lyrobj.setMetaData("wms_extent","%s %s %s %s" % \
|
|
|
(extent[0],extent[1],extent[2],extent[3]))
|
|
(extent[0],extent[1],extent[2],extent[3]))
|
|
|
|
|
+ lyrobj.setMetaData("wfs_extent","%s %s %s %s" % \
|
|
|
|
|
+ (extent[0],extent[1],extent[2],extent[3]))
|
|
|
lyrobj.type = self._getLayerType(ogrLayer)
|
|
lyrobj.type = self._getLayerType(ogrLayer)
|
|
|
else:
|
|
else:
|
|
|
mapobj.removeLayer(mapobj.numlayers-1)
|
|
mapobj.removeLayer(mapobj.numlayers-1)
|
|
|
logging.debug("No ogrDataSource found")
|
|
logging.debug("No ogrDataSource found")
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
|
|
+ #lyrobj.setProjection(self.__getLayerCrs(layer.crsOptions))
|
|
|
lyrobj.setProjection(layer.crsOptions[0])
|
|
lyrobj.setProjection(layer.crsOptions[0])
|
|
|
|
|
|
|
|
lyrobj.dump = mapscript.MS_TRUE
|
|
lyrobj.dump = mapscript.MS_TRUE
|
|
@@ -78,6 +92,11 @@ class WFS(OWS):
|
|
|
style.size=5
|
|
style.size=5
|
|
|
style.width=5
|
|
style.width=5
|
|
|
|
|
|
|
|
|
|
+ ## overwrite already set SRSs
|
|
|
|
|
+ #if len(srss) > 0:
|
|
|
|
|
+ # logging.debug("Overwriting SRS option")
|
|
|
|
|
+ # mapobj.setMetaData("wms_srs"," ".join(srss))
|
|
|
|
|
+
|
|
|
self.saveMapfile(mapobj,mapfilename)
|
|
self.saveMapfile(mapobj,mapfilename)
|
|
|
return mapobj
|
|
return mapobj
|
|
|
|
|
|
|
@@ -95,8 +114,10 @@ class WFS(OWS):
|
|
|
|
|
|
|
|
if self.capabilities.identification.title:
|
|
if self.capabilities.identification.title:
|
|
|
mapobj.setMetaData("wms_title",self.capabilities.identification.title)
|
|
mapobj.setMetaData("wms_title",self.capabilities.identification.title)
|
|
|
|
|
+ mapobj.setMetaData("wfs_title",self.capabilities.identification.title)
|
|
|
if self.capabilities.identification.abstract:
|
|
if self.capabilities.identification.abstract:
|
|
|
mapobj.setMetaData("wms_abstract",self.capabilities.identification.abstract)
|
|
mapobj.setMetaData("wms_abstract",self.capabilities.identification.abstract)
|
|
|
|
|
+ mapobj.setMetaData("wfs_abstract",self.capabilities.identification.abstract)
|
|
|
|
|
|
|
|
def _getLayerType(self,layer):
|
|
def _getLayerType(self,layer):
|
|
|
"""Returns MS layer type based on ogr.Layer.GetGeomType
|
|
"""Returns MS layer type based on ogr.Layer.GetGeomType
|
|
@@ -124,6 +145,13 @@ class WFS(OWS):
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
geomType = layer.GetGeomType()
|
|
geomType = layer.GetGeomType()
|
|
|
|
|
+ if geomType == 0: # unknown
|
|
|
|
|
+ # brutal force way
|
|
|
|
|
+ f = layer.GetNextFeature()
|
|
|
|
|
+ if f:
|
|
|
|
|
+ gr = f.GetGeometryRef()
|
|
|
|
|
+ geomType = gr.GetGeometryType()
|
|
|
|
|
+
|
|
|
if geomType in [ogr.wkbPolygon,
|
|
if geomType in [ogr.wkbPolygon,
|
|
|
ogr.wkbMultiPolygon,
|
|
ogr.wkbMultiPolygon,
|
|
|
ogr.wkbLinearRing]:
|
|
ogr.wkbLinearRing]:
|
|
@@ -133,3 +161,24 @@ class WFS(OWS):
|
|
|
return mapscript.MS_LAYER_LINE
|
|
return mapscript.MS_LAYER_LINE
|
|
|
else:
|
|
else:
|
|
|
return mapscript.MS_LAYER_POINT
|
|
return mapscript.MS_LAYER_POINT
|
|
|
|
|
+
|
|
|
|
|
+ def __getLayerCrs(self,crss):
|
|
|
|
|
+ """
|
|
|
|
|
+ Returns bests (non-degree) coordinate system of the layer, which is
|
|
|
|
|
+ available.
|
|
|
|
|
+
|
|
|
|
|
+ Ofcourse, sometimes, there is no other option, there EPSG:4326, but
|
|
|
|
|
+ take somethign else, if you can
|
|
|
|
|
+ """
|
|
|
|
|
+ for crs in crss:
|
|
|
|
|
+ try:
|
|
|
|
|
+ proj = pyproj.Proj("+init=%s"%crs)
|
|
|
|
|
+ if proj.is_latlon():
|
|
|
|
|
+ continue
|
|
|
|
|
+ else:
|
|
|
|
|
+ return crs
|
|
|
|
|
+ except:
|
|
|
|
|
+ pass
|
|
|
|
|
+ return crss[0]
|
|
|
|
|
+
|
|
|
|
|
+
|