Index: /trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py
===================================================================
--- /trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 381)
+++ /trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 382)
@@ -5,18 +5,25 @@
 import os
 import sys
+import zoo
 
 def readFileFromBuffer(data,ext):
-    geometry=[]
-    osgeo.gdal.FileFromMemBuffer('/vsimem//temp1'+ext,data)
-    ds = osgeo.ogr.Open('/vsimem//temp1'+ext)
-    lyr = ds.GetLayer(0)
-    feat = lyr.GetNextFeature()
-    while feat is not None:
-        geometry+=[feat.Clone()]
-        feat.Destroy()
+    try:
+        geometry=[]
+        print >> sys.stderr,'/vsimem//temp1'+ext
+        #print >> sys.stderr,data
+        osgeo.gdal.FileFromMemBuffer('/vsimem//temp1'+ext,data)
+        ds = osgeo.ogr.Open('/vsimem//temp1'+ext)
+        lyr = ds.GetLayer(0)
         feat = lyr.GetNextFeature()
-    ds.Destroy()
-    osgeo.gdal.Unlink('/vsimem//temp1'+ext)
-    return geometry
+        while feat is not None:
+            geometry+=[feat.Clone()]
+            feat.Destroy()
+            feat = lyr.GetNextFeature()
+        ds.Destroy()
+        osgeo.gdal.Unlink('/vsimem//temp1'+ext)
+        return geometry
+    except Exception,e:
+        print >> sys.stderr,e
+        return []
 
 def buildFeatureFromGeomtry(conf,geom,driverName,ext):
@@ -41,5 +48,9 @@
     try:
         if geom is None:
-            return readFileFromBuffer(my_wfs_response,"")
+            if not(conf["lenv"].has_key("cnt")):
+                conf["lenv"]["cnt"]=0
+            else:
+                conf["lenv"]["cnt"]+=1
+            return readFileFromBuffer(my_wfs_response,str(conf["lenv"]["cnt"]))
         else:
             return buildFeatureFromGeomtry(conf,geom,"GML","xml")
@@ -76,4 +87,14 @@
     i=0
     while i < len(geom):
+        if i==0 and driverName!="GeoJSON":
+            poDstFDefn=geom[i].GetDefnRef()
+            if poDstFDefn is not None:
+                nDstFieldCount = poDstFDefn.GetFieldCount()
+                for iField in range(nDstFieldCount):
+                    poSrcFieldDefn = poDstFDefn.GetFieldDefn(iField)
+                    oFieldDefn = osgeo.ogr.FieldDefn(poSrcFieldDefn.GetNameRef(),poSrcFieldDefn.GetType())
+                    oFieldDefn.SetWidth( poSrcFieldDefn.GetWidth() )
+                    oFieldDefn.SetPrecision( poSrcFieldDefn.GetPrecision() )
+                    lyr.CreateField( oFieldDefn )
         lyr.CreateFeature(geom[i])
         geom[i].Destroy()
@@ -90,6 +111,5 @@
 
 def BufferPy(conf,inputs,outputs):
-    print >> sys.stderr, inputs
-    print >> sys.stderr, outputs
+    print >> sys.stderr, "Starting service ..."
     try:
         bdist=float(inputs["BufferDistance"]["value"])
@@ -97,5 +117,4 @@
         bdist=1
     print >> sys.stderr, bdist
-    
     geometry=extractInputs(conf,inputs["InputPolygon"])
     i=0
@@ -112,5 +131,5 @@
     outputResult(conf,outputs["Result"],rgeometries)
     i=0
-    return 3
+    return zoo.SERVICE_SUCCEEDED
 
 def BoundaryPy(conf,inputs,outputs):
@@ -127,5 +146,5 @@
         i+=1
     outputResult(conf,outputs["Result"],rgeometries)
-    return 3
+    return zoo.SERVICE_SUCCEEDED
 
 def CentroidPy(conf,inputs,outputs):
@@ -144,5 +163,5 @@
         i+=1
     outputResult(conf,outputs["Result"],rgeometries)
-    return 3
+    return zoo.SUCCEEDED
 
 def ConvexHullPy(conf,inputs,outputs):
@@ -158,5 +177,5 @@
         i+=1
     outputResult(conf,outputs["Result"],rgeometries)
-    return 3
+    return zoo.SUCCEEDED
 
 
@@ -198,8 +217,10 @@
 
     geometry1=extractInputs(conf,inputs["InputEntity1"])
-    print >> sys.stderr,inputs["InputEntity2"]
-    geometry2=extractInputs(conf,inputs["InputEntity2"])
-
-    rgeometries=[]
+    geometry2=extractInputs(conf,inputs["InputEntity2"])
+
+    print >> sys.stderr,str(len(geometry1))+" "+str(len(geometry2))
+
+    rgeometries=[]
+    fids=[]
     i=0
     while i < len(geometry1):
@@ -211,6 +232,9 @@
             resg=geometry1[i].GetGeometryRef().Intersection(resg)
             tmp.SetGeometryDirectly(resg)
-            if not(resg.IsEmpty()):
+            if resg is not None and not(resg.IsEmpty()) and fids.count(tmp.GetFID())==0:
                 rgeometries+=[tmp]
+                fids+=[tmp.GetFID()]
+            else:
+                tmp.Destroy()
             j+=1
         geometry1[i].Destroy()
