瀏覽代碼

adding support for being WFS server proxy as well

Jachym Cepicky 14 年之前
父節點
當前提交
455138ff98
共有 3 個文件被更改,包括 52 次插入1 次删除
  1. 11 0
      OWS.py
  2. 1 1
      config.cfg-template
  3. 40 0
      wfs/__init__.py

+ 11 - 0
OWS.py

@@ -277,6 +277,17 @@ def getService():
     qstring = os.environ["QUERY_STRING"]
     params = urlparse.parse_qs(qstring)
 
+    for p in params:
+        if p.lower() == "owsurl":
+            v = params[p]
+            del params[p]
+            params["owsUrl"] = v
+
+        if p.lower() == "owsservice":
+            v = params[p]
+            del params[p]
+            params["owsService"] = v
+
     
     if "owsUrl" in params.keys() and\
         "owsService" in params.keys():

+ 1 - 1
config.cfg-template

@@ -9,5 +9,5 @@ tempdir=/tmp/
 errorfile=stderr
 imagepath=/tmp/mapserv/
 onlineresource=http://localhost/cgi-bin/owsproxy.cgi
-srs=EPSG:4326 EPSG:102067 EPSG:900913 EPSG:3035 EPSG:3857
+srs=EPSG:4326 EPSG:102067 EPSG:900913 EPSG:3035 EPSG:3857 EPSG:900913
 

+ 40 - 0
wfs/__init__.py

@@ -9,6 +9,7 @@ import urllib
 import urlparse
 import logging
 from osgeo import ogr
+import pyproj
 import os
 import re
 
@@ -36,17 +37,25 @@ class WFS(OWS):
 
         logging.debug(self.capabilities.contents)
 
+        srss = []
+
         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]
 
             logging.debug("Creating layer %s" % name)
 
+            srss = srss+filter(lambda y: not y in srss,layer.crsOptions)
+
             lyrobj = mapscript.layerObj(mapobj)
             #lyrobj.name = name.replace(":","_")
             lyrobj.name = name
             lyrobj.title = layer.title
             if layer.title:
                 lyrobj.setMetaData("wms_title",layer.title)
+                lyrobj.setMetaData("wfs_title",layer.title)
             #if layer.abstract:
             #    lyrobj.setMetaData("ows_abstract",  layer.abstract)
             lyrobj.setMetaData("wfs_typename", name)
@@ -62,12 +71,15 @@ class WFS(OWS):
                 if extent:
                     lyrobj.setMetaData("wms_extent","%s %s %s %s" % \
                             (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)
             else:
                 mapobj.removeLayer(mapobj.numlayers-1)
                 logging.debug("No ogrDataSource found")
                 continue
 
+            #lyrobj.setProjection(self.__getLayerCrs(layer.crsOptions))
             lyrobj.setProjection(layer.crsOptions[0])
 
             lyrobj.dump = mapscript.MS_TRUE 
@@ -79,6 +91,11 @@ class WFS(OWS):
             style.size=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)
         return mapobj
     
@@ -96,8 +113,10 @@ class WFS(OWS):
 
         if 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:
             mapobj.setMetaData("wms_abstract",self.capabilities.identification.abstract)
+            mapobj.setMetaData("wfs_abstract",self.capabilities.identification.abstract)
 
     def _getLayerType(self,layer):
         """Returns MS layer type based on ogr.Layer.GetGeomType
@@ -140,3 +159,24 @@ class WFS(OWS):
                return mapscript.MS_LAYER_LINE
         else:
                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]
+
+