|
|
@@ -56,31 +56,40 @@ class WFS(OWS):
|
|
|
self.mapfilename = request.getValueByName("map")
|
|
|
|
|
|
# download data
|
|
|
- if self.request.upper() == "GETMAP":
|
|
|
+ if self.request.upper() in ["GETMAP", "GETFEATUREINFO"]:
|
|
|
dataFile = self.getData(request,typename,layer)
|
|
|
+ if not ogr.Open(dataFile):
|
|
|
+ dataFile = self.getData(request,typename,layer)
|
|
|
if dataFile:
|
|
|
#layer.data = dataFile.name
|
|
|
pass
|
|
|
|
|
|
|
|
|
+ mapscript.msIO_installStdoutToBuffer()
|
|
|
res = self.mapobj.OWSDispatch(request)
|
|
|
|
|
|
- layerobj = self.mapobj.getLayerByName(typename)
|
|
|
-
|
|
|
if mapscript.MS_DONE == res:
|
|
|
raise OWSExceptions.NoValidRequest("No valid OWS Request")
|
|
|
elif mapscript.MS_FAILURE == res:
|
|
|
pass
|
|
|
#raise OWSExceptions.RequestFailed("Request failed")
|
|
|
|
|
|
+
|
|
|
+ print "Content-type: %s\n" % (mapscript.msIO_stripStdoutBufferContentType())
|
|
|
+ # HACK HACK HACK
|
|
|
+ # Fix missing namespace encoding for ArcIMS and similar layers
|
|
|
+ if self.request.upper() == "GETFEATUREINFO" and\
|
|
|
+ typename.find(":") > -1:
|
|
|
+ print self.__fixNamespace(typename)
|
|
|
+ else:
|
|
|
+ print mapscript.msIO_getStdoutBufferBytes()
|
|
|
+
|
|
|
def getData(self,request,typename,layer):
|
|
|
"""Download data from WFS server and store them to local harddrive
|
|
|
"""
|
|
|
|
|
|
fes = request.getValueByName("fes")
|
|
|
bbox = request.getValueByName("bbox").split(",")
|
|
|
- import sys
|
|
|
- print >>sys.stderr, "###########",bbox
|
|
|
featureid = request.getValueByName("featureid")
|
|
|
featureversion = request.getValueByName("featureversion")
|
|
|
datadir = os.path.join(self.cachedir,"cache")
|
|
|
@@ -110,10 +119,10 @@ class WFS(OWS):
|
|
|
and not fes:
|
|
|
# convert "string" to [floats] as [minx,miny,maxx,maxy]
|
|
|
storedbbox = map(lambda x: float(x), open(bboxfile).read().split(","))
|
|
|
- if storedbbox[0] <= bbox[0] and\
|
|
|
- storedbbox[1] <= bbox[1] and \
|
|
|
- storedbbox[2] >= bbox[2] and \
|
|
|
- storedbbox[3] >= bbox[3]:
|
|
|
+ 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):
|
|
|
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]))
|
|
|
@@ -145,24 +154,33 @@ class WFS(OWS):
|
|
|
|
|
|
# create chace file
|
|
|
outfn= os.path.join(datadir,"%s.gml"%typename)
|
|
|
- cacheFile = open(outfn,"w")
|
|
|
+ #cachefile = open(os.path.join(datadir,"%s.gmlorig"%typename),"w")
|
|
|
+ cachefile = open(outfn,"w")
|
|
|
|
|
|
# download feature from WFS
|
|
|
logging.debug("Downloading data [%s] from bbox [%f,%f,%f,%f]"%\
|
|
|
(typename, bbox[0],bbox[1],bbox[2],bbox[3]))
|
|
|
bbox.append(crs.getcode())
|
|
|
- import sys
|
|
|
- print >>sys.stderr, typename, bbox, fes, crs.getcode()
|
|
|
feature = self.capabilities.getfeature(
|
|
|
typename=typename,
|
|
|
bbox=bbox,
|
|
|
filter=fes,
|
|
|
- srsname=crs.getcode())
|
|
|
-
|
|
|
- self.capabilities
|
|
|
-
|
|
|
- cacheFile.write(feature.read())
|
|
|
- cacheFile.close()
|
|
|
+ srsname=crs.getcode(),
|
|
|
+ propertyname=None)
|
|
|
+
|
|
|
+ # features are here
|
|
|
+ # now take OGR and convert downloaded data into OGR-readable
|
|
|
+ # format
|
|
|
+ # this will ommit some GML-specific issues (like namespaces
|
|
|
+ # etc.)
|
|
|
+ # data will be stored into target file name
|
|
|
+
|
|
|
+ cachefile.write(feature.read())
|
|
|
+ cachefile.close()
|
|
|
+ #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)
|
|
|
@@ -171,6 +189,7 @@ class WFS(OWS):
|
|
|
# data are downloaded
|
|
|
# make sure, they have propper axis order - x,y
|
|
|
if self.capabilities.version == "1.1.0" and crs.axisorder == "yx":
|
|
|
+ pass
|
|
|
logging.debug("Setting GML_INVERT_AXIS_ORDER_IF_LAT_LONG variable to YES")
|
|
|
gdal.SetConfigOption("GML_INVERT_AXIS_ORDER_IF_LAT_LONG","YES")
|
|
|
gdal.SetConfigOption("GML_CONSIDER_EPSG_AS_URN","YES")
|
|
|
@@ -406,3 +425,19 @@ class WFS(OWS):
|
|
|
if i.find(typename) == 0:
|
|
|
logging.debug("Removing pre-cached file %s"% i)
|
|
|
os.remove(os.path.join(datadir,i))
|
|
|
+
|
|
|
+ def __fixNamespace(self,typename):
|
|
|
+ """Fix missing namespace in output XML
|
|
|
+ """
|
|
|
+ content = mapscript.msIO_getStdoutBufferBytes()
|
|
|
+
|
|
|
+ # look after something like
|
|
|
+ # <namespace:layerName_layer> and add namespace definition
|
|
|
+
|
|
|
+ if typename.find(":") == -1:
|
|
|
+ return content
|
|
|
+
|
|
|
+ (prefix,name) = typename.split(":")
|
|
|
+ namespace = self.capabilities._capabilities.nsmap[prefix]
|
|
|
+ return content.replace("<%s:%s%s>"%(prefix,name,"_layer"),
|
|
|
+ "<%s:%s%s xmlns:%s=\"%s\">"%(prefix,name,"_layer",prefix,namespace))
|