Jachym Cepicky пре 13 година
родитељ
комит
a4bdc39a81
1 измењених фајлова са 22 додато и 7 уклоњено
  1. 22 7
      wfs/__init__.py

+ 22 - 7
wfs/__init__.py

@@ -93,8 +93,8 @@ class WFS(OWS):
         featureid = request.getValueByName("featureid")
         featureversion = request.getValueByName("featureversion")
         datadir = os.path.join(self.cachedir,"cache")
+        layerobj = self.mapobj.getLayerByName(typename)
 
-        layer = self.capabilities.contents[typename]
         crs = self.__getLayerCrs(layer.crsOptions)
         version = request.getValueByName("version")
 
@@ -107,6 +107,14 @@ class WFS(OWS):
 
         bbox = self.__adjustBBox(bbox,requestCrs, crs,version)
 
+        # do not take anything behind max extent
+        #bbox[0] = layerobj.extent.minx if layerobj.extent.minx >= bbox[0] else bbox[0]
+        #bbox[1] = layerobj.extent.miny if layerobj.extent.miny >= bbox[1] else bbox[1]
+        #bbox[2] = layerobj.extent.maxx if layerobj.extent.maxx <= bbox[2] else bbox[2]
+        #bbox[3] = layerobj.extent.maxy if layerobj.extent.maxy <= bbox[3] else bbox[3]
+
+        bbox = map(lambda x: round(float(x),4), bbox)
+
         # clear dir
         outfn = None 
 
@@ -118,11 +126,11 @@ class WFS(OWS):
                 if os.path.isfile(bboxfile) and not os.path.isfile(filterfile)\
                         and not fes:
                     # convert "string" to [floats] as [minx,miny,maxx,maxy]
-                    storedbbox = map(lambda x: float(x), open(bboxfile).read().split(","))
-                    if round(storedbbox[0],4) <= round(bbox[0],4) and\
-                    round(storedbbox[1],4) <= round(bbox[1],4) and \
-                    round(storedbbox[2],4) >= round(bbox[2],4) and \
-                    round(storedbbox[3],4) >= round(bbox[3],4):
+                    storedbbox = map(lambda x: round(float(x),4), open(bboxfile).read().split(","))
+                    if storedbbox[0] <= bbox[0] and\
+                    storedbbox[1] <= bbox[1] and \
+                    storedbbox[2] >= bbox[2] and \
+                    storedbbox[3] >= bbox[3]:
                         logging.info(
                                 "Using cached file for type [%s] with bbox [%f,%f,%f,%f], not downloading new data"%\
                                         (typename, bbox[0],bbox[1],bbox[2],bbox[3]))
@@ -177,13 +185,20 @@ class WFS(OWS):
 
             cachefile.write(feature.read())
             cachefile.close()
+
+            # check
+            check = ogr.Open(cachefile.name)
+            if not check:
+                self.__clear(datadir,typename)
+            else:
+                check.Destroy()
+
             #ds = ogr.Open(cachefile.name)
             #drv = ogr.GetDriverByName(ds.GetDriver().name)
             #out = drv.CopyDataSource(ds,outfn)
             #out.Destroy()
 
         # set layer connection
-        layerobj = self.mapobj.getLayerByName(typename)
         layerobj.connection = os.path.abspath(outfn)
 
         # data are downloaded