Browse Source

wcs fixes

Jachym Cepicky 14 năm trước cách đây
mục cha
commit
ace75b7ba9
2 tập tin đã thay đổi với 28 bổ sung15 xóa
  1. 5 0
      OWS.py
  2. 23 15
      wcs/__init__.py

+ 5 - 0
OWS.py

@@ -165,9 +165,11 @@ class OWS:
 
         # if no 'map' parameter in URL, create new mapfile
         if not request.getValueByName("map"):
+            logging.debug("Creating new mapfile")
             mapobj = self.makeMap()
         else:
             # there is 'map' parameter in URL and the file exists, load it
+            logging.debug("Using existing mapfile %s" % request.getValueByName("map"))
             if os.path.isfile(request.getValueByName("map")):
                 mapobj = mapscript.mapObj(request.getValueByName("map"))
             # there is 'map' parameter in URL BUT the file does not exist:
@@ -196,6 +198,9 @@ class OWS:
         mapobj.setExtent(-180,-90,90,180)
 
         logging.debug("Setting ERRORFILE to %s"%self.config.get("MapServer","errorfile"))
+        if not os.path.exists(self.config.get("MapServer","errorfile")):
+            tmp = open(self.config.get("MapServer","errorfile"),"w")
+            tmp.close()
         if os.access(self.config.get("MapServer","errorfile"), os.W_OK):
             mapobj.setConfigOption("MS_ERRORFILE",self.config.get("MapServer","errorfile"))
         else:

+ 23 - 15
wcs/__init__.py

@@ -21,6 +21,9 @@ class WCS(OWS):
         OWS.__init__(self,url,qstring)
 
     def makeMap(self,mapfilename=None):
+
+        lyrobj = None
+
         self.version = self.capabilities.attrib["version"]
         self.wcsns = self.capabilities.nsmap[self.capabilities.prefix]
 
@@ -36,21 +39,26 @@ class WCS(OWS):
                     os.path.join( os.path.dirname(__file__), "templates",'wcs.xml'))
 
             ds = gdal.Open(layerDefFile)
-            lyrobj = mapscript.layerObj(mapobj)
-            lyrobj.name = name
-            lyrobj.data = layerDefFile
-            lyrobj.title = layer["{%s}%s" % (self.owsns11,"Title")].text
-            lyrobj.setMetaData("wms_title",layer["{%s}%s" % (self.owsns11,"Title")].text)
-            if "{%s}%s" % (self.owsns11,"Abstract") in layer:
-                lyrobj.setMetaData("ows_abstract",  layer["{%s}%s" % (self.owsns11,"Abstract")].text)
-            sr = osr.SpatialReference()
-            sr.ImportFromWkt(ds.GetProjection())
-            lyrobj.setProjection(sr.ExportToProj4())
-            lyrobj.type = mapscript.MS_LAYER_RASTER
-            lyrobj.dump = mapscript.MS_TRUE
-            lyrobj.template = "foo"
-            cls = mapscript.classObj(lyrobj)
-            mapscript.styleObj(cls)
+            try:
+                lyrobj = mapscript.layerObj(mapobj)
+                lyrobj.name = name
+                lyrobj.data = layerDefFile
+                lyrobj.title = layer["{%s}%s" % (self.owsns11,"Title")].text
+                lyrobj.setMetaData("wms_title",layer["{%s}%s" % (self.owsns11,"Title")].text)
+                if "{%s}%s" % (self.owsns11,"Abstract") in layer:
+                    lyrobj.setMetaData("ows_abstract",  layer["{%s}%s" % (self.owsns11,"Abstract")].text)
+                sr = osr.SpatialReference()
+                sr.ImportFromWkt(ds.GetProjection())
+                lyrobj.setProjection(sr.ExportToProj4())
+                lyrobj.type = mapscript.MS_LAYER_RASTER
+                lyrobj.dump = mapscript.MS_TRUE
+                lyrobj.template = "foo"
+                cls = mapscript.classObj(lyrobj)
+                mapscript.styleObj(cls)
+            except Exception,e:
+                mapobj.removeLayer(lyrobj.index)
+                logging.warning("Could not GetProjection of %s: %s, skipping." %\
+                                (layer.Identifier.text,e))
 
         self.saveMapfile(mapobj,mapfilename)
         return mapobj