Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BoundaryPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BoundaryPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BoundaryPy.zcfg	(revision 9)
@@ -0,0 +1,57 @@
+[BoundaryPy]
+ Title = Compute boundary.
+ Abstract = A new geometry object is created and returned containing the boundary of the geometry on which the method is invoked. 
+ processVersion = 1
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputPolygon]
+   Title = Polygon to conpute boundary
+   Abstract = URI to a set of GML that describes the polygon.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = application/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The geometry created
+   Abstract = The geometry containing the boundary of the geometry on which the method is invoked.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     asReference = true	
+    </Supported>
+   </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BufferPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BufferPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BufferPy.zcfg	(revision 9)
@@ -0,0 +1,69 @@
+[BufferPy]
+ 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. 
+ Profile = urn:ogc:wps:1.0.0:buffer
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData lang="en">
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputPolygon]
+   Title = Polygon to be buffered
+   Abstract = URI to a set of GML that describes the polygon.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     asReference = true	
+    </Default>
+    <Supported>
+     mimeType = aplication/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+  [BufferDistance]
+   Title = Buffer Distance
+   Abstract = Distance to be used to calculate buffer.
+   minOccurs = 0
+   maxOccurs = 1
+   <LiteralData>
+    DataType = float
+    <Default>
+     uom = meters
+     value = 1
+    </Default>
+    <Supported>
+     uom = feet
+    </Supported>
+   </LiteralData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Buffered Polygon
+   Abstract = GML stream describing the buffered polygon feature.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     asReference = true	
+    </Supported>
+   </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/CentroidPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/CentroidPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/CentroidPy.zcfg	(revision 9)
@@ -0,0 +1,54 @@
+[CentroidPy]
+ Title = Get the centroid of a polygon. 
+ Abstract = Compute the geometry centroid.
+ Profile = urn:ogc:wps:1.0.0:centroid
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData lang="en">
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputPolygon]
+   Title = Polygon to get the centroid
+   Abstract = The centroid which is not necessarily within the geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <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 = The Centroid
+   Abstract = JSON String / GML Entity of the centroid
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/point.xsd
+     asReference = true	
+    </Supported>
+   </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ConvexHullPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ConvexHullPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ConvexHullPy.zcfg	(revision 9)
@@ -0,0 +1,51 @@
+[ConvexHullPy]
+ 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.
+ processVersion = 1
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData lang="en">
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputPolygon]
+   Title = Polygon to compute convexhull
+   Abstract = URI to a set of GML that describes the polygon.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+   title = Mon test
+   </MetaData>
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = application/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The convex hull of the geometry
+   Abstract = The convex hull of the geometry
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataOutputs> 
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/DifferencePy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/DifferencePy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/DifferencePy.zcfg	(revision 9)
@@ -0,0 +1,75 @@
+[DifferencePy]
+ Title = Compute difference. . 
+ Abstract = Generates a new geometry which is the region of this geometry with the region of the other geometry removed.
+ Profile = urn:ogc:wps:1.0.0:difference
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <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
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <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 = The difference between two geometries
+   Abstract = The difference between the two geometries.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+    <ComplexData>
+     <Default>
+       mimeType = application/json
+       encoding = UTF-8
+       extension = js
+     </Default>
+     <Supported>
+      mimeType = text/xml
+      schema = http://fooa/gml/3.1.0/polygon.xsd
+      encoding = UTF-8
+      extension = xml
+     </Supported>
+    </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/IntersectionPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/IntersectionPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/IntersectionPy.zcfg	(revision 9)
@@ -0,0 +1,75 @@
+[IntersectionPy]
+ 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_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <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
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <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 = Intersection of the two geometries
+   Abstract = A new geometry representing the intersection or NULL if there is no intersection or an error occurs.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+    <ComplexData>
+     <Default>
+       mimeType = application/json
+       encoding = UTF-8
+       extension = js
+     </Default>
+     <Supported>
+      mimeType = text/xml
+      schema = http://fooa/gml/3.1.0/polygon.xsd
+      encoding = UTF-8
+      extension = xml
+     </Supported>
+    </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/SymDifferencePy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/SymDifferencePy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/SymDifferencePy.zcfg	(revision 9)
@@ -0,0 +1,75 @@
+[SymDifferencePy]
+ Title = Compute symmetric difference. 
+ Abstract = Generates a new geometry which is the symmetric difference of this geometry and the other geometry.
+ Profile = urn:ogc:wps:1.0.0:symmetricdifference
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <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
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <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 = The symmetric difference between two geometries
+   Abstract = The symmetric difference between the two geometries.
+   <MetaData lang="en">
+    Title = Symmetric Difference  
+   </MetaData>   
+    <ComplexData>
+     <Default>
+       mimeType = application/json
+       encoding = UTF-8
+       extension = js
+     </Default>
+     <Supported>
+      mimeType = text/xml
+      schema = http://fooa/gml/3.1.0/polygon.xsd
+      encoding = UTF-8
+      extension = xml
+     </Supported>
+    </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/UnionPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/UnionPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/UnionPy.zcfg	(revision 9)
@@ -0,0 +1,73 @@
+[UnionPy]
+ 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
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = application/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = application/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The union of two geometries
+   Abstract = The geometry representing the union of the two geometries.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+    <ComplexData>
+     <Default>
+       mimeType = application/json
+       encoding = UTF-8
+       extension = js
+     </Default>
+     <Supported>
+      mimeType = text/xml
+      schema = http://fooa/gml/3.1.0/polygon.xsd
+      encoding = UTF-8
+      extension = xml
+     </Supported>
+    </ComplexData>
+ </DataOutputs>  
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 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 9)
@@ -0,0 +1,95 @@
+import osgeo.ogr
+import libxml2
+
+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']")
+    for node in res:
+        geometry_as_string=node.serialize()
+        geometry=osgeo.ogr.CreateGeometryFromGML(geometry_as_string)
+	return geometry
+    return geometry
+
+def extractInputs(obj):
+    if obj["mimeType"]=="application/json":
+	return osgeo.ogr.CreateGeometryFromJson(obj["value"])
+    else:
+	try:
+        	return createGeometryFromWFS(obj["value"])
+	except:
+		return osgeo.ogr.CreateGeometryFromJson(obj["value"])
+    return null
+    
+def outputResult(obj,geom):
+    if obj["mimeType"]=="application/json":
+        obj["value"]=geom.ExportToJson()
+        obj["mimeType"]="text/plain"
+    else:
+        obj["value"]=geom.ExportToGML()
+
+def BoundaryPy(conf,inputs,outputs):
+    geometry=extractInputs(inputs["InputPolygon"])
+    rgeom=geometry.GetBoundary()
+    if outputs["Result"]["mimeType"]=="application/json":
+        outputs["Result"]["value"]=rgeom.ExportToJson()
+        outputs["Result"]["mimeType"]="text/plain"
+    else:
+        outputs["Result"]["value"]=rgeom.ExportToGML()
+    return 3
+
+def CentroidPy(conf,inputs,outputs):
+    geometry=extractInputs(inputs["InputPolygon"])
+    if geometry.GetGeometryType()!=3:
+        geometry=geometry.ConvexHull()
+    rgeom=geometry.Centroid()
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def ConvexHullPy(conf,inputs,outputs):
+    geometry=extractInputs(inputs["InputPolygon"])
+    rgeom=geometry.ConvexHull()
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def BufferPy(conf,inputs,outputs):
+    geometry=createGeometryFromWFS(inputs["InputPolygon"]["value"])
+    try:
+        bdist=int(inputs["BufferDistance"]["value"])
+    except:
+        bdist=10
+    rgeom=geometry.Buffer(bdist)
+    if outputs["Result"]["mimeType"]=="application/json":
+        outputs["Result"]["value"]=rgeom.ExportToJson()
+        outputs["Result"]["mimeType"]="text/plain"
+    else:
+        outputs["Result"]["value"]=rgeom.ExportToGML()
+    return 3
+
+def UnionPy(conf,inputs,outputs):
+    geometry1=extractInputs(inputs["InputEntity1"])
+    geometry2=extractInputs(inputs["InputEntity2"])
+    rgeom=geometry1.Union(geometry2)
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def IntersectionPy(conf,inputs,outputs):
+    geometry1=extractInputs(inputs["InputEntity1"])
+    geometry2=extractInputs(inputs["InputEntity2"])
+    rgeom=geometry1.Intersection(geometry2)
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def DifferencePy(conf,inputs,outputs):
+    geometry1=extractInputs(inputs["InputEntity1"])
+    geometry2=extractInputs(inputs["InputEntity2"])
+    rgeom=geometry1.Difference(geometry2)
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def SymDifferencePy(conf,inputs,outputs):
+    geometry1=extractInputs(inputs["InputEntity1"])
+    geometry2=extractInputs(inputs["InputEntity2"])
+    rgeom=geometry1.SymmetricDifference(geometry2)
+    outputResult(outputs["Result"],rgeom)
+    return 3
Index: trunk/zoo-services/ogr/base-vect-ops/Makefile
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/Makefile	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/Makefile	(revision 9)
@@ -1,7 +1,7 @@
-CFLAGS=-I../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags`  `gdal-config --cflags`   -DLINUX_FREE_ISSUE #-DDEBUG
+CFLAGS=-I../../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags`  `gdal-config --cflags`   -DLINUX_FREE_ISSUE #-DDEBUG
 CC=gcc
 
 cgi-env/service.zo: service.c
-	g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c `gdal-config --libs`
+	g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o `gdal-config --libs`
 
 clean:
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg	(revision 9)
@@ -8,19 +8,20 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
   [InputPolygon]
-   Title = Polygon to be buffered
+   Title = Polygon to compute boundary
    Abstract = URI to a set of GML that describes the polygon.
    minOccurs = 1
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
-     mimeType = text/js
+     mimeType = text/xml
      encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
     </Default>
     <Supported>
@@ -30,41 +31,30 @@
     </Supported>
    </ComplexData>
-  [BufferDistance]
-   Title = Buffer Distance
-   Abstract = Distance to be used to calculate buffer.
-   minOccurs = 0
-   maxOccurs = 1
-   <LiteralData>
-    DataType = float
-    <Default>
-     uom = meters
-    </Default>
-    <Supported>
-     uom = feet
-    </Supported>
-   </LiteralData>
  </DataInputs>
  <DataOutputs>
-  [Boundary]
+  [Result]
    Title = The geometry created
    Abstract = The geometry containing the boundary of the geometry on which the method is invoked.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
-     mimeType = text/xml
+     mimeType = application/json
      encoding = UTF-8
-     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = js
      asReference = true	
     </Default>
     <Supported>
      mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = xml
+    </Supported>
+    <Supported>
+     mimeType = text/xml
      encoding = base64
      schema = http://fooa/gml/3.1.0/polygon.xsd
-    </Supported>
-    <Supported>
-     mimeType = text/js
-     encoding = UTF-8
+     extension = xml
     </Supported>
    </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData lang="en">
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -49,15 +49,15 @@
  </DataInputs>
  <DataOutputs>
-  [BufferedPolygon]
+  [Result]
    Title = Buffered Polygon
    Abstract = GML stream describing the buffered polygon feature.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
-     mimeType = text/xml
+     mimeType = application/json
      encoding = UTF-8
-     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = js
      asReference = true	
     </Default>
@@ -66,8 +66,11 @@
      encoding = base64
      schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = xml
     </Supported>
     <Supported>
-     mimeType = application/json
+     mimeType = text/xml
      encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = xml
     </Supported>
    </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg	(revision 9)
@@ -1,5 +1,5 @@
 [Centroid]
  Title = Get the centroid of a polygon. 
- Abstract = Create a buffer around a single polygon. Accepts the polygon as GML and provides GML output for the buffered feature. 
+ Abstract = Compute the geometry centroid.
  Profile = urn:ogc:wps:1.0.0:centroid
  processVersion = 2
@@ -9,14 +9,14 @@
  serviceType = C
  <MetaData lang="en">
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
   [InputPolygon]
-   Title = Polygon to be buffered
-   Abstract = URI to a set of GML that describes the polygon.
+   Title = Polygon to get the centroid
+   Abstract = The centroid which is not necessarily within the geometry.
    minOccurs = 1
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -34,25 +34,22 @@
  </DataInputs>
  <DataOutputs>
-  [Centroid]
+  [Result]
    Title = The Centroid
    Abstract = JSON String / GML Entity of the centroid
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
-     mimeType = text/js
+     mimeType = application/json
      encoding = UTF-8
+     extension = js
+     asReference = true	
     </Default>
-    <Supported>
-     mimeType = text/xml
-     encoding = base64
-     schema = http://fooa/gml/3.1.0/point.xsd
-    </Supported>
     <Supported>
      mimeType = text/xml
      encoding = UTF-8
      schema = http://fooa/gml/3.1.0/point.xsd
-     asReference = true	
+     extension = xml
     </Supported>
    </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg	(revision 9)
@@ -8,14 +8,14 @@
  serviceType = C
  <MetaData lang="en">
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
   [InputPolygon]
-   Title = Polygon to compute are
+   Title = Polygon to compute convexhull
    Abstract = URI to a set of GML that describes the polygon.
    minOccurs = 1
    maxOccurs = 1
    <MetaData lang="en">
-   Test1 = Mon test
+   title = Mon test
    </MetaData>
    <ComplexData>
@@ -37,16 +37,18 @@
    Abstract = The convex hull of the geometry
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
+     mimeType = application/json
+     encoding = UTF-8
+     extension = js
+     asReference = true	
+    </Default>
+    <Supported>
      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
+     extension = xml
     </Supported>
    </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -54,9 +54,9 @@
  </DataInputs>
  <DataOutputs>
-  [Distance]
-   Title = The distance between two geometries
-   Abstract = The shortest distance between the two geometries.
+  [Result]
+   Title = The difference between two geometries
+   Abstract = The difference between the two geometries.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <ComplexData>
@@ -64,4 +64,5 @@
        mimeType = application/json
        encoding = UTF-8
+       extension = js
      </Default>
      <Supported>
@@ -69,4 +70,5 @@
       schema = http://fooa/gml/3.1.0/polygon.xsd
       encoding = UTF-8
+      extension = xml
      </Supported>
     </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Distance.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Distance.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Distance.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -58,5 +58,5 @@
    Abstract = The shortest distance between the two geometries.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <LiteralData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/GetArea.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/GetArea.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/GetArea.zcfg	(revision 9)
@@ -8,5 +8,5 @@
  serviceType = C
  <MetaData lang="en">
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -17,5 +17,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-   Test1 = Mon test
+   title = Mon test
    </MetaData>
    <ComplexData>
@@ -37,5 +37,5 @@
    Abstract = The Computed Area Value
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <LiteralData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -54,9 +54,9 @@
  </DataInputs>
  <DataOutputs>
-  [Distance]
-   Title = The distance between two geometries
-   Abstract = The shortest distance between the two geometries.
+  [Result]
+   Title = Intersection of geometries
+   Abstract = A new geometry representing the intersection or NULL if there is no intersection or an error occurs.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <ComplexData>
@@ -64,4 +64,5 @@
        mimeType = application/json
        encoding = UTF-8
+       extension = js
      </Default>
      <Supported>
@@ -69,4 +70,5 @@
       schema = http://fooa/gml/3.1.0/polygon.xsd
       encoding = UTF-8
+      extension = xml
      </Supported>
     </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -54,9 +54,9 @@
  </DataInputs>
  <DataOutputs>
-  [Distance]
-   Title = The distance between two geometries
-   Abstract = The shortest distance between the two geometries.
+  [Result]
+   Title = The resulting geometry
+   Abstract = The symmetric difference of two geometries
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <ComplexData>
@@ -64,4 +64,5 @@
        mimeType = application/json
        encoding = UTF-8
+       extension = js
      </Default>
      <Supported>
@@ -69,4 +70,5 @@
       schema = http://fooa/gml/3.1.0/polygon.xsd
       encoding = UTF-8
+      extension = xml
      </Supported>
     </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -54,9 +54,9 @@
  </DataInputs>
  <DataOutputs>
-  [Distance]
-   Title = The distance between two geometries
-   Abstract = The shortest distance between the two geometries.
+  [Result]
+   Title = The union of two geometries
+   Abstract = The geometry representing the union of the two geometries.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <ComplexData>
@@ -64,4 +64,5 @@
        mimeType = application/json
        encoding = UTF-8
+       extension = js
      </Default>
      <Supported>
@@ -69,4 +70,5 @@
       schema = http://fooa/gml/3.1.0/polygon.xsd
       encoding = UTF-8
+      extension = xml
      </Supported>
     </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/service.c
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/service.c	(revision 1)
+++ trunk/zoo-services/ogr/base-vect-ops/service.c	(revision 9)
@@ -23,6 +23,8 @@
  */
 
-#include "cpl_minixml.h"
+#include "cpl_conv.h"
 #include "ogr_api.h"
+#include "ogr_geometry.h"
+#include "geos_c.h"
 #include "service.h"
 
@@ -39,5 +41,4 @@
 #include <openssl/buffer.h>
 
-  xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
   void printExceptionReportResponse(maps*,map*);
   char *base64(const unsigned char *input, int length);
@@ -71,9 +72,12 @@
     }
     xmlDocDumpFormatMemory(ndoc, &xmlbuff, &buffersize, 1);
-    char *tmp=strdup(strstr((char*)xmlbuff,"?>")+2);
+    char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char));
+    sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2);
+    //strdup(strstr((char*)xmlbuff,"?>")+2);
     xmlXPathFreeObject(xpathObj);
-    xmlXPathFreeContext(xpathCtx); 
+    xmlXPathFreeContext(xpathCtx);
     xmlFree(xmlbuff);
     xmlFreeDoc(doc);
+    xmlFreeDoc(ndoc);
     xmlCleanupParser();
 #ifdef DEBUG
@@ -81,12 +85,301 @@
 #endif
     OGRGeometryH res=OGR_G_CreateFromGML(tmp);
+    free(tmp);
     if(res==NULL){
-    	map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML");
-	addToMap(tmp,"code","NoApplicableCode");
-	printExceptionReportResponse(conf,tmp);
-	exit(0);
+      map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML");
+      addToMap(tmp,"code","NoApplicableCode");
+      printExceptionReportResponse(conf,tmp);
+      exit(0);
     }
     else
-    	return OGR_G_CreateFromGML(tmp);
+      return res;//OGR_G_CreateFromGML(tmp);
+  }
+
+  int Simplify(maps*& conf,maps*& inputs,maps*& outputs){
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+    double tolerance;
+    map* tmp0=getMapFromMaps(cursor,"Tolerance","value");
+    if(tmp0==NULL){
+      tolerance=atof("2.0");
+    }
+    else
+      tolerance=atof(tmp0->value);
+    fprintf(stderr,"Tolerance for Simplify %f",tolerance);
+    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+    if(!tmp)
+      return SERVICE_FAILED;
+    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime");
+    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);
+    }
+    else
+      geometry=createGeometryFromGML(conf,tmp->value);
+    GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS();
+    GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance);
+    res=OGRGeometryFactory::createFromGEOS(gres);
+    if(tmp1!=NULL){
+      if(strncmp(tmp1->value,"text/js",7)==0 ||
+	 strncmp(tmp1->value,"application/json",16)==0){
+        outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value));
+	addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
+	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
+      }
+      else{
+        outputs->content=createMap("value",OGR_G_ExportToGML(res));
+	addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
+	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
+	addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
+      }
+    }else{
+      outputs->content=createMap("value",OGR_G_ExportToJson(res));
+      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
+      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
+    }
+    outputs->next=NULL;
+    //GEOSFree(ggeometry);
+    //GEOSFree(gres);
+    OGR_G_DestroyGeometry(res);
+    OGR_G_DestroyGeometry(geometry);
+    return SERVICE_SUCCEEDED;
+  }
+
+
+  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){
+#ifdef DEBUG
+    fprintf(stderr,"\nService internal print\n");
+#endif
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+#ifdef DEBUG
+    dumpMaps(cursor);
+#endif
+    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+    if(!tmp)
+      return SERVICE_FAILED;
+    fprintf(stderr,"Service internal print \n");
+    dumpMaps(inputs);
+    fprintf(stderr,"/Service internal print \n");
+    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
+    fprintf(stderr,"Service internal print \n");
+    dumpMap(tmp1);
+    fprintf(stderr,"/Service internal print \n");
+    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);
+    }
+    else
+      geometry=createGeometryFromGML(conf,tmp->value);
+    res=(*myFunc)(geometry);
+    fprintf(stderr,"Service internal print \n");
+    dumpMaps(outputs);
+    fprintf(stderr,"/Service internal print \n");
+    map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
+    fprintf(stderr,"Service internal print \n");
+    dumpMap(tmp_2);
+    fprintf(stderr,"/Service internal print \n");
+    if(tmp_2!=NULL){
+      if(strncmp(tmp_2->value,"text/js",7)==0 ||
+	 strncmp(tmp_2->value,"application/json",16)==0){
+	char *tres=OGR_G_ExportToJson(res);
+        addToMap(outputs->content,"value",tres);
+	free(tres);
+	addToMap(outputs->content,"mimeType","text/plain");
+	addToMap(outputs->content,"encoding","UTF-8");
+      }
+      else{
+	char *tres=OGR_G_ExportToGML(res);
+        addToMap(outputs->content,"value",tres);
+	free(tres);
+      }
+    }else{
+      char *tres=OGR_G_ExportToJson(res);
+      addToMap(outputs->content,"value",tres);
+      free(tres);
+      addToMap(outputs->content,"mimeType","text/plain");
+      addToMap(outputs->content,"encoding","UTF-8");
+    }
+    outputs->next=NULL;
+#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,"Service internal print \n");
+    dumpMaps(outputs);
+    fprintf(stderr,"/Service internal print \n");
+    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)
+     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);
+   int bufferDistance=1;
+   tmp=getMapFromMaps(inputs,"BufferDistance","value");
+   if(tmp!=NULL)
+		bufferDistance=atoi(tmp->value);
+   res=OGR_G_Buffer(geometry,bufferDistance,30);
+   tmp1=getMapFromMaps(outputs,"Result","mimeType");
+   if(strncmp(tmp1->value,"application/json",16)==0){
+		addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+		addToMap(outputs->content,"mimeType","text/plain");
+   }
+   else{
+		addToMap(outputs->content,"value",OGR_G_ExportToGML(res));
+   }
+   outputs->next=NULL;
+   OGR_G_DestroyGeometry(geometry);
+   OGR_G_DestroyGeometry(res);
+   return SERVICE_SUCCEEDED;
+}
+
+/*  int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
+#ifdef DEBUG
+    fprintf(stderr,"\nService internal print\n");
+#endif
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+    int bufferDistance;    
+    if(cursor!=NULL){
+#ifdef DEBUG
+      fprintf(stderr,"\nService internal print\n");
+      dumpMaps(cursor);
+      fprintf(stderr,"\nService internal print\n");
+      dumpMaps(inputs);
+      fprintf(stderr,"\nService internal print\n");
+#endif
+      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
+      if(tmp1!=NULL){
+        if(strncmp(tmp1->value,"application/json",16)==0 ||
+	   strncmp(tmp1->value,"text/js",7)==0)
+      	  geometry=OGR_G_CreateGeometryFromJson(tmp->value);
+	else
+	  geometry=createGeometryFromGML(conf,tmp->value);
+      }
+      else
+      	geometry=createGeometryFromGML(conf,tmp->value);
+    }
+    if(cursor!=NULL){
+      map* tmp=getMapFromMaps(cursor,"BufferDistance","value");
+      if(tmp==NULL){
+	bufferDistance=10;
+      }
+      else
+	bufferDistance=atoi(tmp->value);
+#ifdef DEBUG
+      fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);
+#endif
+    }
+#ifdef DEBUG
+    dumpMaps(outputs);
+#endif
+    map* tmp=getMapFromMaps(outputs,"Result","mimeType");
+    res=OGR_G_Buffer(geometry,bufferDistance,30);
+#ifdef DEBUG
+    dumpMap(tmp);
+#endif
+    if(tmp!=NULL){
+#ifdef DEBUG
+      dumpMap(tmp);
+#endif
+      if(strncmp(tmp->value,"application/json",16)==0){
+	addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+	addToMap(outputs->content,"mimeType","text/plain");
+	addToMap(outputs->content,"encoding","UTF-8");
+      }
+      else if(strcmp(tmp->value,"text/xml")==0){
+	xmlInitParser();
+	xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
+	xmlChar *xmlbuff;
+	int buffersize;
+	char *buff=OGR_G_ExportToGML(res);
+	addToMap(outputs->content,"value",buff);
+	map* tmp1=getMapFromMaps(outputs,"Result","encoding");
+	if(tmp1!=NULL)
+	  addToMap(outputs->content,"encoding",tmp1->value);
+	else
+	  addToMap(outputs->content,"encoding","UTF-8");
+	xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
+	xmlFree(xmlbuff);
+	xmlFreeDoc(doc);
+	xmlCleanupParser();
+      }
+      else{
+	addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+	addToMap(outputs->content,"mimeType","text/plain");
+	addToMap(outputs->content,"encoding","UTF-8");
+	outputs->next=NULL;
+      }
+      outputs->next=NULL;
+    }
+    else{
+      addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+      addToMap(outputs->content,"mimeType","text/plain");
+      addToMap(outputs->content,"encoding","UTF-8");
+      outputs->next=NULL;
+    }
+    outputs->next=NULL;
+#ifdef DEBUG
+    dumpMaps(outputs);
+    fprintf(stderr,"\nService internal print\n===\n");
+#endif
+    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);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull);
+  }
+
+
+  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);
   }
 
@@ -130,15 +423,14 @@
     }
     res=(*myFunc)(geometry1,geometry2);
-    outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="Result";
-    char tmpres[100];
-    sprintf(tmpres,"%d",res);
-    outputs->content=createMap("value",OGR_G_ExportToJson(res));
-    addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-    addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
+    addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+    addToMap(outputs->content,"mimeType","text/plain");
+    addToMap(outputs->content,"encoding","UTF-8");
     outputs->next=NULL;
+    OGR_G_DestroyGeometry(geometry1);
+    OGR_G_DestroyGeometry(geometry2);
+    OGR_G_DestroyGeometry(res);
     return SERVICE_SUCCEEDED;
   }
-
+  
 #ifdef WIN32
   __declspec(dllexport)
@@ -162,366 +454,9 @@
   }
 
-  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n");
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry,res;
-    int bufferDistance;
-#ifdef DEBUG
-    dumpMaps(cursor);
-#endif
-    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-    if(!tmp)
-      return SERVICE_FAILED;
-    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime");
-    if(tmp1!=NULL){
-      if(strncmp(tmp1->value,"text/js",7)==0)
-        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-      else
-        geometry=createGeometryFromGML(conf,tmp->value);
-      }
-    else
-      geometry=createGeometryFromGML(conf,tmp->value);
-    res=(*myFunc)(geometry);
-    /**
-     * Here we should check what is the requested output.
-     * Let's use JSON per default.
-     */
-    //outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="Result";
-    if(tmp1!=NULL){
-      if(strncmp(tmp1->value,"text/js",7)==0){
-        outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value));
-	addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      }
-      else{
-        outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
-	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-	addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
-      }
-    }else{
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-    }
-    outputs->next=NULL;
-#ifdef DEBUG
-    dumpMaps(outputs);
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    return SERVICE_SUCCEEDED;
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull);
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\nStarting\n");
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry,res;
-    int bufferDistance;
-    xmlInitParser();
-    
-    if(cursor!=NULL){
-      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"text/js",7)==0)
-      	  geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry=createGeometryFromGML(conf,tmp->value);
-    }
-    res=OGR_G_GetBoundary(geometry);
-    outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="Boundary";
-    outputs->content=createMap("value",OGR_G_ExportToJson(res));
-    addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-    addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-    /*
-    outputs->content=createMap("value",OGR_G_ExportToGML(res));
-    addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
-    addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-    addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
-    */
-    outputs->next=NULL;
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    xmlCleanupParser();
-    return SERVICE_SUCCEEDED;
-    }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n");
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry,res=NULL;
-    int bufferDistance;    
-    if(cursor!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"\nService internal print\n");
-      dumpMaps(cursor);
-      fprintf(stderr,"\nService internal print\n");
-      dumpMaps(inputs);
-      fprintf(stderr,"\nService internal print\n");
-#endif
-      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0)
-      	  geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry=createGeometryFromGML(conf,tmp->value);
-    }else{
-    /**
-     * Print WPSExceptionError message here !!
-     */
-    }
-#ifdef DEBUG
-    dumpMaps(outputs);
-#endif
-    res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
-    OGRwkbGeometryType gtype=OGR_G_GetGeometryType(geometry);
-    if(gtype!=wkbPolygon){
-    	fprintf(stderr,"\n\nGeometry Type is not Polygon, let us use the ConvexHull !\n\n");
-    	geometry=OGR_G_ConvexHull(OGR_G_Clone(geometry));
-    }else{
-    	fprintf(stderr,"\n\nGeometry Type is Polygon, thanks !\n\n");
-    }
-    int c=OGR_G_Centroid(geometry,res);
-#ifdef DEBUG
-    fprintf(stderr,"\n\nC VALUE : %d\n\n",c);
-#endif
-    map* tmp=getMapFromMaps(outputs,"Result","mimeType");
-#ifdef DEBUG
-    dumpMaps(outputs);
-#endif
-    if(tmp!=NULL){
-#ifdef DEBUG
-      dumpMap(tmp);
-#endif
-      if(strncmp(mtoupper(tmp->value),mtoupper("application/json"),16)==0){
-	outputs->content=createMap("value",OGR_G_ExportToJson(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      }
-      else if(strncmp(mtoupper(tmp->value),mtoupper("text/xml"),8)==0){
-	/*xmlInitParser();
-	xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
-	xmlChar *xmlbuff;
-	int buffersize;*/
-	outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
-	map* tmp1=getMapFromMaps(outputs,"Result","encoding");
-	if(tmp1!=NULL)
-	  addMapToMap(&outputs->content,createMap("encoding",tmp1->value));
-	else
-	  addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-	/*xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-	outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	xmlFree(xmlbuff);
-	xmlFreeDoc(doc);
-	xmlCleanupParser();
-	*/
-      }
-    else{
-      outputs=(maps*)malloc(sizeof(maps*));
-      outputs->name="Result";
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      outputs->next=NULL;
-    }
-    outputs->next=NULL;
-    }
-    else{
-      outputs=(maps*)malloc(sizeof(maps*));
-      outputs->name="Result";
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      outputs->next=NULL;
-    }
-    outputs->next=NULL;
-#ifdef DEBUG
-    dumpMaps(outputs);
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    return SERVICE_SUCCEEDED;
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n");
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry,res;
-    int bufferDistance;    
-    if(cursor!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"\nService internal print\n");
-      dumpMaps(cursor);
-      fprintf(stderr,"\nService internal print\n");
-      dumpMaps(inputs);
-      fprintf(stderr,"\nService internal print\n");
-#endif
-      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0)
-      	  geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry=createGeometryFromGML(conf,tmp->value);
-    }
-    if(cursor!=NULL){
-      map* tmp=getMapFromMaps(cursor,"BufferDistance","value");
-      if(tmp==NULL){
-	bufferDistance=10;
-      }
-      else
-	bufferDistance=atoi(tmp->value);
-#ifdef DEBUG
-      fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);
-#endif
-    }
-#ifdef DEBUG
-    dumpMaps(outputs);
-#endif
-    map* tmp=getMapFromMaps(outputs,"BufferedPolygon","mimeType");
-    res=OGR_G_Buffer(geometry,bufferDistance,30);
-#ifdef DEBUG
-    dumpMap(tmp);
-#endif
-    if(tmp!=NULL){
-#ifdef DEBUG
-      dumpMap(tmp);
-#endif
-      if(strncmp(mtoupper(tmp->value),mtoupper("application/json"),16)==0){
-	outputs->content=createMap("value",OGR_G_ExportToJson(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      }
-      else if(strcmp(mtoupper(tmp->value),mtoupper("text/xml"))==0){
-	xmlInitParser();
-	xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
-	xmlChar *xmlbuff;
-	int buffersize;
-	outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
-	map* tmp1=getMapFromMaps(outputs,"BufferedPolygon","encoding");
-	if(tmp1!=NULL)
-	  addMapToMap(&outputs->content,createMap("encoding",tmp1->value));
-	else
-	  addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-	xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-	outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	xmlFree(xmlbuff);
-	xmlFreeDoc(doc);
-	xmlCleanupParser();
-      }
-    else{
-      outputs=(maps*)malloc(sizeof(maps*));
-      outputs->name="BufferedPolygon";
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      outputs->next=NULL;
-    }
-    outputs->next=NULL;
-    }
-    else{
-      outputs=(maps*)malloc(sizeof(maps*));
-      outputs->name="BufferedPolygon";
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      outputs->next=NULL;
-    }
-    outputs->next=NULL;
-#ifdef DEBUG
-    dumpMaps(outputs);
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    return SERVICE_SUCCEEDED;
-  }
-
 #ifdef WIN32
   __declspec(dllexport)
 #endif
   int Union(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print1\n");
-    fflush(stderr);
-#endif
-    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);
-    }
-    {
-      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
-      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
-#ifdef DEBUG
-      fprintf(stderr,"MY MAP\n");
-      dumpMap(tmp1);
-      fprintf(stderr,"MY MAP\n");
-#endif
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0)
-      	  geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry2=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry2=createGeometryFromGML(conf,tmp->value);
-    }
-    res=OGR_G_Union(geometry1,geometry2);
-    outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="Result";
-    char tmpres[100];
-    sprintf(tmpres,"%d",res);
-    outputs->content=createMap("value",OGR_G_ExportToJson(res));
-    addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-    addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-    outputs->next=NULL;
-    return SERVICE_SUCCEEDED;
+    return applyTwo(conf,inputs,outputs,&OGR_G_Union);
   }
 
@@ -589,4 +524,7 @@
   }
 
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
   int GetArea(maps*& conf,maps*& inputs,maps*& outputs){
     fprintf(stderr,"GETAREA \n");
