source: branches/branch-1.2/zoo-services/ogr/base-vect-ops/service.c @ 469

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

Merge branch-1.2 r268:r296.

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

Search

Context Navigation

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