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

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

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

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
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      setMapInMaps(conf,"lenv","message",_ss("Unable to parse Input Polygon"));
59      setMapInMaps(conf,"lenv","code","InvalidParameterValue");
60      return NULL;
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);
74    char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char));
75    sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2);
76    xmlXPathFreeObject(xpathObj);
77    xmlXPathFreeContext(xpathCtx);
78    xmlFree(xmlbuff);
79    xmlFreeDoc(doc);
80    xmlFreeDoc(ndoc);
81#ifndef WIN32
82    xmlCleanupParser();
83#endif
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);
88    free(tmp);
89    if(res==NULL){
90      setMapInMaps(conf,"lenv","message",_ss("Unable to call OGR_G_CreatFromGML"));
91      return NULL;
92    }
93    else
94      return res;
95  }
96
97#ifdef WIN32
98  __declspec(dllexport)
99#endif
100  int Simplify(maps*& conf,maps*& inputs,maps*& outputs){
101    maps* cursor=inputs;
102    OGRGeometryH geometry,res;
103    double tolerance;
104    map* tmp0=getMapFromMaps(cursor,"Tolerance","value");
105    if(tmp0==NULL){
106      tolerance=atof("2.0");
107    }
108    else
109      tolerance=atof(tmp0->value);
110#ifdef DEBUG
111    fprintf(stderr,"Tolerance for Simplify %f",tolerance);
112#endif
113    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
114    if(!tmp){
115      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
116      return SERVICE_FAILED;
117    }
118    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
119    if(tmp1!=NULL){
120      if(strncmp(tmp1->value,"text/js",7)==0 ||
121         strncmp(tmp1->value,"application/json",16)==0)
122        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
123      else
124        geometry=createGeometryFromGML(conf,tmp->value);
125    }
126    else{
127      setMapInMaps(conf,"lenv","message",_ss("Unable to find any geometry for InputPolygon"));
128      return SERVICE_FAILED;
129    }
130    if(geometry==NULL){
131      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
132      return SERVICE_FAILED;
133    }
134#ifdef DEBUG
135    fprintf(stderr,"Create GEOSGeometry object");
136#endif
137    GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS();
138    GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance);
139    res=(OGRGeometryH)OGRGeometryFactory::createFromGEOS(gres);
140    tmp1=getMapFromMaps(outputs,"Result","mimeType");
141    if(tmp1!=NULL){
142      if(strncmp(tmp1->value,"text/js",7)==0 ||
143         strncmp(tmp1->value,"application/json",16)==0){
144        char *tmpS=OGR_G_ExportToJson(res);
145        setMapInMaps(outputs,"Result","value",tmpS);
146#ifndef WIN32
147        setMapInMaps(outputs,"Result","mimeType","text/plain");
148        setMapInMaps(outputs,"Result","encoding","UTF-8");
149        free(tmpS);
150#endif
151      }
152      else{
153        char *tmpS=OGR_G_ExportToGML(res);
154        setMapInMaps(outputs,"Result","value",tmpS);
155#ifndef WIN32
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);
160#endif
161      }
162    }else{
163      char *tmpS=OGR_G_ExportToJson(res);
164      setMapInMaps(outputs,"Result","value",tmpS);
165#ifndef WIN32
166      setMapInMaps(outputs,"Result","mimeType","text/plain");
167      setMapInMaps(outputs,"Result","encoding","UTF-8");
168      free(tmpS);
169#endif
170    }
171    outputs->next=NULL;
172    //GEOSFree(ggeometry);
173    //GEOSFree(gres);
174    OGR_G_DestroyGeometry(res);
175    OGR_G_DestroyGeometry(geometry);
176    return SERVICE_SUCCEEDED;
177  }
178
179
180  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH),char* schema){
181#ifdef DEBUG
182    fprintf(stderr,"\nService internal print\n");
183#endif
184    maps* cursor=inputs;
185    OGRGeometryH geometry,res;
186#ifdef DEBUG
187    dumpMaps(cursor);
188#endif
189    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
190    if(!tmp){
191      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
192      return SERVICE_FAILED;
193    }
194#ifdef DEBUG
195    fprintf(stderr,"Service internal print \n");
196    dumpMaps(inputs);
197    fprintf(stderr,"/Service internal print \n");
198#endif
199    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
200#ifdef DEBUG
201    fprintf(stderr,"Service internal print \n");
202    dumpMap(tmp1);
203    fprintf(stderr,"/Service internal print \n");
204#endif
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);
209      else
210        geometry=createGeometryFromGML(conf,tmp->value);
211    }
212    else
213      geometry=createGeometryFromGML(conf,tmp->value);
214    if(geometry==NULL){
215      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
216      return SERVICE_FAILED;
217    }
218    res=(*myFunc)(geometry);
219#ifdef DEBUG
220    fprintf(stderr,"Service internal print \n");
221    dumpMaps(outputs);
222    fprintf(stderr,"/Service internal print \n");
223#endif
224    map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
225#ifdef DEBUG
226    fprintf(stderr,"Service internal print \n");
227    dumpMap(tmp_2);
228    fprintf(stderr,"/Service internal print \n");
229#endif
230    if(tmp_2!=NULL){
231      if(strncmp(tmp_2->value,"text/js",7)==0 ||
232         strncmp(tmp_2->value,"application/json",16)==0){
233        char *tmpS=OGR_G_ExportToJson(res);
234        setMapInMaps(outputs,"Result","value",tmpS);
235#ifndef WIN32
236        setMapInMaps(outputs,"Result","mimeType","text/plain");
237        setMapInMaps(outputs,"Result","encoding","UTF-8");
238        free(tmpS);
239#endif
240      }
241      else{
242        char *tmpS=OGR_G_ExportToGML(res);
243        setMapInMaps(outputs,"Result","value",tmpS);
244#ifndef WIN32
245        setMapInMaps(outputs,"Result","mimeType","text/xml");
246        setMapInMaps(outputs,"Result","encoding","UTF-8");
247        setMapInMaps(outputs,"Result","schema",schema);
248        free(tmpS);
249#endif
250      }
251    }else{
252      char *tmpS=OGR_G_ExportToJson(res);
253      setMapInMaps(outputs,"Result","value",tmpS);
254#ifndef WIN32
255      setMapInMaps(outputs,"Result","mimeType","text/plain");
256      setMapInMaps(outputs,"Result","encoding","UTF-8");
257      free(tmpS);
258#endif
259    }
260    //outputs->next=NULL;
261#ifdef DEBUG
262    dumpMaps(outputs);
263    fprintf(stderr,"\nService internal print\n===\n");
264#endif
265    OGR_G_DestroyGeometry(res);
266    OGR_G_DestroyGeometry(geometry);
267    //CPLFree(res);
268    //CPLFree(geometry);
269#ifdef DEBUG
270    fprintf(stderr,"Service internal print \n");
271    dumpMaps(outputs);
272    fprintf(stderr,"/Service internal print \n");
273#endif
274    return SERVICE_SUCCEEDED;
275  }
276
277#ifdef WIN32
278  __declspec(dllexport)
279#endif
280int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
281   OGRGeometryH geometry,res;
282   map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
283   if(tmp==NULL){
284     setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
285     return SERVICE_FAILED;
286   }else
287     if(strlen(tmp->value)<=0){
288       setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
289       return SERVICE_FAILED;
290     }
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);
296   if(geometry==NULL){
297     setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry"));
298     return SERVICE_FAILED;
299   }
300   double bufferDistance;
301   tmp=getMapFromMaps(inputs,"BufferDistance","value");
302   if(tmp==NULL){
303     bufferDistance=atof("10.0");
304   }
305   else
306     bufferDistance=atof(tmp->value);
307   res=OGR_G_Buffer(geometry,bufferDistance,30);
308   dumpMap(tmp);
309   tmp1=getMapFromMaps(outputs,"Result","mimeType");
310   dumpMap(tmp);
311   if(strncmp(tmp1->value,"application/json",16)==0){
312     char *tmpS=OGR_G_ExportToJson(res);
313     setMapInMaps(outputs,"Result","value",tmpS);
314     dumpMap(tmp);
315#ifndef WIN32
316     setMapInMaps(outputs,"Result","mimeType","text/plain");
317     setMapInMaps(outputs,"Result","encoding","UTF-8");
318     free(tmpS);
319#endif
320   }
321   else{
322     char *tmpS=OGR_G_ExportToGML(res);
323     setMapInMaps(outputs,"Result","value",tmpS);
324     dumpMap(tmp);
325#ifndef WIN32
326     free(tmpS);
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");
330#endif
331   }
332   //outputs->next=NULL;
333   OGR_G_DestroyGeometry(geometry);
334   OGR_G_DestroyGeometry(res);
335   return SERVICE_SUCCEEDED;
336}
337
338#ifdef WIN32
339  __declspec(dllexport)
340#endif
341  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
342    return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary,"http://fooa/gml/3.1.0/polygon.xsd");
343  }
344
345#ifdef WIN32
346  __declspec(dllexport)
347#endif
348  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
349    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull,"http://fooa/gml/3.1.0/polygon.xsd");
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){
368    return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid,"http://fooa/gml/3.1.0/point.xsd");
369  }
370
371  int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH,OGRGeometryH)){
372#ifdef DEBUG
373    fprintf(stderr,"\nService internal print1\n");
374    fflush(stderr);
375    fprintf(stderr,"\nService internal print1\n");
376    dumpMaps(inputs);
377    fprintf(stderr,"\nService internal print1\n");
378#endif
379
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    }
395    if(geometry1==NULL){
396      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
397#ifdef DEBUG
398      fprintf(stderr,"SERVICE FAILED !\n");
399#endif
400      return SERVICE_FAILED;
401    }
402#ifdef DEBUG
403    fprintf(stderr,"\nService internal print1 InputEntity1\n");
404#endif
405    {
406      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
407      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
408#ifdef DEBUG
409      fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16));
410      //dumpMap(tmp);
411      fprintf(stderr,"MY MAP\n");
412      fprintf(stderr,"\nService internal print1 InputEntity2\n");
413#endif
414      if(tmp1!=NULL){
415        if(strncmp(tmp1->value,"application/json",16)==0){
416#ifdef DEBUG
417          fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n");
418#endif
419          geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
420        }
421        else{
422#ifdef DEBUG
423          fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n");
424#endif
425          geometry2=createGeometryFromGML(conf,tmp->value);
426        }
427      }
428      else
429        geometry2=createGeometryFromGML(conf,tmp->value);
430#ifdef DEBUG
431      fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n");
432#endif
433    }
434#ifdef DEBUG
435    fprintf(stderr,"\nService internal print1 InputEntity2 Final\n");
436#endif
437    if(geometry2==NULL){
438      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
439#ifdef DEBUG
440      fprintf(stderr,"SERVICE FAILED !\n");
441#endif
442      return SERVICE_FAILED;
443    }
444#ifdef DEBUG
445    fprintf(stderr,"\nService internal print1\n");
446#endif
447    res=(*myFunc)(geometry1,geometry2);
448#ifdef DEBUG
449    fprintf(stderr,"\nService internal print1\n");
450#endif   
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);
456#ifndef WIN32
457      setMapInMaps(outputs,"Result","mimeType","text/plain");
458      setMapInMaps(outputs,"Result","encoding","UTF-8");
459      free(tmpS);
460#endif
461    }
462    else{
463      char *tmpS=OGR_G_ExportToGML(res);
464      setMapInMaps(outputs,"Result","value",tmpS);
465#ifndef WIN32
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);
470#endif
471    }
472   
473    /* vecchia da togliere */
474    /*
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);
480    */
481    OGR_G_DestroyGeometry(geometry1);
482    OGR_G_DestroyGeometry(geometry2);
483    OGR_G_DestroyGeometry(res);
484    return SERVICE_SUCCEEDED;
485  }
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  }
493
494#ifdef WIN32
495  __declspec(dllexport)
496#endif
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
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    }
544    if(geometry1==NULL){
545      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
546      fprintf(stderr,"SERVICE FAILED !\n");
547      return SERVICE_FAILED;
548    }
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    }
567    if(geometry2==NULL){
568      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
569      fprintf(stderr,"SERVICE FAILED !\n");
570      return SERVICE_FAILED;
571    }
572    res=OGR_G_Distance(geometry1,geometry2);   
573    char tmpres[100];
574    sprintf(tmpres,"%f",res);
575    setMapInMaps(outputs,"Distance","value",tmpres);
576    setMapInMaps(outputs,"Distance","dataType","float");
577#ifdef DEBUG
578    dumpMaps(outputs);
579    fprintf(stderr,"\nService internal print\n===\n");
580#endif
581    return SERVICE_SUCCEEDED;
582  }
583
584#ifdef WIN32
585  __declspec(dllexport)
586#endif
587  int GetArea(maps*& conf,maps*& inputs,maps*& outputs){
588    fprintf(stderr,"GETAREA \n");
589    double res;
590    /**
591     * Extract Geometry from the InputPolygon value
592     */
593    OGRGeometryH geometry;
594    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
595    if(tmp==NULL){
596      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon"));
597      return SERVICE_FAILED;
598    }
599    fprintf(stderr,"geometry creation %s \n",tmp->value);
600    geometry=createGeometryFromGML(conf,tmp->value);
601    if(geometry==NULL){
602      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon"));
603      return SERVICE_FAILED;
604    }
605    fprintf(stderr,"geometry created %s \n",tmp->value);
606    res=OGR_G_GetArea(geometry);
607    fprintf(stderr,"area %d \n",res);
608    /**
609     * Filling the outputs
610     */
611    char tmp1[100];
612    sprintf(tmp1,"%f",res);
613    setMapInMaps(outputs,"Area","value",tmp1);
614    setMapInMaps(outputs,"Area","dataType","float");
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