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");
