source: trunk/zoo-services/ogr/base-vect-ops/service.c @ 216

Last change on this file since 216 was 216, checked in by djay, 13 years ago

Add WIN32 platform support. Fix for values containing @ passed as KVP.

File size: 19.3 KB
RevLine 
[1]1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright 2008-2009 GeoLabs SARL. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
[9]25#include "cpl_conv.h"
[1]26#include "ogr_api.h"
[9]27#include "ogr_geometry.h"
28#include "geos_c.h"
[1]29#include "service.h"
[36]30#include "service_internal.h"
[1]31
32extern "C" {
33#include <libxml/tree.h>
34#include <libxml/parser.h>
35#include <libxml/xpath.h>
36#include <libxml/xpathInternals.h>
37
38#include <openssl/sha.h>
39#include <openssl/hmac.h>
40#include <openssl/evp.h>
41#include <openssl/bio.h>
42#include <openssl/buffer.h>
43
44  void printExceptionReportResponse(maps*,map*);
[216]45  char *base64(const char *input, int length);
[1]46
47  OGRGeometryH createGeometryFromGML(maps* conf,char* inputStr){
48    xmlInitParser();
49    xmlDocPtr doc = xmlParseMemory(inputStr,strlen(inputStr));
50    xmlChar *xmlbuff;
51    int buffersize;
52    xmlXPathContextPtr xpathCtx;
53    xmlXPathObjectPtr xpathObj;
54    char * xpathExpr="/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']";
55    xpathCtx = xmlXPathNewContext(doc);
56    xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr,xpathCtx);
57    if(!xpathObj->nodesetval){
[216]58      setMapInMaps(conf,"lenv","message",_ss("Unable to parse Input Polygon"));
59      setMapInMaps(conf,"lenv","code","InvalidParameterValue");
60      return NULL;
[1]61    }
62    int size = (xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0;
63    /**
64     * Create a temporary XML document
65     */
66    xmlDocPtr ndoc = xmlNewDoc(BAD_CAST "1.0");
67    /**
68     * Only one polygon should be provided so we use it as the root node.
69     */
70    for(int k=size-1;k>=0;k--){ 
71      xmlDocSetRootElement(ndoc, xpathObj->nodesetval->nodeTab[k]);
72    }
73    xmlDocDumpFormatMemory(ndoc, &xmlbuff, &buffersize, 1);
[9]74    char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char));
75    sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2);
[1]76    xmlXPathFreeObject(xpathObj);
[9]77    xmlXPathFreeContext(xpathCtx);
[1]78    xmlFree(xmlbuff);
79    xmlFreeDoc(doc);
[9]80    xmlFreeDoc(ndoc);
[216]81#ifndef WIN32
[1]82    xmlCleanupParser();
[216]83#endif
[1]84#ifdef DEBUG
85    fprintf(stderr,"\nService internal print\n Loading the geometry from GML string ...");
86#endif
87    OGRGeometryH res=OGR_G_CreateFromGML(tmp);
[9]88    free(tmp);
[1]89    if(res==NULL){
[36]90      setMapInMaps(conf,"lenv","message",_ss("Unable to call OGR_G_CreatFromGML"));
[26]91      return NULL;
[1]92    }
93    else
[26]94      return res;
[1]95  }
96
[216]97#ifdef WIN32
98  __declspec(dllexport)
99#endif
[9]100  int Simplify(maps*& conf,maps*& inputs,maps*& outputs){
[1]101    maps* cursor=inputs;
[9]102    OGRGeometryH geometry,res;
103    double tolerance;
104    map* tmp0=getMapFromMaps(cursor,"Tolerance","value");
105    if(tmp0==NULL){
106      tolerance=atof("2.0");
[1]107    }
[9]108    else
109      tolerance=atof(tmp0->value);
[216]110#ifdef DEBUG
[9]111    fprintf(stderr,"Tolerance for Simplify %f",tolerance);
[216]112#endif
[1]113    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
[26]114    if(!tmp){
[36]115      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
[1]116      return SERVICE_FAILED;
[26]117    }
118    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
[1]119    if(tmp1!=NULL){
[9]120      if(strncmp(tmp1->value,"text/js",7)==0 ||
[26]121         strncmp(tmp1->value,"application/json",16)==0)
[1]122        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
123      else
124        geometry=createGeometryFromGML(conf,tmp->value);
[9]125    }
[26]126    else{
[36]127      setMapInMaps(conf,"lenv","message",_ss("Unable to find any geometry for InputPolygon"));
[26]128      return SERVICE_FAILED;
129    }
130    if(geometry==NULL){
[36]131      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
[26]132      return SERVICE_FAILED;
133    }
[216]134#ifdef DEBUG
[26]135    fprintf(stderr,"Create GEOSGeometry object");
[216]136#endif
[9]137    GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS();
138    GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance);
[216]139    res=(OGRGeometryH)OGRGeometryFactory::createFromGEOS(gres);
[26]140    tmp1=getMapFromMaps(outputs,"Result","mimeType");
[1]141    if(tmp1!=NULL){
[9]142      if(strncmp(tmp1->value,"text/js",7)==0 ||
143         strncmp(tmp1->value,"application/json",16)==0){
[26]144        char *tmpS=OGR_G_ExportToJson(res);
145        setMapInMaps(outputs,"Result","value",tmpS);
[216]146#ifndef WIN32
[26]147        setMapInMaps(outputs,"Result","mimeType","text/plain");
148        setMapInMaps(outputs,"Result","encoding","UTF-8");
149        free(tmpS);
[216]150#endif
[1]151      }
152      else{
[26]153        char *tmpS=OGR_G_ExportToGML(res);
154        setMapInMaps(outputs,"Result","value",tmpS);
[216]155#ifndef WIN32
[26]156        setMapInMaps(outputs,"Result","mimeType","text/xml");
157        setMapInMaps(outputs,"Result","encoding","UTF-8");
158        setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
159        free(tmpS);
[216]160#endif
[1]161      }
162    }else{
[216]163      char *tmpS=OGR_G_ExportToJson(res);
[26]164      setMapInMaps(outputs,"Result","value",tmpS);
[216]165#ifndef WIN32
[26]166      setMapInMaps(outputs,"Result","mimeType","text/plain");
167      setMapInMaps(outputs,"Result","encoding","UTF-8");
168      free(tmpS);
[216]169#endif
[1]170    }
171    outputs->next=NULL;
[9]172    //GEOSFree(ggeometry);
173    //GEOSFree(gres);
174    OGR_G_DestroyGeometry(res);
175    OGR_G_DestroyGeometry(geometry);
[1]176    return SERVICE_SUCCEEDED;
177  }
178
179
[54]180  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH),char* schema){
[1]181#ifdef DEBUG
[9]182    fprintf(stderr,"\nService internal print\n");
[1]183#endif
184    maps* cursor=inputs;
185    OGRGeometryH geometry,res;
186#ifdef DEBUG
[9]187    dumpMaps(cursor);
[1]188#endif
[9]189    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
[35]190    if(!tmp){
[36]191      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
[9]192      return SERVICE_FAILED;
[35]193    }
[216]194#ifdef DEBUG
[9]195    fprintf(stderr,"Service internal print \n");
196    dumpMaps(inputs);
197    fprintf(stderr,"/Service internal print \n");
[216]198#endif
[9]199    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
[216]200#ifdef DEBUG
[9]201    fprintf(stderr,"Service internal print \n");
202    dumpMap(tmp1);
203    fprintf(stderr,"/Service internal print \n");
[216]204#endif
[9]205    if(tmp1!=NULL){
206      if(strncmp(tmp1->value,"text/js",7)==0 ||
207         strncmp(tmp1->value,"application/json",7)==0)
208        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
[1]209      else
[9]210        geometry=createGeometryFromGML(conf,tmp->value);
[1]211    }
[9]212    else
213      geometry=createGeometryFromGML(conf,tmp->value);
[35]214    if(geometry==NULL){
[36]215      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
[26]216      return SERVICE_FAILED;
[35]217    }
[9]218    res=(*myFunc)(geometry);
[216]219#ifdef DEBUG
[9]220    fprintf(stderr,"Service internal print \n");
[1]221    dumpMaps(outputs);
[9]222    fprintf(stderr,"/Service internal print \n");
[216]223#endif
[9]224    map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
[216]225#ifdef DEBUG
[9]226    fprintf(stderr,"Service internal print \n");
227    dumpMap(tmp_2);
228    fprintf(stderr,"/Service internal print \n");
[216]229#endif
[9]230    if(tmp_2!=NULL){
231      if(strncmp(tmp_2->value,"text/js",7)==0 ||
232         strncmp(tmp_2->value,"application/json",16)==0){
[26]233        char *tmpS=OGR_G_ExportToJson(res);
234        setMapInMaps(outputs,"Result","value",tmpS);
[216]235#ifndef WIN32
[26]236        setMapInMaps(outputs,"Result","mimeType","text/plain");
237        setMapInMaps(outputs,"Result","encoding","UTF-8");
238        free(tmpS);
[216]239#endif
[1]240      }
[9]241      else{
[26]242        char *tmpS=OGR_G_ExportToGML(res);
243        setMapInMaps(outputs,"Result","value",tmpS);
[216]244#ifndef WIN32
[54]245        setMapInMaps(outputs,"Result","mimeType","text/xml");
[26]246        setMapInMaps(outputs,"Result","encoding","UTF-8");
[54]247        setMapInMaps(outputs,"Result","schema",schema);
[26]248        free(tmpS);
[216]249#endif
[1]250      }
[9]251    }else{
[26]252      char *tmpS=OGR_G_ExportToJson(res);
253      setMapInMaps(outputs,"Result","value",tmpS);
[216]254#ifndef WIN32
[26]255      setMapInMaps(outputs,"Result","mimeType","text/plain");
256      setMapInMaps(outputs,"Result","encoding","UTF-8");
257      free(tmpS);
[216]258#endif
[1]259    }
[216]260    //outputs->next=NULL;
[1]261#ifdef DEBUG
262    dumpMaps(outputs);
263    fprintf(stderr,"\nService internal print\n===\n");
264#endif
[9]265    OGR_G_DestroyGeometry(res);
266    OGR_G_DestroyGeometry(geometry);
267    //CPLFree(res);
268    //CPLFree(geometry);
[216]269#ifdef DEBUG
[9]270    fprintf(stderr,"Service internal print \n");
271    dumpMaps(outputs);
272    fprintf(stderr,"/Service internal print \n");
[216]273#endif
[1]274    return SERVICE_SUCCEEDED;
275  }
276
277#ifdef WIN32
278  __declspec(dllexport)
279#endif
[9]280int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
281   OGRGeometryH geometry,res;
282   map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
[32]283   if(tmp==NULL){
[36]284     setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
[9]285     return SERVICE_FAILED;
[32]286   }else
287     if(strlen(tmp->value)<=0){
[36]288       setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
[32]289       return SERVICE_FAILED;
290     }
[9]291   map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
292   if(strncmp(tmp1->value,"application/json",16)==0)
293     geometry=OGR_G_CreateGeometryFromJson(tmp->value);
294   else
295     geometry=createGeometryFromGML(conf,tmp->value);
[26]296   if(geometry==NULL){
[36]297     setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry"));
[26]298     return SERVICE_FAILED;
299   }
300   double bufferDistance;
[9]301   tmp=getMapFromMaps(inputs,"BufferDistance","value");
[26]302   if(tmp==NULL){
303     bufferDistance=atof("10.0");
304   }
305   else
306     bufferDistance=atof(tmp->value);
[9]307   res=OGR_G_Buffer(geometry,bufferDistance,30);
[216]308   dumpMap(tmp);
[9]309   tmp1=getMapFromMaps(outputs,"Result","mimeType");
[216]310   dumpMap(tmp);
[9]311   if(strncmp(tmp1->value,"application/json",16)==0){
[26]312     char *tmpS=OGR_G_ExportToJson(res);
313     setMapInMaps(outputs,"Result","value",tmpS);
[216]314     dumpMap(tmp);
315#ifndef WIN32
[26]316     setMapInMaps(outputs,"Result","mimeType","text/plain");
317     setMapInMaps(outputs,"Result","encoding","UTF-8");
318     free(tmpS);
[216]319#endif
[9]320   }
321   else{
[26]322     char *tmpS=OGR_G_ExportToGML(res);
323     setMapInMaps(outputs,"Result","value",tmpS);
[216]324     dumpMap(tmp);
325#ifndef WIN32
[35]326     free(tmpS);
[26]327     setMapInMaps(outputs,"Result","mimeType","text/xml");
328     setMapInMaps(outputs,"Result","encoding","UTF-8");
329     setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
[216]330#endif
[9]331   }
[216]332   //outputs->next=NULL;
[9]333   OGR_G_DestroyGeometry(geometry);
334   OGR_G_DestroyGeometry(res);
335   return SERVICE_SUCCEEDED;
336}
337
[1]338#ifdef WIN32
339  __declspec(dllexport)
340#endif
[9]341  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
[54]342    return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary,"http://fooa/gml/3.1.0/polygon.xsd");
[9]343  }
344
345#ifdef WIN32
346  __declspec(dllexport)
347#endif
348  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
[54]349    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull,"http://fooa/gml/3.1.0/polygon.xsd");
[9]350  }
351
352
353  OGRGeometryH MY_OGR_G_Centroid(OGRGeometryH hTarget){
354    OGRGeometryH res;
355    res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
356    OGRwkbGeometryType gtype=OGR_G_GetGeometryType(hTarget);
357    if(gtype!=wkbPolygon){
358      hTarget=OGR_G_ConvexHull(hTarget);
359    }
360    int c=OGR_G_Centroid(hTarget,res);
361    return res;
362  }
363
364#ifdef WIN32
365  __declspec(dllexport)
366#endif
367  int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
[54]368    return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid,"http://fooa/gml/3.1.0/point.xsd");
[9]369  }
370
371  int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH,OGRGeometryH)){
[1]372#ifdef DEBUG
373    fprintf(stderr,"\nService internal print1\n");
[26]374    fflush(stderr);
375    fprintf(stderr,"\nService internal print1\n");
376    dumpMaps(inputs);
377    fprintf(stderr,"\nService internal print1\n");
[216]378#endif
[9]379
[1]380    maps* cursor=inputs;
381    OGRGeometryH geometry1,geometry2;
382    OGRGeometryH res;
383    {
384      map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
385      map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType");
386      if(tmp1!=NULL){
387        if(strncmp(tmp1->value,"application/json",16)==0)
388          geometry1=OGR_G_CreateGeometryFromJson(tmp->value);
389        else
390          geometry1=createGeometryFromGML(conf,tmp->value);
391      }
392      else
393        geometry1=createGeometryFromGML(conf,tmp->value);
394    }
[26]395    if(geometry1==NULL){
[36]396      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
[216]397#ifdef DEBUG
[26]398      fprintf(stderr,"SERVICE FAILED !\n");
[216]399#endif
[26]400      return SERVICE_FAILED;
401    }
[216]402#ifdef DEBUG
[26]403    fprintf(stderr,"\nService internal print1 InputEntity1\n");
[216]404#endif
[1]405    {
406      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
407      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
[216]408#ifdef DEBUG
[26]409      fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16));
410      //dumpMap(tmp);
[1]411      fprintf(stderr,"MY MAP\n");
[26]412      fprintf(stderr,"\nService internal print1 InputEntity2\n");
[216]413#endif
[1]414      if(tmp1!=NULL){
[26]415        if(strncmp(tmp1->value,"application/json",16)==0){
[216]416#ifdef DEBUG
[26]417          fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n");
[216]418#endif
[1]419          geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
[26]420        }
421        else{
[216]422#ifdef DEBUG
[26]423          fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n");
[216]424#endif
[1]425          geometry2=createGeometryFromGML(conf,tmp->value);
[26]426        }
[1]427      }
428      else
429        geometry2=createGeometryFromGML(conf,tmp->value);
[216]430#ifdef DEBUG
[26]431      fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n");
[216]432#endif
[1]433    }
[216]434#ifdef DEBUG
[26]435    fprintf(stderr,"\nService internal print1 InputEntity2 Final\n");
[216]436#endif
[26]437    if(geometry2==NULL){
[36]438      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
[216]439#ifdef DEBUG
[26]440      fprintf(stderr,"SERVICE FAILED !\n");
[216]441#endif
[26]442      return SERVICE_FAILED;
443    }
[216]444#ifdef DEBUG
[26]445    fprintf(stderr,"\nService internal print1\n");
[216]446#endif
[9]447    res=(*myFunc)(geometry1,geometry2);
[216]448#ifdef DEBUG
[26]449    fprintf(stderr,"\nService internal print1\n");
[216]450#endif   
[55]451    /* nuova parte */
452    map* tmp2=getMapFromMaps(outputs,"Result","mimeType");
453    if(strncmp(tmp2->value,"application/json",16)==0){
454      char *tmpS=OGR_G_ExportToJson(res);
455      setMapInMaps(outputs,"Result","value",tmpS);
[216]456#ifndef WIN32
[55]457      setMapInMaps(outputs,"Result","mimeType","text/plain");
458      setMapInMaps(outputs,"Result","encoding","UTF-8");
459      free(tmpS);
[216]460#endif
[55]461    }
462    else{
463      char *tmpS=OGR_G_ExportToGML(res);
464      setMapInMaps(outputs,"Result","value",tmpS);
[216]465#ifndef WIN32
[55]466      setMapInMaps(outputs,"Result","mimeType","text/xml");
467      setMapInMaps(outputs,"Result","encoding","UTF-8");
468      setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
469      free(tmpS);
[216]470#endif
[55]471    }
472   
473    /* vecchia da togliere */
474    /*
[26]475    char *tmpS=OGR_G_ExportToJson(res);
476    setMapInMaps(outputs,"Result","value",tmpS);
477    setMapInMaps(outputs,"Result","mimeType","text/plain");
478    setMapInMaps(outputs,"Result","encoding","UTF-8");
479    free(tmpS);
[55]480    */
[9]481    OGR_G_DestroyGeometry(geometry1);
482    OGR_G_DestroyGeometry(geometry2);
483    OGR_G_DestroyGeometry(res);
[1]484    return SERVICE_SUCCEEDED;
485  }
[9]486 
487#ifdef WIN32
488  __declspec(dllexport)
489#endif
490  int Difference(maps*& conf,maps*& inputs,maps*& outputs){
491    return applyTwo(conf,inputs,outputs,&OGR_G_Difference);
492  }
[1]493
494#ifdef WIN32
495  __declspec(dllexport)
496#endif
[9]497  int SymDifference(maps*& conf,maps*& inputs,maps*& outputs){
498    return applyTwo(conf,inputs,outputs,&OGR_G_SymmetricDifference);
499  }
500
501#ifdef WIN32
502  __declspec(dllexport)
503#endif
504  int Intersection(maps*& conf,maps*& inputs,maps*& outputs){
505    return applyTwo(conf,inputs,outputs,&OGR_G_Intersection);
506  }
507
508#ifdef WIN32
509  __declspec(dllexport)
510#endif
511  int Union(maps*& conf,maps*& inputs,maps*& outputs){
512    return applyTwo(conf,inputs,outputs,&OGR_G_Union);
513  }
514
515#ifdef WIN32
516  __declspec(dllexport)
517#endif
[1]518  int Distance(maps*& conf,maps*& inputs,maps*& outputs){
519#ifdef DEBUG
520    fprintf(stderr,"\nService internal print1\n");
521#endif
522    fflush(stderr);
523    maps* cursor=inputs;
524    OGRGeometryH geometry1,geometry2;
525    double res;
526    {
527      map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
528      map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType");
529#ifdef DEBUG
530      fprintf(stderr,"MY MAP\n");
531      dumpMap(tmp1);
532      dumpMaps(inputs);
533      fprintf(stderr,"MY MAP\n");
534#endif
535      if(tmp1!=NULL){
536        if(strncmp(tmp1->value,"application/json",16)==0)
537          geometry1=OGR_G_CreateGeometryFromJson(tmp->value);
538        else
539          geometry1=createGeometryFromGML(conf,tmp->value);
540      }
541      else
542        geometry1=createGeometryFromGML(conf,tmp->value);
543    }
[26]544    if(geometry1==NULL){
[36]545      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
[26]546      fprintf(stderr,"SERVICE FAILED !\n");
547      return SERVICE_FAILED;
548    }
[1]549    {
550      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
551      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
552#ifdef DEBUG
553      fprintf(stderr,"MY MAP\n");
554      dumpMap(tmp1);
555      dumpMaps(inputs);
556      fprintf(stderr,"MY MAP\n");
557#endif
558      if(tmp1!=NULL){
559        if(strncmp(tmp1->value,"application/json",16)==0)
560          geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
561        else
562          geometry2=createGeometryFromGML(conf,tmp->value);
563      }
564      else
565        geometry2=createGeometryFromGML(conf,tmp->value);
566    }
[26]567    if(geometry2==NULL){
[36]568      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
[26]569      fprintf(stderr,"SERVICE FAILED !\n");
570      return SERVICE_FAILED;
571    }
572    res=OGR_G_Distance(geometry1,geometry2);   
[1]573    char tmpres[100];
[55]574    sprintf(tmpres,"%f",res);
[26]575    setMapInMaps(outputs,"Distance","value",tmpres);
576    setMapInMaps(outputs,"Distance","dataType","float");
[1]577#ifdef DEBUG
578    dumpMaps(outputs);
579    fprintf(stderr,"\nService internal print\n===\n");
580#endif
581    return SERVICE_SUCCEEDED;
582  }
583
[9]584#ifdef WIN32
585  __declspec(dllexport)
586#endif
[1]587  int GetArea(maps*& conf,maps*& inputs,maps*& outputs){
588    fprintf(stderr,"GETAREA \n");
589    double res;
590    /**
[26]591     * Extract Geometry from the InputPolygon value
[1]592     */
[26]593    OGRGeometryH geometry;
594    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
595    if(tmp==NULL){
[36]596      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon"));
[26]597      return SERVICE_FAILED;
598    }
[1]599    fprintf(stderr,"geometry creation %s \n",tmp->value);
[26]600    geometry=createGeometryFromGML(conf,tmp->value);
601    if(geometry==NULL){
[36]602      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon"));
[26]603      return SERVICE_FAILED;
604    }
[1]605    fprintf(stderr,"geometry created %s \n",tmp->value);
[26]606    res=OGR_G_GetArea(geometry);
[1]607    fprintf(stderr,"area %d \n",res);
608    /**
[26]609     * Filling the outputs
[1]610     */
611    char tmp1[100];
[55]612    sprintf(tmp1,"%f",res);
[26]613    setMapInMaps(outputs,"Area","value",tmp1);
614    setMapInMaps(outputs,"Area","dataType","float");
[1]615#ifdef DEBUG
616    dumpMaps(outputs);
617#endif
618    return SERVICE_SUCCEEDED;
619  }
620
621}
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png