Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/Makefile
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/Makefile	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/Makefile	(revision 491)
@@ -3,6 +3,12 @@
 CFLAGS=${ZOO_CFLAGS} ${JSCFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} `geos-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG
 
+ifneq ($(MS_FILE),)
+	MS_FILES=${ZRPATH}/zoo-kernel/${MS_FILE} -lmapserver
+else
+	MS_FILES=
+endif
+
 cgi-env/ogr_service.zo: service.c
-	g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o ${JS_LDFLAGS} ${JSLDFLAGS} ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} `geos-config --libs`
+	g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o ${JS_LDFLAGS} ${JSLDFLAGS} ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} `geos-config --libs` ${MS_FILES} -lfcgi
 
 clean:
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg	(revision 491)
@@ -1,5 +1,5 @@
 [Boundary]
  Title = Compute boundary.
- Abstract = A new geometry object is created and returned containing the boundary of the geometry on which the method is invoked. 
+ Abstract = This service shall return a feature callection representing the combinatorial boundary of each geometry in the InputPolygon feature collection.
  processVersion = 1
  storeSupported = true
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg	(revision 491)
@@ -1,5 +1,5 @@
 [Buffer]
  Title = Create a buffer around a polygon. 
- Abstract = Create a buffer around a single polygon. Accepts the polygon as GML and provides GML output for the buffered feature. 
+ Abstract = This service shall return a feature collection representing the buffer of geometry InputPolygon at distance BufferDistance. The buffer of a geometry at distance d is the Polygon or MultiPolygon which contains all points within a distance d of the geometry.
  Profile = urn:ogc:wps:1.0.0:buffer
  processVersion = 2
@@ -63,10 +63,4 @@
     </Default>
     <Supported>
-     mimeType = text/xml
-     encoding = base64
-     schema = http://fooa/gml/3.1.0/polygon.xsd
-     extension = xml
-    </Supported>
-    <Supported>
      mimeType = application/json
      encoding = UTF-8
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg	(revision 491)
@@ -1,5 +1,5 @@
 [Centroid]
  Title = Get the centroid of a polygon. 
- Abstract = Compute the geometry centroid.
+ Abstract = This service shall return the point that is the geometric centre of gravity of the geometry InputPolygon.
  Profile = urn:ogc:wps:1.0.0:centroid
  processVersion = 2
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Contains.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Contains.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Contains.zcfg	(revision 491)
@@ -0,0 +1,57 @@
+[Contains]
+ Title = Contains
+ Abstract = This service shall return a true value if and only if the geometry g2 lies in the closure (boundary union interior) of geometry g1 - the inverse of Within(g1: Geometry, g2: Geometry).
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Contains result
+   Abstract = A value true or false if the geometry1 contains the geometry2.
+   <MetaData>
+    title = Mon test  
+   </MetaData>   
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg	(revision 491)
@@ -1,5 +1,5 @@
 [ConvexHull]
  Title = Compute convex hull.
- Abstract = A new geometry object is created and returned containing the convex hull of the geometry on which the method is invoked.
+ Abstract = This service shall return a feature collection that represents the convex hull of geometry InputPolygon. The convex hull is the smallest convex polygon that contains all points of the geometry. The convex Hull for a geometry of encoding data type Point is the point itself
  processVersion = 1
  storeSupported = true
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Crosses.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Crosses.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Crosses.zcfg	(revision 491)
@@ -0,0 +1,57 @@
+[Crosses]
+ Title = Crosses test
+ Abstract = This service shall return a true value if and only if the geometries g1 and g2 share some but neither is containe in the other, and the dimension of the intersection is less than that of both of the geometries.
+ processVersion = 2
+ profile = urn:ogc:wps:1.0.0:union
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Disjoint result
+   Abstract = true if disjoint.
+   <MetaData>
+    title = Mon test  
+   </MetaData>   
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg	(revision 491)
@@ -1,5 +1,5 @@
 [Difference]
  Title = Compute difference. . 
- Abstract = Generates a new geometry which is the region of this geometry with the region of the other geometry removed.
+ Abstract = This function SHALL return a bag of geometry values representing the closure of the set difference between the two geometries InputEntity1 and InputEntity2. The difference is the set of all points which lie on InputEntity1 but not on InputEntity2.
  Profile = urn:ogc:wps:1.0.0:difference
  processVersion = 2
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Disjoint.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Disjoint.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Disjoint.zcfg	(revision 491)
@@ -0,0 +1,57 @@
+[Disjoint]
+ Title = Disjoint 
+ Abstract = This servuce shall return a true value if and only if the geometries g1 and g2 have no point in common.
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Disjoint result
+   Abstract = true if disjoint.
+   <MetaData>
+    title = Mon test  
+   </MetaData>   
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Equals.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Equals.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Equals.zcfg	(revision 491)
@@ -0,0 +1,57 @@
+[Equals]
+ Title = Equals 
+ Abstract = This service shall return a true value if and only if the geometries g1 and g2 are equal
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Equals result
+   Abstract = Should be true if two geometries are equivalent..
+   <MetaData>
+    title = Mon test  
+   </MetaData>   
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg	(revision 491)
@@ -1,5 +1,5 @@
 [Intersection]
  Title = Compute intersection. 
- Abstract = Generates a new geometry which is the region of intersection of the two geometries operated on.
+ Abstract = This function SHALL return a bag of geometry values representing the Point set intersection of geometry InputEntity1 and geometry InputEntity2.
  Profile = urn:ogc:wps:1.0.0:union
  processVersion = 2
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Intersects.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Intersects.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Intersects.zcfg	(revision 491)
@@ -0,0 +1,57 @@
+[Intersects]
+ Title = Intersects test
+ Abstract = This service shall return a true value if and only if the geometries g1 and g2 have at least one boundary point in common, but no interior points.
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Contains result
+   Abstract = A value true or false if the geometry1 contains the geometry2.
+   <MetaData>
+    title = Mon test  
+   </MetaData>   
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/IsSimple.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/IsSimple.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/IsSimple.zcfg	(revision 491)
@@ -0,0 +1,37 @@
+[IsSimple]
+ Title = IsSimple test 
+ Abstract = This service shall return a true value if and only if geometry g has no anomalous geometric points, such as self intersection or self tangency. Simple curves intersect themselves only at their endpoints (only if they are also closed, see next function).
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputPolygon]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = IsSimple result
+   Abstract = The boolean result
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/IsValid.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/IsValid.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/IsValid.zcfg	(revision 491)
@@ -0,0 +1,37 @@
+[IsValid]
+ Title = IsValid test 
+ Abstract = This service shall return a TRUE value if and only if the geometry g is valid
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputPolygon]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Equals result
+   Abstract = Should be true if two geometries are equivalent..
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg	(revision 491)
@@ -1,5 +1,5 @@
 [SymDifference]
  Title = Compute symmetric difference. 
- Abstract = Generates a new geometry which is the symmetric difference of this geometry and the other geometry.
+ Abstract = This service shall return a feature collection representing the closure of the symmetric difference of two Geometries. The symmetric difference is the set of points which lie on either InputEntity1 or InputEntity2 but not in both.
  Profile = urn:ogc:wps:1.0.0:symmetricdifference
  processVersion = 2
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Touches.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Touches.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Touches.zcfg	(revision 491)
@@ -0,0 +1,57 @@
+[Touches]
+ Title = Compute intersection. 
+ Abstract = Generates a new geometry which is the region of intersection of the two geometries operated on.
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Intersects result
+   Abstract = A value true or false if the geometry1 and geometry2 touches.
+   <MetaData>
+    title = Mon test  
+   </MetaData>   
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg	(revision 491)
@@ -1,6 +1,6 @@
 [Union]
  Title = Compute union. 
- Abstract = Generates a new geometry which is the region of union of the two geometries operated on.
- Profile = urn:ogc:wps:1.0.0:union
+ Abstract = This service shall return a bag of geometry values representing a Point set union of geometry InputEntity1 with geometry InputEntity2.
+ profile = urn:ogc:wps:1.0.0:union
  processVersion = 2
  storeSupported = true
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Within.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Within.zcfg	(revision 491)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Within.zcfg	(revision 491)
@@ -0,0 +1,57 @@
+[Within]
+ Title = Within test
+ Abstract = This service shall return a true value if and only if the geometry InputEntity1 is spatially within geometry InputEntity2; that is if every point on InputEntity1 is also on InputEntity2.
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_service.zo
+ serviceType = C
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Within result
+   Abstract = A value true or false if the geometry1 contains the geometry2.
+   <MetaData>
+    title = Mon test  
+   </MetaData>   
+    <LiteralData>
+      dataType=boolean
+      <Default />
+    </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/service.c
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/service.c	(revision 374)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/service.c	(revision 491)
@@ -26,4 +26,9 @@
 #include "ogr_api.h"
 #include "ogr_geometry.h"
+
+#include "cpl_minixml.h"
+#include "ogr_api.h"
+#include "ogrsf_frmts.h"
+
 #include "geos_c.h"
 #include "service.h"
@@ -44,5 +49,4 @@
   void printExceptionReportResponse(maps*,map*);
   char *base64(const char *input, int length);
-  int errorException(maps *m, const char *message, const char *errorcode);
 
   OGRGeometryH createGeometryFromGML(maps* conf,char* inputStr){
@@ -53,5 +57,5 @@
     xmlXPathContextPtr xpathCtx;
     xmlXPathObjectPtr xpathObj;
-    char * xpathExpr="/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']";
+    const char * xpathExpr="/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']";
     xpathCtx = xmlXPathNewContext(doc);
     xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr,xpathCtx);
@@ -179,13 +183,12 @@
 
 
-  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH),char* schema){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n");
-#endif
+  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometry* (OGRGeometry::*myFunc)() const,const char* schema){
+    OGRRegisterAll();
+
     maps* cursor=inputs;
     OGRGeometryH geometry,res;
-#ifdef DEBUG
-    dumpMaps(cursor);
-#endif
+    OGRLayer *poDstLayer;
+    const char *oDriver1;
+    OGRDataSource       *poODS;
     map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
     if(!tmp){
@@ -193,323 +196,1030 @@
       return SERVICE_FAILED;
     }
-#ifdef DEBUG
-    fprintf(stderr,"Service internal print \n");
-    dumpMaps(inputs);
-    fprintf(stderr,"/Service internal print \n");
-#endif
+    char filename[1024];
     map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
-#ifdef DEBUG
-    fprintf(stderr,"Service internal print \n");
-    dumpMap(tmp1);
-    fprintf(stderr,"/Service internal print \n");
-#endif
+    const char *oDriver;
+    oDriver="GeoJSON";
+    sprintf(filename,"/vsimem/input_%d.json",getpid());
     if(tmp1!=NULL){
-      if(strncmp(tmp1->value,"text/js",7)==0 ||
-	 strncmp(tmp1->value,"application/json",7)==0)
-        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-      else
-        geometry=createGeometryFromGML(conf,tmp->value);
+      if(strcmp(tmp1->value,"text/xml")==0){
+	sprintf(filename,"/vsimem/input_%d.xml",getpid());
+	oDriver="GML";
+      }
+    }
+    VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE);
+    VSIFCloseL(ifile);
+    OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
+    char pszDestDataSource[100];
+    if( ipoDS == NULL )
+      {
+	OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
+	
+	fprintf( stderr, "FAILURE:\n"
+		 "Unable to open datasource `%s' with the following drivers.\n",
+		 filename );
+	
+	for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+	  {
+	    fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
+	  }
+	char tmp[1024];
+	sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
+	setMapInMaps(conf,"lenv","message",tmp);
+	return SERVICE_FAILED;
+      }
+    for( int iLayer = 0; iLayer < ipoDS->GetLayerCount();
+	 iLayer++ )
+      {
+	OGRLayer        *poLayer = ipoDS->GetLayer(iLayer);
+	
+	if( poLayer == NULL )
+	  {
+	    fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
+		     iLayer );
+	    char tmp[1024];
+	    sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
+	    setMapInMaps(conf,"lenv","message",tmp);
+	    return SERVICE_FAILED;
+	  }
+	
+	OGRFeature  *poFeature;
+
+	/* -------------------------------------------------------------------- */
+	/*      Try opening the output datasource as an existing, writable      */
+	/* -------------------------------------------------------------------- */
+	
+	OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar();
+	OGRSFDriver          *poDriver = NULL;
+	int                  iDriver;
+	
+	map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
+	oDriver1="GeoJSON";
+	sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid());
+	if(tmpMap!=NULL){
+	  if(strcmp(tmpMap->value,"text/xml")==0){
+	    sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid());
+	    oDriver1="GML";
+	  }
+	}
+	
+	for( iDriver = 0;
+	     iDriver < poR->GetDriverCount() && poDriver == NULL;
+	     iDriver++ )
+	  {
+	    if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver1) )
+	      {
+		poDriver = poR->GetDriver(iDriver);
+	      }
+	  }
+	
+	if( poDriver == NULL )
+	  {
+	    char emessage[8192];
+	    sprintf( emessage, "Unable to find driver `%s'.\n", oDriver );
+	    sprintf( emessage,  "%sThe following drivers are available:\n",emessage );
+	    
+	    for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+	      {
+		sprintf( emessage,  "%s  -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() );
+	      }
+	    
+	    setMapInMaps(conf,"lenv","message",emessage);
+	    return SERVICE_FAILED;
+	    
+	  }
+	
+	if( !poDriver->TestCapability( ODrCCreateDataSource ) ){
+	  char emessage[1024];
+	  sprintf( emessage,  "%s driver does not support data source creation.\n",
+		   "json" );
+	  setMapInMaps(conf,"lenv","message",emessage);
+	  return SERVICE_FAILED;
+	}
+	
+	/* -------------------------------------------------------------------- */
+	/*      Create the output data source.                                  */
+	/* -------------------------------------------------------------------- */
+	//map* tpath=getMapFromMaps(conf,"main","tmpPath");
+	char **papszDSCO=NULL;
+	poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
+	if( poODS == NULL ){
+	  char emessage[1024];      
+	  sprintf( emessage,  "%s driver failed to create %s\n", 
+		   "json", pszDestDataSource );
+	  setMapInMaps(conf,"lenv","message",emessage);
+	  return SERVICE_FAILED;
+	}
+	
+	/* -------------------------------------------------------------------- */
+	/*      Create the layer.                                               */
+	/* -------------------------------------------------------------------- */
+	if( !poODS->TestCapability( ODsCCreateLayer ) )
+	  {
+	    char emessage[1024];
+	    sprintf( emessage, 
+		     "Layer %s not found, and CreateLayer not supported by driver.", 
+		     "Result" );
+	    setMapInMaps(conf,"lenv","message",emessage);
+	    return SERVICE_FAILED;
+	  }
+	
+	//CPLErrorReset();
+	
+	poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL);
+	if( poDstLayer == NULL ){
+	  setMapInMaps(conf,"lenv","message","Layer creation failed.\n");
+	  return SERVICE_FAILED;
+	}
+	
+	OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+	int iField;
+	int hasMmField=0;
+	
+	for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
+	  {
+	    OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField);
+            if (iField >= 0)
+                poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) );
+            else
+            {
+                fprintf( stderr, "Field '%s' not found in source layer.\n", 
+                        iField );
+		return SERVICE_FAILED;
+            }
+	  }
+
+	while(TRUE){
+	  OGRFeature      *poDstFeature = NULL;
+	  poFeature = poLayer->GetNextFeature();
+	  if( poFeature == NULL )
+	    break;
+	  if(poFeature->GetGeometryRef() != NULL){
+	    // DO SOMETHING HERE !!
+	    poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() );
+	    if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE )
+	      {
+		char tmpMsg[1024];
+		sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
+			 poFeature->GetFID(), poFDefn->GetName() );
+		
+		OGRFeature::DestroyFeature( poFeature );
+		OGRFeature::DestroyFeature( poDstFeature );
+		return SERVICE_FAILED;
+	      }
+	    if(poDstFeature->SetGeometryDirectly((poDstFeature->GetGeometryRef()->*myFunc)()) != OGRERR_NONE )
+	      {
+		char tmpMsg[1024];
+		sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
+			 poFeature->GetFID(), poFDefn->GetName() );
+		
+		OGRFeature::DestroyFeature( poFeature );
+		OGRFeature::DestroyFeature( poDstFeature );
+		return SERVICE_FAILED;
+	      }
+	    OGRFeature::DestroyFeature( poFeature );
+	    if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE )
+	      {		
+		OGRFeature::DestroyFeature( poDstFeature );
+		return SERVICE_FAILED;
+	      }
+	    OGRFeature::DestroyFeature( poDstFeature );
+	  }
+	}
+
+      }
+
+    delete poODS;
+    delete ipoDS;
+
+    char *res1=readVSIFile(conf,pszDestDataSource);
+    if(res1==NULL)
+      return SERVICE_FAILED;
+    setMapInMaps(outputs,"Result","value",res1);
+    free(res1);
+
+    OGRCleanupAll();
+    return SERVICE_SUCCEEDED;
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
+    OGRRegisterAll();
+
+    double bufferDistance;
+    map* tmp0=getMapFromMaps(inputs,"BufferDistance","value");
+    if(tmp0==NULL){
+      bufferDistance=atof("10.0");
     }
     else
-      geometry=createGeometryFromGML(conf,tmp->value);
-    if(geometry==NULL){
+      bufferDistance=atof(tmp0->value);
+
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+    OGRLayer *poDstLayer;
+    const char *oDriver1;
+    OGRDataSource       *poODS;
+    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+    if(!tmp){
       setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
       return SERVICE_FAILED;
     }
-    res=(*myFunc)(geometry);
+    char filename[1024];
+    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
+    const char *oDriver;
+    oDriver="GeoJSON";
+    sprintf(filename,"/vsimem/input_%d.json",getpid());
+    if(tmp1!=NULL){
+      if(strcmp(tmp1->value,"text/xml")==0){
+	sprintf(filename,"/vsimem/input_%d.xml",getpid());
+	oDriver="GML";
+      }
+    }
+    VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE);
+    VSIFCloseL(ifile);
+    OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
+    char pszDestDataSource[100];
+    if( ipoDS == NULL )
+      {
+	OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
+	
+	fprintf( stderr, "FAILURE:\n"
+		 "Unable to open datasource `%s' with the following drivers.\n",
+		 filename );
+	
+	for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+	  {
+	    fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
+	  }
+	char tmp[1024];
+	sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
+	setMapInMaps(conf,"lenv","message",tmp);
+	return SERVICE_FAILED;
+      }
+    for( int iLayer = 0; iLayer < ipoDS->GetLayerCount();
+	 iLayer++ )
+      {
+	OGRLayer        *poLayer = ipoDS->GetLayer(iLayer);
+	
+	if( poLayer == NULL )
+	  {
+	    fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
+		     iLayer );
+	    char tmp[1024];
+	    sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
+	    setMapInMaps(conf,"lenv","message",tmp);
+	    return SERVICE_FAILED;
+	  }
+	
+	OGRFeature  *poFeature;
+
+	/* -------------------------------------------------------------------- */
+	/*      Try opening the output datasource as an existing, writable      */
+	/* -------------------------------------------------------------------- */
+	
+	OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar();
+	OGRSFDriver          *poDriver = NULL;
+	int                  iDriver;
+	
+	map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
+	oDriver1="GeoJSON";
+	sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid());
+	if(tmpMap!=NULL){
+	  if(strcmp(tmpMap->value,"text/xml")==0){
+	    sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid());
+	    oDriver1="GML";
+	  }
+	}
+	
+	for( iDriver = 0;
+	     iDriver < poR->GetDriverCount() && poDriver == NULL;
+	     iDriver++ )
+	  {
+	    if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver1) )
+	      {
+		poDriver = poR->GetDriver(iDriver);
+	      }
+	  }
+	
+	if( poDriver == NULL )
+	  {
+	    char emessage[8192];
+	    sprintf( emessage, "Unable to find driver `%s'.\n", oDriver );
+	    sprintf( emessage,  "%sThe following drivers are available:\n",emessage );
+	    
+	    for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+	      {
+		sprintf( emessage,  "%s  -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() );
+	      }
+	    
+	    setMapInMaps(conf,"lenv","message",emessage);
+	    return SERVICE_FAILED;
+	    
+	  }
+	
+	if( !poDriver->TestCapability( ODrCCreateDataSource ) ){
+	  char emessage[1024];
+	  sprintf( emessage,  "%s driver does not support data source creation.\n",
+		   "json" );
+	  setMapInMaps(conf,"lenv","message",emessage);
+	  return SERVICE_FAILED;
+	}
+	
+	/* -------------------------------------------------------------------- */
+	/*      Create the output data source.                                  */
+	/* -------------------------------------------------------------------- */
+	//map* tpath=getMapFromMaps(conf,"main","tmpPath");
+	char **papszDSCO=NULL;
+	poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
+	if( poODS == NULL ){
+	  char emessage[1024];      
+	  sprintf( emessage,  "%s driver failed to create %s\n", 
+		   "json", pszDestDataSource );
+	  setMapInMaps(conf,"lenv","message",emessage);
+	  return SERVICE_FAILED;
+	}
+	
+	/* -------------------------------------------------------------------- */
+	/*      Create the layer.                                               */
+	/* -------------------------------------------------------------------- */
+	if( !poODS->TestCapability( ODsCCreateLayer ) )
+	  {
+	    char emessage[1024];
+	    sprintf( emessage, 
+		     "Layer %s not found, and CreateLayer not supported by driver.", 
+		     "Result" );
+	    setMapInMaps(conf,"lenv","message",emessage);
+	    return SERVICE_FAILED;
+	  }
+	
+	//CPLErrorReset();
+	
+	poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL);
+	if( poDstLayer == NULL ){
+	  setMapInMaps(conf,"lenv","message","Layer creation failed.\n");
+	  return SERVICE_FAILED;
+	}
+	
+	OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+	int iField;
+	int hasMmField=0;
+	
+	for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
+	  {
+	    OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField);
+            if (iField >= 0)
+                poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) );
+            else
+            {
+                fprintf( stderr, "Field '%s' not found in source layer.\n", 
+                        iField );
+		return SERVICE_FAILED;
+            }
+	  }
+
+	while(TRUE){
+	  OGRFeature      *poDstFeature = NULL;
+	  poFeature = poLayer->GetNextFeature();
+	  if( poFeature == NULL )
+	    break;
+	  if(poFeature->GetGeometryRef() != NULL){
+	    // DO SOMETHING HERE !!
+	    poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() );
+	    if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE )
+	      {
+		char tmpMsg[1024];
+		sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
+			 poFeature->GetFID(), poFDefn->GetName() );
+		
+		OGRFeature::DestroyFeature( poFeature );
+		OGRFeature::DestroyFeature( poDstFeature );
+		return SERVICE_FAILED;
+	      }
+	    if(poDstFeature->SetGeometryDirectly(poDstFeature->GetGeometryRef()->Buffer(bufferDistance,30)) != OGRERR_NONE )
+	      {
+		char tmpMsg[1024];
+		sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
+			 poFeature->GetFID(), poFDefn->GetName() );
+		
+		OGRFeature::DestroyFeature( poFeature );
+		OGRFeature::DestroyFeature( poDstFeature );
+		return SERVICE_FAILED;
+	      }
+	    OGRFeature::DestroyFeature( poFeature );
+	    if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE )
+	      {		
+		OGRFeature::DestroyFeature( poDstFeature );
+		return SERVICE_FAILED;
+	      }
+	    OGRFeature::DestroyFeature( poDstFeature );
+	  }
+	}
+
+      }
+
+    delete poODS;
+    delete ipoDS;
+
+    char *res1=readVSIFile(conf,pszDestDataSource);
+    if(res1==NULL)
+      return SERVICE_FAILED;
+    setMapInMaps(outputs,"Result","value",res1);
+    free(res1);
+
+    OGRCleanupAll();
+    return SERVICE_SUCCEEDED;
+
+}
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOne(conf,inputs,outputs,&OGRGeometry::Boundary,"http://fooa/gml/3.1.0/polygon.xsd");
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOne(conf,inputs,outputs,&OGRGeometry::ConvexHull,"http://fooa/gml/3.1.0/polygon.xsd");
+  }
+
+
+  OGRDataSource* loadEntity(maps* conf,maps* inputs,char **filename,const char **oDriver,const char *entity,int iter){
+    map* tmp=getMapFromMaps(inputs,entity,"value");
+    map* tmp1=getMapFromMaps(inputs,entity,"mimeType");
+    *oDriver="GeoJSON";
+    sprintf(*filename,"/vsimem/input_%d.json",getpid()+iter);
+    if(tmp1!=NULL){
+      if(strcmp(tmp1->value,"text/xml")==0){
+	sprintf(*filename,"/vsimem/input_%d.xml",getpid()+iter);
+	*oDriver="GML";
+      }
+    }
+    VSILFILE *ifile=VSIFileFromMemBuffer(*filename,(GByte*)tmp->value,strlen(tmp->value),FALSE);
+    VSIFCloseL(ifile);
+    return OGRSFDriverRegistrar::Open(*filename,FALSE);    
+  }
+
+  int applyOneBool(maps*& conf,maps*& inputs,maps*& outputs,OGRBoolean (OGRGeometry::*myFunc)() const){
 #ifdef DEBUG
-    fprintf(stderr,"Service internal print \n");
-    dumpMaps(outputs);
-    fprintf(stderr,"/Service internal print \n");
-#endif
-    map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
+    fprintf(stderr,"\nService internal print\n");
+#endif
+    OGRRegisterAll();
+
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+    OGRLayer *poDstLayer;
+    const char *oDriver1;
+    OGRDataSource       *poODS;
 #ifdef DEBUG
-    fprintf(stderr,"Service internal print \n");
-    dumpMap(tmp_2);
-    fprintf(stderr,"/Service internal print \n");
-#endif
-    if(tmp_2!=NULL){
-      if(strncmp(tmp_2->value,"text/js",7)==0 ||
-	 strncmp(tmp_2->value,"application/json",16)==0){
-	char *tmpS=OGR_G_ExportToJson(res);
-	setMapInMaps(outputs,"Result","value",tmpS);
-#ifndef WIN32
-	setMapInMaps(outputs,"Result","mimeType","text/plain");
-	setMapInMaps(outputs,"Result","encoding","UTF-8");
-	free(tmpS);
-#endif
-      }
-      else{
-	char *tmpS=OGR_G_ExportToGML(res);
-	setMapInMaps(outputs,"Result","value",tmpS);
-#ifndef WIN32
-	setMapInMaps(outputs,"Result","mimeType","text/xml");
-	setMapInMaps(outputs,"Result","encoding","UTF-8");
-	setMapInMaps(outputs,"Result","schema",schema);
-	free(tmpS);
-#endif
-      }
-    }else{
-      char *tmpS=OGR_G_ExportToJson(res);
-      setMapInMaps(outputs,"Result","value",tmpS);
-#ifndef WIN32
-      setMapInMaps(outputs,"Result","mimeType","text/plain");
-      setMapInMaps(outputs,"Result","encoding","UTF-8");
-      free(tmpS);
-#endif
-    }
-    //outputs->next=NULL;
+    dumpMaps(cursor);
+#endif
+    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+    if(!tmp){
+      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
+      return SERVICE_FAILED;
+    }
+    char filename[1024];
+    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
+    const char *oDriver;
+    oDriver="GeoJSON";
+    sprintf(filename,"/vsimem/input_%d.json",getpid());
+    if(tmp1!=NULL){
+      if(strcmp(tmp1->value,"text/xml")==0){
+	sprintf(filename,"/vsimem/input_%d.xml",getpid());
+	oDriver="GML";
+      }
+    }
+    VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE);
+    VSIFCloseL(ifile);
+    OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
+    char pszDestDataSource[100];
+    if( ipoDS == NULL )
+      {
+	OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
+	
+	fprintf( stderr, "FAILURE:\n"
+		 "Unable to open datasource `%s' with the following drivers.\n",
+		 filename );
+	
+	for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+	  {
+	    fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
+	  }
+	char tmp[1024];
+	sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
+	setMapInMaps(conf,"lenv","message",tmp);
+	return SERVICE_FAILED;
+      }
+    for( int iLayer = 0; iLayer < ipoDS->GetLayerCount();
+	 iLayer++ )
+      {
+	OGRLayer        *poLayer = ipoDS->GetLayer(iLayer);
+	
+	if( poLayer == NULL )
+	  {
+	    fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
+		     iLayer );
+	    char tmp[1024];
+	    sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
+	    setMapInMaps(conf,"lenv","message",tmp);
+	    return SERVICE_FAILED;
+	  }
+	
+	OGRFeature  *poFeature;
+
+
+	while(TRUE){
+	  OGRFeature      *poDstFeature = NULL;
+	  poFeature = poLayer->GetNextFeature();
+	  if( poFeature == NULL )
+	    break;
+	  if(poFeature->GetGeometryRef() != NULL){
+	    // DO SOMETHING HERE !!
+	    if((poFeature->GetGeometryRef()->*myFunc)()==0){
+	      setMapInMaps(outputs,"Result","value","false");
+	      OGRFeature::DestroyFeature( poFeature );
+	      delete ipoDS;
+	      return SERVICE_SUCCEEDED;
+	    }
+	  }
+	  OGRFeature::DestroyFeature( poFeature );
+	}
+
+      }
+
+    delete ipoDS;
+    setMapInMaps(outputs,"Result","value","true");
+
+    OGRCleanupAll();
+    return SERVICE_SUCCEEDED;
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int IsSimple(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsSimple);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int IsClosed(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsRing);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int IsValid(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsValid);
+  }
+
+  
+  int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometry* (OGRGeometry::*myFunc)(const OGRGeometry*) const){
 #ifdef DEBUG
-    dumpMaps(outputs);
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    OGR_G_DestroyGeometry(res);
-    OGR_G_DestroyGeometry(geometry);
-    //CPLFree(res);
-    //CPLFree(geometry);
+    fprintf(stderr,"\nService internal print\n");
+#endif
+    OGRRegisterAll();
+
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+    OGRLayer *poDstLayer;
+    //const char *oDriver1;
+    OGRDataSource       *poODS;
 #ifdef DEBUG
-    fprintf(stderr,"Service internal print \n");
-    dumpMaps(outputs);
-    fprintf(stderr,"/Service internal print \n");
-#endif
+    dumpMaps(cursor);
+#endif
+
+    char *filename=(char*)malloc(1024*sizeof(char));
+    const char *oDriver1;
+    OGRDataSource* ipoDS1 = loadEntity(conf,inputs,&filename,&oDriver1,"InputEntity1",1);
+
+    char *filename1=(char*)malloc(1024*sizeof(char));
+    const char *oDriver2;
+    OGRDataSource* ipoDS2 = loadEntity(conf,inputs,&filename1,&oDriver2,"InputEntity2",2);
+    const char *oDriver3;
+    char pszDestDataSource[100];
+    if( ipoDS1 == NULL || ipoDS2 == NULL )
+      {
+	OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
+	
+	fprintf( stderr, "FAILURE:\n"
+		 "Unable to open datasource `%s' with the following drivers.\n",
+		 filename );
+	
+	for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+	  {
+	    fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
+	  }
+	char tmp[1024];
+	if( ipoDS1 == NULL )
+	  sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
+	if( ipoDS2 == NULL )
+	  sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename1);
+	setMapInMaps(conf,"lenv","message",tmp);
+	return SERVICE_FAILED;
+      }
+    for( int iLayer = 0; iLayer < ipoDS1->GetLayerCount();
+	 iLayer++ )
+      {
+	OGRLayer        *poLayer1 = ipoDS1->GetLayer(iLayer);
+	
+	if( poLayer1 == NULL )
+	  {
+	    fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
+		     iLayer );
+	    char tmp[1024];
+	    sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
+	    setMapInMaps(conf,"lenv","message",tmp);
+	    return SERVICE_FAILED;
+	  }
+
+	for( int iLayer1 = 0; iLayer1 < ipoDS2->GetLayerCount();
+	     iLayer1++ )
+	  {
+	    OGRLayer        *poLayer2 = ipoDS2->GetLayer(iLayer1);
+	    
+	    if( poLayer1 == NULL )
+	      {
+		fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
+			 iLayer1 );
+		char tmp[1024];
+		sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer1);
+		setMapInMaps(conf,"lenv","message",tmp);
+		return SERVICE_FAILED;
+	      }
+	
+	    OGRFeature  *poFeature1,*poFeature2;
+
+	    /* -------------------------------------------------------------------- */
+	    /*      Try opening the output datasource as an existing, writable      */
+	    /* -------------------------------------------------------------------- */
+	    
+	    OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar();
+	    OGRSFDriver          *poDriver = NULL;
+	    int                  iDriver;
+	    
+	    map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
+	    oDriver3="GeoJSON";
+	    sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid());
+	    if(tmpMap!=NULL){
+	      if(strcmp(tmpMap->value,"text/xml")==0){
+		sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid());
+		oDriver3="GML";
+	      }
+	    }
+	    
+	    for( iDriver = 0;
+		 iDriver < poR->GetDriverCount() && poDriver == NULL;
+		 iDriver++ )
+	      {
+#ifdef DEBUG
+		fprintf(stderr,"D:%s\n",poR->GetDriver(iDriver)->GetName());
+#endif
+		if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver3) )
+		  {
+		    poDriver = poR->GetDriver(iDriver);
+		  }
+	      }
+	    
+	    if( poDriver == NULL )
+	      {
+		char emessage[8192];
+		sprintf( emessage, "Unable to find driver `%s'.\n", oDriver1 );
+		sprintf( emessage,  "%sThe following drivers are available:\n",emessage );
+		
+		for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+		  {
+		    sprintf( emessage,  "%s  -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() );
+		  }
+		
+		setMapInMaps(conf,"lenv","message",emessage);
+		return SERVICE_FAILED;
+		
+	      }
+	    
+	    if( !poDriver->TestCapability( ODrCCreateDataSource ) ){
+	      char emessage[1024];
+	      sprintf( emessage,  "%s driver does not support data source creation.\n",
+		       "json" );
+	      setMapInMaps(conf,"lenv","message",emessage);
+	      return SERVICE_FAILED;
+	    }
+	    
+	    /* -------------------------------------------------------------------- */
+	    /*      Create the output data source.                                  */
+	    /* -------------------------------------------------------------------- */
+	    //map* tpath=getMapFromMaps(conf,"main","tmpPath");
+	    char **papszDSCO=NULL;
+	    poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
+	    if( poODS == NULL ){
+	      char emessage[1024];      
+	      sprintf( emessage,  "%s driver failed to create %s\n", 
+		       "json", pszDestDataSource );
+	      setMapInMaps(conf,"lenv","message",emessage);
+	      return SERVICE_FAILED;
+	    }
+	    
+	    /* -------------------------------------------------------------------- */
+	    /*      Create the layer.                                               */
+	    /* -------------------------------------------------------------------- */
+	    if( !poODS->TestCapability( ODsCCreateLayer ) )
+	      {
+		char emessage[1024];
+		sprintf( emessage, 
+			 "Layer %s not found, and CreateLayer not supported by driver.", 
+			 "Result" );
+		setMapInMaps(conf,"lenv","message",emessage);
+		return SERVICE_FAILED;
+	      }
+	    
+	    //CPLErrorReset();
+	    
+	    poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL);
+	    if( poDstLayer == NULL ){
+	      setMapInMaps(conf,"lenv","message","Layer creation failed.\n");
+	      return SERVICE_FAILED;
+	    }
+	    
+	    OGRFeatureDefn *poFDefn = poLayer1->GetLayerDefn();
+	    int iField;
+	    int hasMmField=0;
+	    
+	    for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
+	      {
+		OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField);
+		if (iField >= 0)
+		  poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) );
+		else
+		  {
+		    fprintf( stderr, "Field '%s' not found in source layer.\n", 
+			     iField );
+		    return SERVICE_FAILED;
+		  }
+	      }
+	    
+	    while(TRUE){
+	      OGRFeature      *poDstFeature = NULL;
+	      poFeature1 = poLayer1->GetNextFeature();
+	      if( poFeature1 == NULL )
+		break;
+	      while(TRUE){
+		poFeature2 = poLayer2->GetNextFeature();
+		if( poFeature2 == NULL )
+		  break;
+
+		if(poFeature1->GetGeometryRef() != NULL && poFeature2->GetGeometryRef() != NULL){
+		  // DO SOMETHING HERE !!
+		  poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() );
+		  if( poDstFeature->SetFrom( poFeature2, TRUE ) != OGRERR_NONE )
+		    {
+		      char tmpMsg[1024];
+		      sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
+			       poFeature2->GetFID(), poFDefn->GetName() );
+		      
+		      OGRFeature::DestroyFeature( poFeature1 );
+		      OGRFeature::DestroyFeature( poFeature2 );
+		      OGRFeature::DestroyFeature( poDstFeature );
+		      return SERVICE_FAILED;
+		    }
+		  if(poDstFeature->SetGeometryDirectly((poFeature1->GetGeometryRef()->*myFunc)(poFeature2->GetGeometryRef())) != OGRERR_NONE )
+		    {
+		      char tmpMsg[1024];
+		      sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
+			       poFeature2->GetFID(), poFDefn->GetName() );
+		      
+		      OGRFeature::DestroyFeature( poFeature1 );
+		      OGRFeature::DestroyFeature( poFeature2 );
+		      OGRFeature::DestroyFeature( poDstFeature );
+		      return SERVICE_FAILED;
+		    }
+		  OGRFeature::DestroyFeature( poFeature1 );
+		  OGRFeature::DestroyFeature( poFeature2 );
+		  if(!poDstFeature->GetGeometryRef()->IsEmpty())
+		    if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE )
+		      {		
+			OGRFeature::DestroyFeature( poDstFeature );
+			return SERVICE_FAILED;
+		      }
+		  OGRFeature::DestroyFeature( poDstFeature );
+		}
+	      }
+	    }
+	  }
+      }
+
+    delete poODS;
+    delete ipoDS1;
+    delete ipoDS2;
+    free(filename);
+    free(filename1);
+
+    char *res1=readVSIFile(conf,pszDestDataSource);
+    if(res1==NULL)
+      return SERVICE_FAILED;
+    setMapInMaps(outputs,"Result","value",res1);
+    free(res1);
+    OGRCleanupAll();
     return SERVICE_SUCCEEDED;
   }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
-   OGRGeometryH geometry,res;
-   map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-   if(tmp==NULL){
-     setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
-     return SERVICE_FAILED;
-   }else
-     if(strlen(tmp->value)<=0){
-       setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
-       return SERVICE_FAILED;
-     }
-   map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
-   if(strncmp(tmp1->value,"application/json",16)==0)
-     geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-   else
-     geometry=createGeometryFromGML(conf,tmp->value);
-   if(geometry==NULL){
-     setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry"));
-     return SERVICE_FAILED;
-   }
-   double bufferDistance;
-   tmp=getMapFromMaps(inputs,"BufferDistance","value");
-   if(tmp==NULL){
-     bufferDistance=atof("10.0");
-   }
-   else
-     bufferDistance=atof(tmp->value);
-   res=OGR_G_Buffer(geometry,bufferDistance,30);
-   dumpMap(tmp);
-   tmp1=getMapFromMaps(outputs,"Result","mimeType");
-   dumpMap(tmp);
-   if(strncmp(tmp1->value,"application/json",16)==0){
-     char *tmpS=OGR_G_ExportToJson(res);
-     setMapInMaps(outputs,"Result","value",tmpS);
-     dumpMap(tmp);
-#ifndef WIN32
-     setMapInMaps(outputs,"Result","mimeType","text/plain");
-     setMapInMaps(outputs,"Result","encoding","UTF-8");
-     free(tmpS);
-#endif
-   }
-   else{
-     char *tmpS=OGR_G_ExportToGML(res);
-     setMapInMaps(outputs,"Result","value",tmpS);
-     dumpMap(tmp);
-#ifndef WIN32
-     free(tmpS);
-     setMapInMaps(outputs,"Result","mimeType","text/xml");
-     setMapInMaps(outputs,"Result","encoding","UTF-8");
-     setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
-#endif
-   }
-   //outputs->next=NULL;
-   OGR_G_DestroyGeometry(geometry);
-   OGR_G_DestroyGeometry(res);
-   return SERVICE_SUCCEEDED;
-}
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary,"http://fooa/gml/3.1.0/polygon.xsd");
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull,"http://fooa/gml/3.1.0/polygon.xsd");
-  }
-
-
-  OGRGeometryH MY_OGR_G_Centroid(OGRGeometryH hTarget){
-    OGRGeometryH res;
-    res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
-    OGRwkbGeometryType gtype=OGR_G_GetGeometryType(hTarget);
-    if(gtype!=wkbPolygon){
-      hTarget=OGR_G_ConvexHull(hTarget);
-    }
-    int c=OGR_G_Centroid(hTarget,res);
-    return res;
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid,"http://fooa/gml/3.1.0/point.xsd");
-  }
-
-  int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH,OGRGeometryH)){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print1\n");
-    fflush(stderr);
-    fprintf(stderr,"\nService internal print1\n");
-    dumpMaps(inputs);
-    fprintf(stderr,"\nService internal print1\n");
-#endif
+  
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Difference(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwo(conf,inputs,outputs,&OGRGeometry::Difference);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int SymDifference(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwo(conf,inputs,outputs,&OGRGeometry::SymDifference);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Intersection(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwo(conf,inputs,outputs,&OGRGeometry::Intersection);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Union(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwo(conf,inputs,outputs,&OGRGeometry::Union);
+  }
+
+  int applyTwoBool(maps*& conf,maps*& inputs,maps*& outputs,OGRBoolean (OGRGeometry::*myFunc)(const OGRGeometry*) const){
+    OGRRegisterAll();
 
     maps* cursor=inputs;
-    OGRGeometryH geometry1,geometry2;
-    OGRGeometryH res;
-    {
-      map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
-      map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType");
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0)
-      	  geometry1=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry1=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry1=createGeometryFromGML(conf,tmp->value);
-    }
-    if(geometry1==NULL){
-      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
-#ifdef DEBUG
-      fprintf(stderr,"SERVICE FAILED !\n");
-#endif
-      return SERVICE_FAILED;
-    }
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print1 InputEntity1\n");
-#endif
-    {
-      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
-      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
-#ifdef DEBUG
-      fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16));
-      //dumpMap(tmp);
-      fprintf(stderr,"MY MAP\n");
-      fprintf(stderr,"\nService internal print1 InputEntity2\n");
-#endif
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0){
-#ifdef DEBUG
-	  fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n");
-#endif
-      	  geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
-	}
-	else{
-#ifdef DEBUG
-	  fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n");
-#endif
-	  geometry2=createGeometryFromGML(conf,tmp->value);
-	}
-      }
-      else
-      	geometry2=createGeometryFromGML(conf,tmp->value);
-#ifdef DEBUG
-      fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n");
-#endif
-    }
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print1 InputEntity2 Final\n");
-#endif
-    if(geometry2==NULL){
-      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
-#ifdef DEBUG
-      fprintf(stderr,"SERVICE FAILED !\n");
-#endif
-      return SERVICE_FAILED;
-    }
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print1\n");
-#endif
-    res=(*myFunc)(geometry1,geometry2);
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print1\n");
-#endif    
-    /* nuova parte */
-    map* tmp2=getMapFromMaps(outputs,"Result","mimeType");
-    if(strncmp(tmp2->value,"application/json",16)==0){
-      char *tmpS=OGR_G_ExportToJson(res);
-      setMapInMaps(outputs,"Result","value",tmpS);
-#ifndef WIN32
-      setMapInMaps(outputs,"Result","mimeType","text/plain");
-      setMapInMaps(outputs,"Result","encoding","UTF-8");
-      free(tmpS);
-#endif
-    }
-    else{
-      char *tmpS=OGR_G_ExportToGML(res);
-      setMapInMaps(outputs,"Result","value",tmpS);
-#ifndef WIN32
-      setMapInMaps(outputs,"Result","mimeType","text/xml");
-      setMapInMaps(outputs,"Result","encoding","UTF-8");
-      setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
-      free(tmpS);
-#endif
-    }
-    
-    /* vecchia da togliere */
-    /*
-    char *tmpS=OGR_G_ExportToJson(res);
-    setMapInMaps(outputs,"Result","value",tmpS);
-    setMapInMaps(outputs,"Result","mimeType","text/plain");
-    setMapInMaps(outputs,"Result","encoding","UTF-8");
-    free(tmpS);
-    */
-    OGR_G_DestroyGeometry(geometry1);
-    OGR_G_DestroyGeometry(geometry2);
-    OGR_G_DestroyGeometry(res);
+    OGRGeometryH geometry,res;
+    OGRLayer *poDstLayer;
+    OGRDataSource       *poODS;
+
+    char *filename=(char*)malloc(1024*sizeof(char));
+    const char *oDriver1;
+    OGRDataSource* ipoDS1 = loadEntity(conf,inputs,&filename,&oDriver1,"InputEntity1",1);
+
+    char *filename1=(char*)malloc(1024*sizeof(char));
+    const char *oDriver2;
+    OGRDataSource* ipoDS2 = loadEntity(conf,inputs,&filename1,&oDriver2,"InputEntity2",2);
+    const char *oDriver3;
+    char pszDestDataSource[100];
+    if( ipoDS1 == NULL || ipoDS2 == NULL )
+      {
+	OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
+	
+	fprintf( stderr, "FAILURE:\n"
+		 "Unable to open datasource `%s' with the following drivers.\n",
+		 filename );
+	
+	for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+	  {
+	    fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
+	  }
+	char tmp[1024];
+	if( ipoDS1 == NULL )
+	  sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
+	if( ipoDS2 == NULL )
+	  sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename1);
+	setMapInMaps(conf,"lenv","message",tmp);
+	return SERVICE_FAILED;
+      }
+    for( int iLayer = 0; iLayer < ipoDS1->GetLayerCount();
+	 iLayer++ )
+      {
+	OGRLayer        *poLayer1 = ipoDS1->GetLayer(iLayer);
+	
+	if( poLayer1 == NULL )
+	  {
+	    fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
+		     iLayer );
+	    char tmp[1024];
+	    sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
+	    setMapInMaps(conf,"lenv","message",tmp);
+	    return SERVICE_FAILED;
+	  }
+
+	for( int iLayer1 = 0; iLayer1 < ipoDS2->GetLayerCount();
+	     iLayer1++ )
+	  {
+	    OGRLayer        *poLayer2 = ipoDS2->GetLayer(iLayer1);
+	    
+	    if( poLayer1 == NULL )
+	      {
+		fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
+			 iLayer1 );
+		char tmp[1024];
+		sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer1);
+		setMapInMaps(conf,"lenv","message",tmp);
+		return SERVICE_FAILED;
+	      }
+	
+	    OGRFeature  *poFeature1,*poFeature2;
+
+
+	    while(TRUE){
+	      OGRFeature      *poDstFeature = NULL;
+	      poFeature1 = poLayer1->GetNextFeature();
+	      if( poFeature1 == NULL )
+		break;
+	      while(TRUE){
+		poFeature2 = poLayer2->GetNextFeature();
+		if( poFeature2 == NULL )
+		  break;
+		if(poFeature1->GetGeometryRef() != NULL && poFeature2->GetGeometryRef() != NULL){
+		  // DO SOMETHING HERE !!
+		  if((poFeature1->GetGeometryRef()->*myFunc)(poFeature2->GetGeometryRef())==0){
+		    setMapInMaps(outputs,"Result","value","false");
+		    OGRFeature::DestroyFeature( poFeature1 );
+		    OGRFeature::DestroyFeature( poFeature2 );
+		    delete ipoDS1;
+		    delete ipoDS2;
+		    free(filename);
+		    free(filename1);
+		    return SERVICE_SUCCEEDED;
+		  }
+		}
+		OGRFeature::DestroyFeature( poFeature2 );
+	      }
+	      OGRFeature::DestroyFeature( poFeature1 );
+	    }
+	  }
+      }
+
+    delete ipoDS1;
+    delete ipoDS2;
+    free(filename);
+    free(filename1);
+
+    setMapInMaps(outputs,"Result","value","true");
+
+    OGRCleanupAll();
     return SERVICE_SUCCEEDED;
   }
-  
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Difference(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyTwo(conf,inputs,outputs,&OGR_G_Difference);
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int SymDifference(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyTwo(conf,inputs,outputs,&OGR_G_SymmetricDifference);
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Intersection(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyTwo(conf,inputs,outputs,&OGR_G_Intersection);
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Union(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyTwo(conf,inputs,outputs,&OGR_G_Union);
+
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Equals(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwoBool(conf,inputs,outputs,(OGRBoolean (OGRGeometry::*)(const OGRGeometry *) const)&OGRGeometry::Equals);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Disjoint(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Disjoint);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Touches(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Touches);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Crosses(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Crosses);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Within(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Within);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Contains(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Contains);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Overlaps(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Overlaps);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Intersects(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyTwoBool(conf,inputs,outputs,(OGRBoolean (OGRGeometry::*)(const OGRGeometry *) const)&OGRGeometry::Intersects);
   }
 
@@ -605,5 +1315,5 @@
     }
     fprintf(stderr,"geometry created %s \n",tmp->value);
-    res=OGR_G_GetArea(geometry);
+    res=OGR_G_Area(geometry);
     fprintf(stderr,"area %d \n",res);
     /**
