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

Last change on this file since 1 was 1, checked in by djay, 10 years ago

Initial ZOO SVN Repository Import.

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