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

Last change on this file since 103 was 55, checked in by nmarco, 14 years ago

fixed error in GetArea? and Distance functions: wrong data type. Added the output in GML format in the ApplayTwo? function. Distance.zcfg: translated from French to English

File size: 18.6 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*);
45  char *base64(const unsigned char *input, int length);
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){
58      map* tmp=createMap("text","Unable to parse Input Polygon");
59      addToMap(tmp,"code","InvalidParameterValue");
60      printExceptionReportResponse(conf,tmp);
61      exit(0);
62    }
63    int size = (xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0;
64    /**
65     * Create a temporary XML document
66     */
67    xmlDocPtr ndoc = xmlNewDoc(BAD_CAST "1.0");
68    /**
69     * Only one polygon should be provided so we use it as the root node.
70     */
71    for(int k=size-1;k>=0;k--){ 
72      xmlDocSetRootElement(ndoc, xpathObj->nodesetval->nodeTab[k]);
73    }
74    xmlDocDumpFormatMemory(ndoc, &xmlbuff, &buffersize, 1);
[9]75    char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char));
76    sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2);
[1]77    xmlXPathFreeObject(xpathObj);
[9]78    xmlXPathFreeContext(xpathCtx);
[1]79    xmlFree(xmlbuff);
80    xmlFreeDoc(doc);
[9]81    xmlFreeDoc(ndoc);
[1]82    xmlCleanupParser();
83#ifdef DEBUG
84    fprintf(stderr,"\nService internal print\n Loading the geometry from GML string ...");
85#endif
86    OGRGeometryH res=OGR_G_CreateFromGML(tmp);
[9]87    free(tmp);
[1]88    if(res==NULL){
[36]89      setMapInMaps(conf,"lenv","message",_ss("Unable to call OGR_G_CreatFromGML"));
[26]90      return NULL;
[1]91    }
92    else
[26]93      return res;
[1]94  }
95
[9]96  int Simplify(maps*& conf,maps*& inputs,maps*& outputs){
[1]97    maps* cursor=inputs;
[9]98    OGRGeometryH geometry,res;
99    double tolerance;
100    map* tmp0=getMapFromMaps(cursor,"Tolerance","value");
101    if(tmp0==NULL){
102      tolerance=atof("2.0");
[1]103    }
[9]104    else
105      tolerance=atof(tmp0->value);
106    fprintf(stderr,"Tolerance for Simplify %f",tolerance);
[1]107    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
[26]108    if(!tmp){
[36]109      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
[1]110      return SERVICE_FAILED;
[26]111    }
112    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
[1]113    if(tmp1!=NULL){
[9]114      if(strncmp(tmp1->value,"text/js",7)==0 ||
[26]115         strncmp(tmp1->value,"application/json",16)==0)
[1]116        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
117      else
118        geometry=createGeometryFromGML(conf,tmp->value);
[9]119    }
[26]120    else{
[36]121      setMapInMaps(conf,"lenv","message",_ss("Unable to find any geometry for InputPolygon"));
[26]122      return SERVICE_FAILED;
123    }
124    if(geometry==NULL){
[36]125      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
[26]126      return SERVICE_FAILED;
127    }
128    fprintf(stderr,"Create GEOSGeometry object");
[9]129    GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS();
130    GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance);
131    res=OGRGeometryFactory::createFromGEOS(gres);
[26]132    tmp1=getMapFromMaps(outputs,"Result","mimeType");
[1]133    if(tmp1!=NULL){
[9]134      if(strncmp(tmp1->value,"text/js",7)==0 ||
135         strncmp(tmp1->value,"application/json",16)==0){
[26]136        char *tmpS=OGR_G_ExportToJson(res);
137        setMapInMaps(outputs,"Result","value",tmpS);
138        setMapInMaps(outputs,"Result","mimeType","text/plain");
139        setMapInMaps(outputs,"Result","encoding","UTF-8");
140        free(tmpS);
[1]141      }
142      else{
[26]143        char *tmpS=OGR_G_ExportToGML(res);
144        setMapInMaps(outputs,"Result","value",tmpS);
145        setMapInMaps(outputs,"Result","mimeType","text/xml");
146        setMapInMaps(outputs,"Result","encoding","UTF-8");
147        setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
148        free(tmpS);
[1]149      }
150    }else{
[26]151      char *tmpS=OGR_G_ExportToJson(tmp->value);
152      setMapInMaps(outputs,"Result","value",tmpS);
153      setMapInMaps(outputs,"Result","mimeType","text/plain");
154      setMapInMaps(outputs,"Result","encoding","UTF-8");
155      free(tmpS);
[1]156    }
157    outputs->next=NULL;
[9]158    //GEOSFree(ggeometry);
159    //GEOSFree(gres);
160    OGR_G_DestroyGeometry(res);
161    OGR_G_DestroyGeometry(geometry);
[1]162    return SERVICE_SUCCEEDED;
163  }
164
165
[54]166  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH),char* schema){
[1]167#ifdef DEBUG
[9]168    fprintf(stderr,"\nService internal print\n");
[1]169#endif
170    maps* cursor=inputs;
171    OGRGeometryH geometry,res;
172#ifdef DEBUG
[9]173    dumpMaps(cursor);
[1]174#endif
[9]175    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
[35]176    if(!tmp){
[36]177      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
[9]178      return SERVICE_FAILED;
[35]179    }
[9]180    fprintf(stderr,"Service internal print \n");
181    dumpMaps(inputs);
182    fprintf(stderr,"/Service internal print \n");
183    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
184    fprintf(stderr,"Service internal print \n");
185    dumpMap(tmp1);
186    fprintf(stderr,"/Service internal print \n");
187    if(tmp1!=NULL){
188      if(strncmp(tmp1->value,"text/js",7)==0 ||
189         strncmp(tmp1->value,"application/json",7)==0)
190        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
[1]191      else
[9]192        geometry=createGeometryFromGML(conf,tmp->value);
[1]193    }
[9]194    else
195      geometry=createGeometryFromGML(conf,tmp->value);
[35]196    if(geometry==NULL){
[36]197      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
[26]198      return SERVICE_FAILED;
[35]199    }
[9]200    res=(*myFunc)(geometry);
201    fprintf(stderr,"Service internal print \n");
[1]202    dumpMaps(outputs);
[9]203    fprintf(stderr,"/Service internal print \n");
204    map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
205    fprintf(stderr,"Service internal print \n");
206    dumpMap(tmp_2);
207    fprintf(stderr,"/Service internal print \n");
208    if(tmp_2!=NULL){
209      if(strncmp(tmp_2->value,"text/js",7)==0 ||
210         strncmp(tmp_2->value,"application/json",16)==0){
[26]211        char *tmpS=OGR_G_ExportToJson(res);
212        setMapInMaps(outputs,"Result","value",tmpS);
213        setMapInMaps(outputs,"Result","mimeType","text/plain");
214        setMapInMaps(outputs,"Result","encoding","UTF-8");
215        free(tmpS);
[1]216      }
[9]217      else{
[26]218        char *tmpS=OGR_G_ExportToGML(res);
219        setMapInMaps(outputs,"Result","value",tmpS);
[54]220        setMapInMaps(outputs,"Result","mimeType","text/xml");
[26]221        setMapInMaps(outputs,"Result","encoding","UTF-8");
[54]222        setMapInMaps(outputs,"Result","schema",schema);
[26]223        free(tmpS);
[1]224      }
[9]225    }else{
[26]226      char *tmpS=OGR_G_ExportToJson(res);
227      setMapInMaps(outputs,"Result","value",tmpS);
228      setMapInMaps(outputs,"Result","mimeType","text/plain");
229      setMapInMaps(outputs,"Result","encoding","UTF-8");
230      free(tmpS);
[1]231    }
232    outputs->next=NULL;
233#ifdef DEBUG
234    dumpMaps(outputs);
235    fprintf(stderr,"\nService internal print\n===\n");
236#endif
[9]237    OGR_G_DestroyGeometry(res);
238    OGR_G_DestroyGeometry(geometry);
239    //CPLFree(res);
240    //CPLFree(geometry);
241    fprintf(stderr,"Service internal print \n");
242    dumpMaps(outputs);
243    fprintf(stderr,"/Service internal print \n");
[1]244    return SERVICE_SUCCEEDED;
245  }
246
247#ifdef WIN32
248  __declspec(dllexport)
249#endif
[9]250int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
251   OGRGeometryH geometry,res;
252   map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
[32]253   if(tmp==NULL){
[36]254     setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
[9]255     return SERVICE_FAILED;
[32]256   }else
257     if(strlen(tmp->value)<=0){
[36]258       setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
[32]259       return SERVICE_FAILED;
260     }
[9]261   map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
262   if(strncmp(tmp1->value,"application/json",16)==0)
263     geometry=OGR_G_CreateGeometryFromJson(tmp->value);
264   else
265     geometry=createGeometryFromGML(conf,tmp->value);
[26]266   if(geometry==NULL){
[36]267     setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry"));
[26]268     return SERVICE_FAILED;
269   }
270   double bufferDistance;
[9]271   tmp=getMapFromMaps(inputs,"BufferDistance","value");
[26]272   if(tmp==NULL){
273     bufferDistance=atof("10.0");
274   }
275   else
276     bufferDistance=atof(tmp->value);
[9]277   res=OGR_G_Buffer(geometry,bufferDistance,30);
278   tmp1=getMapFromMaps(outputs,"Result","mimeType");
279   if(strncmp(tmp1->value,"application/json",16)==0){
[26]280     char *tmpS=OGR_G_ExportToJson(res);
281     setMapInMaps(outputs,"Result","value",tmpS);
282     setMapInMaps(outputs,"Result","mimeType","text/plain");
283     setMapInMaps(outputs,"Result","encoding","UTF-8");
284     free(tmpS);
[9]285   }
286   else{
[26]287     char *tmpS=OGR_G_ExportToGML(res);
288     setMapInMaps(outputs,"Result","value",tmpS);
[35]289     free(tmpS);
[26]290     setMapInMaps(outputs,"Result","mimeType","text/xml");
291     setMapInMaps(outputs,"Result","encoding","UTF-8");
292     setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
[9]293   }
294   outputs->next=NULL;
295   OGR_G_DestroyGeometry(geometry);
296   OGR_G_DestroyGeometry(res);
297   return SERVICE_SUCCEEDED;
298}
299
[1]300#ifdef WIN32
301  __declspec(dllexport)
302#endif
[9]303  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
[54]304    return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary,"http://fooa/gml/3.1.0/polygon.xsd");
[9]305  }
306
307#ifdef WIN32
308  __declspec(dllexport)
309#endif
310  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
[54]311    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull,"http://fooa/gml/3.1.0/polygon.xsd");
[9]312  }
313
314
315  OGRGeometryH MY_OGR_G_Centroid(OGRGeometryH hTarget){
316    OGRGeometryH res;
317    res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
318    OGRwkbGeometryType gtype=OGR_G_GetGeometryType(hTarget);
319    if(gtype!=wkbPolygon){
320      hTarget=OGR_G_ConvexHull(hTarget);
321    }
322    int c=OGR_G_Centroid(hTarget,res);
323    return res;
324  }
325
326#ifdef WIN32
327  __declspec(dllexport)
328#endif
329  int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
[54]330    return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid,"http://fooa/gml/3.1.0/point.xsd");
[9]331  }
332
333  int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH,OGRGeometryH)){
[1]334#ifdef DEBUG
335    fprintf(stderr,"\nService internal print1\n");
[26]336    fflush(stderr);
[9]337#endif
[26]338    fprintf(stderr,"\nService internal print1\n");
339    dumpMaps(inputs);
340    fprintf(stderr,"\nService internal print1\n");
[9]341
[1]342    maps* cursor=inputs;
343    OGRGeometryH geometry1,geometry2;
344    OGRGeometryH res;
345    {
346      map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
347      map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType");
348      if(tmp1!=NULL){
349        if(strncmp(tmp1->value,"application/json",16)==0)
350          geometry1=OGR_G_CreateGeometryFromJson(tmp->value);
351        else
352          geometry1=createGeometryFromGML(conf,tmp->value);
353      }
354      else
355        geometry1=createGeometryFromGML(conf,tmp->value);
356    }
[26]357    if(geometry1==NULL){
[36]358      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
[26]359      fprintf(stderr,"SERVICE FAILED !\n");
360      return SERVICE_FAILED;
361    }
362    fprintf(stderr,"\nService internal print1 InputEntity1\n");
[1]363    {
364      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
365      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
[26]366      //#ifdef DEBUG
367      fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16));
368      //dumpMap(tmp);
[1]369      fprintf(stderr,"MY MAP\n");
[26]370      ///#endif
371      fprintf(stderr,"\nService internal print1 InputEntity2\n");
[1]372      if(tmp1!=NULL){
[26]373        if(strncmp(tmp1->value,"application/json",16)==0){
374          fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n");
[1]375          geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
[26]376        }
377        else{
378          fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n");
[1]379          geometry2=createGeometryFromGML(conf,tmp->value);
[26]380        }
[1]381      }
382      else
383        geometry2=createGeometryFromGML(conf,tmp->value);
[26]384      fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n");
[1]385    }
[26]386    fprintf(stderr,"\nService internal print1 InputEntity2 Final\n");
387    if(geometry2==NULL){
[36]388      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
[26]389      fprintf(stderr,"SERVICE FAILED !\n");
390      return SERVICE_FAILED;
391    }
392    fprintf(stderr,"\nService internal print1\n");
[9]393    res=(*myFunc)(geometry1,geometry2);
[26]394    fprintf(stderr,"\nService internal print1\n");
[55]395   
396    /* nuova parte */
397    map* tmp2=getMapFromMaps(outputs,"Result","mimeType");
398    if(strncmp(tmp2->value,"application/json",16)==0){
399      char *tmpS=OGR_G_ExportToJson(res);
400      setMapInMaps(outputs,"Result","value",tmpS);
401      setMapInMaps(outputs,"Result","mimeType","text/plain");
402      setMapInMaps(outputs,"Result","encoding","UTF-8");
403      free(tmpS);
404    }
405    else{
406      char *tmpS=OGR_G_ExportToGML(res);
407      setMapInMaps(outputs,"Result","value",tmpS);
408      setMapInMaps(outputs,"Result","mimeType","text/xml");
409      setMapInMaps(outputs,"Result","encoding","UTF-8");
410      setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
411      free(tmpS);
412    }
413   
414    /* vecchia da togliere */
415    /*
[26]416    char *tmpS=OGR_G_ExportToJson(res);
417    setMapInMaps(outputs,"Result","value",tmpS);
418    setMapInMaps(outputs,"Result","mimeType","text/plain");
419    setMapInMaps(outputs,"Result","encoding","UTF-8");
420    free(tmpS);
[55]421    */
[9]422    OGR_G_DestroyGeometry(geometry1);
423    OGR_G_DestroyGeometry(geometry2);
424    OGR_G_DestroyGeometry(res);
[1]425    return SERVICE_SUCCEEDED;
426  }
[9]427 
428#ifdef WIN32
429  __declspec(dllexport)
430#endif
431  int Difference(maps*& conf,maps*& inputs,maps*& outputs){
432    return applyTwo(conf,inputs,outputs,&OGR_G_Difference);
433  }
[1]434
435#ifdef WIN32
436  __declspec(dllexport)
437#endif
[9]438  int SymDifference(maps*& conf,maps*& inputs,maps*& outputs){
439    return applyTwo(conf,inputs,outputs,&OGR_G_SymmetricDifference);
440  }
441
442#ifdef WIN32
443  __declspec(dllexport)
444#endif
445  int Intersection(maps*& conf,maps*& inputs,maps*& outputs){
446    return applyTwo(conf,inputs,outputs,&OGR_G_Intersection);
447  }
448
449#ifdef WIN32
450  __declspec(dllexport)
451#endif
452  int Union(maps*& conf,maps*& inputs,maps*& outputs){
453    return applyTwo(conf,inputs,outputs,&OGR_G_Union);
454  }
455
456#ifdef WIN32
457  __declspec(dllexport)
458#endif
[1]459  int Distance(maps*& conf,maps*& inputs,maps*& outputs){
460#ifdef DEBUG
461    fprintf(stderr,"\nService internal print1\n");
462#endif
463    fflush(stderr);
464    maps* cursor=inputs;
465    OGRGeometryH geometry1,geometry2;
466    double res;
467    {
468      map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
469      map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType");
470#ifdef DEBUG
471      fprintf(stderr,"MY MAP\n");
472      dumpMap(tmp1);
473      dumpMaps(inputs);
474      fprintf(stderr,"MY MAP\n");
475#endif
476      if(tmp1!=NULL){
477        if(strncmp(tmp1->value,"application/json",16)==0)
478          geometry1=OGR_G_CreateGeometryFromJson(tmp->value);
479        else
480          geometry1=createGeometryFromGML(conf,tmp->value);
481      }
482      else
483        geometry1=createGeometryFromGML(conf,tmp->value);
484    }
[26]485    if(geometry1==NULL){
[36]486      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
[26]487      fprintf(stderr,"SERVICE FAILED !\n");
488      return SERVICE_FAILED;
489    }
[1]490    {
491      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
492      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
493#ifdef DEBUG
494      fprintf(stderr,"MY MAP\n");
495      dumpMap(tmp1);
496      dumpMaps(inputs);
497      fprintf(stderr,"MY MAP\n");
498#endif
499      if(tmp1!=NULL){
500        if(strncmp(tmp1->value,"application/json",16)==0)
501          geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
502        else
503          geometry2=createGeometryFromGML(conf,tmp->value);
504      }
505      else
506        geometry2=createGeometryFromGML(conf,tmp->value);
507    }
[26]508    if(geometry2==NULL){
[36]509      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
[26]510      fprintf(stderr,"SERVICE FAILED !\n");
511      return SERVICE_FAILED;
512    }
513    res=OGR_G_Distance(geometry1,geometry2);   
[1]514    char tmpres[100];
[55]515    sprintf(tmpres,"%f",res);
[26]516    setMapInMaps(outputs,"Distance","value",tmpres);
517    setMapInMaps(outputs,"Distance","dataType","float");
[1]518#ifdef DEBUG
519    dumpMaps(outputs);
520    fprintf(stderr,"\nService internal print\n===\n");
521#endif
522    return SERVICE_SUCCEEDED;
523  }
524
[9]525#ifdef WIN32
526  __declspec(dllexport)
527#endif
[1]528  int GetArea(maps*& conf,maps*& inputs,maps*& outputs){
529    fprintf(stderr,"GETAREA \n");
530    double res;
531    /**
[26]532     * Extract Geometry from the InputPolygon value
[1]533     */
[26]534    OGRGeometryH geometry;
535    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
536    if(tmp==NULL){
[36]537      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon"));
[26]538      return SERVICE_FAILED;
539    }
[1]540    fprintf(stderr,"geometry creation %s \n",tmp->value);
[26]541    geometry=createGeometryFromGML(conf,tmp->value);
542    if(geometry==NULL){
[36]543      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon"));
[26]544      return SERVICE_FAILED;
545    }
[1]546    fprintf(stderr,"geometry created %s \n",tmp->value);
[26]547    res=OGR_G_GetArea(geometry);
[1]548    fprintf(stderr,"area %d \n",res);
549    /**
[26]550     * Filling the outputs
[1]551     */
552    char tmp1[100];
[55]553    sprintf(tmp1,"%f",res);
[26]554    setMapInMaps(outputs,"Area","value",tmp1);
555    setMapInMaps(outputs,"Area","dataType","float");
[1]556#ifdef DEBUG
557    dumpMaps(outputs);
558#endif
559    return SERVICE_SUCCEEDED;
560  }
561
562}
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