Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 256)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 257)
@@ -1,26 +1,42 @@
+from osgeo import *
 import osgeo.ogr
+import osgeo.gdal
 import libxml2
 import os
 import sys
 
-def createGeometryFromWFS(my_wfs_response):
-    doc=libxml2.parseMemory(my_wfs_response,len(my_wfs_response))
-    ctxt = doc.xpathNewContext()
-    res=ctxt.xpathEval("/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon' or local-name()='Point' or local-name()='MultiPoint' or local-name()='MultiLineString' or local-name()='LineString' ]")
+def createGeometryFromWFS(conf,my_wfs_response):
     geometry=[]
     try:
-        for node in res:
-            geometry_as_string=node.serialize()
-            geometry+=[osgeo.ogr.CreateGeometryFromGML(geometry_as_string)]
+        # Create virtual file or parse XML file depending on the GDAL Version
+        gV=int(osgeo.gdal.VersionInfo())
+        if gV >= 1800:
+            osgeo.gdal.FileFromMemBuffer('/vsimem//temp', my_wfs_response)
+            ds = osgeo.ogr.Open('/vsimem//temp')
+            lyr = ds.GetLayer(0)
+            feat = lyr.GetNextFeature()
+            while feat is not None:
+                geometry+=[feat.GetGeometryRef().Clone()]
+                feat.Destroy()
+                feat = lyr.GetNextFeature()
+            ds.Destroy()
+            osgeo.gdal.Unlink('/vsimem//temp')
+        else:
+            doc=libxml2.parseMemory(my_wfs_response,len(my_wfs_response))
+            ctxt = doc.xpathNewContext()
+            res=ctxt.xpathEval("/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon' or local-name()='Point' or local-name()='MultiPoint' or local-name()='MultiLineString' or local-name()='LineString' ]")
+            for node in res:
+                geometry_as_string=node.serialize()
+                geometry+=[osgeo.ogr.CreateGeometryFromGML(geometry_as_string)]
     except:
-        print >> sys.stderr,"Error"
+        print >> sys.stderr,"Unable to load file from mem buffer\n\n\n"
     return geometry
 
-def extractInputs(obj):
+def extractInputs(conf,obj):
     if obj["mimeType"]=="application/json":
 	return [osgeo.ogr.CreateGeometryFromJson(obj["value"])]
     else:
 	try:
-        	return createGeometryFromWFS(obj["value"])
+        	return createGeometryFromWFS(conf,obj["value"])
 	except:
 		return [osgeo.ogr.CreateGeometryFromJson(obj["value"])]
@@ -34,5 +50,10 @@
         extension = [ ".js" ]
     drv = osgeo.ogr.GetDriverByName( driverName )
-    ds = drv.CreateDataSource( conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0] )
+    # Create virtual file or real one depending on the GDAL Version
+    gV=int(osgeo.gdal.VersionInfo())
+    if gV >= 1800:
+        ds = drv.CreateDataSource( "/vsimem/store"+conf["lenv"]["sid"]+extension[0] )
+    else:
+        ds = drv.CreateDataSource( conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0] )
     lyr = ds.CreateLayer( "Result", None, osgeo.ogr.wkbUnknown )
     field_defn = osgeo.ogr.FieldDefn( "Name", osgeo.ogr.OFTString )
@@ -49,11 +70,22 @@
         i+=1
     ds.Destroy()
-    obj["value"]=open(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0],"r").read()
-    os.unlink(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0])
-    if len(extension)>1:
-        os.unlink(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[1])
+    if gV >= 1800:
+        vsiFile=osgeo.gdal.VSIFOpenL("/vsimem/store"+conf["lenv"]["sid"]+extension[0],"r")
+        i=0
+        while osgeo.gdal.VSIFSeekL(vsiFile,0,os.SEEK_END)>0:
+            i+=1
+        fileSize=osgeo.gdal.VSIFTellL(vsiFile)
+        osgeo.gdal.VSIFSeekL(vsiFile,0,os.SEEK_SET)
+        obj["value"]=osgeo.gdal.VSIFReadL(fileSize,1,vsiFile)
+        osgeo.gdal.Unlink("/vsimem/store"+conf["lenv"]["sid"]+extension[0])
+    else:
+        obj["value"]=open(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0],"r").read()
+        os.unlink(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0])
+        if len(extension)>1:
+            os.unlink(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[1])
+    
 
 def BoundaryPy(conf,inputs,outputs):
-    geometry=extractInputs(inputs["InputPolygon"])
+    geometry=extractInputs(conf,inputs["InputPolygon"])
     i=0
     rgeometries=[]
@@ -66,5 +98,5 @@
 
 def CentroidPy(conf,inputs,outputs):
-    geometry=extractInputs(inputs["InputPolygon"])
+    geometry=extractInputs(conf,inputs["InputPolygon"])
     i=0
     rgeometries=[]
@@ -79,5 +111,5 @@
 
 def ConvexHullPy(conf,inputs,outputs):
-    geometry=extractInputs(inputs["InputPolygon"])
+    geometry=extractInputs(conf,inputs["InputPolygon"])
     i=0
     rgeometries=[]
@@ -94,5 +126,5 @@
     except:
         bdist=10
-    geometry=extractInputs(inputs["InputPolygon"])
+    geometry=extractInputs(conf,inputs["InputPolygon"])
     i=0
     rgeometries=[]
@@ -106,6 +138,6 @@
 
 def UnionPy(conf,inputs,outputs):
-    geometry1=extractInputs(inputs["InputEntity1"])
-    geometry2=extractInputs(inputs["InputEntity2"])
+    geometry1=extractInputs(conf,inputs["InputEntity1"])
+    geometry2=extractInputs(conf,inputs["InputEntity2"])
     rgeometries=[]
     i=0
@@ -127,6 +159,6 @@
 
 def IntersectionPy(conf,inputs,outputs):
-    geometry1=extractInputs(inputs["InputEntity1"])
-    geometry2=extractInputs(inputs["InputEntity2"])
+    geometry1=extractInputs(conf,inputs["InputEntity1"])
+    geometry2=extractInputs(conf,inputs["InputEntity2"])
     rgeometries=[]
     i=0
@@ -148,6 +180,6 @@
 
 def DifferencePy(conf,inputs,outputs):
-    geometry1=extractInputs(inputs["InputEntity1"])
-    geometry2=extractInputs(inputs["InputEntity2"])
+    geometry1=extractInputs(conf,inputs["InputEntity1"])
+    geometry2=extractInputs(conf,inputs["InputEntity2"])
     rgeometries=[]
     i=0
@@ -169,6 +201,6 @@
 
 def SymDifferencePy(conf,inputs,outputs):
-    geometry1=extractInputs(inputs["InputEntity1"])
-    geometry2=extractInputs(inputs["InputEntity2"])
+    geometry1=extractInputs(conf,inputs["InputEntity1"])
+    geometry2=extractInputs(conf,inputs["InputEntity2"])
     rgeometries=[]
     i=0
