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 | |
---|
32 | extern "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); |
---|
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 | 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); |
---|
87 | free(tmp); |
---|
88 | if(res==NULL){ |
---|
89 | setMapInMaps(conf,"lenv","message",_ss("Unable to call OGR_G_CreatFromGML")); |
---|
90 | return NULL; |
---|
91 | } |
---|
92 | else |
---|
93 | return res; |
---|
94 | } |
---|
95 | |
---|
96 | int Simplify(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
97 | maps* cursor=inputs; |
---|
98 | OGRGeometryH geometry,res; |
---|
99 | double tolerance; |
---|
100 | map* tmp0=getMapFromMaps(cursor,"Tolerance","value"); |
---|
101 | if(tmp0==NULL){ |
---|
102 | tolerance=atof("2.0"); |
---|
103 | } |
---|
104 | else |
---|
105 | tolerance=atof(tmp0->value); |
---|
106 | fprintf(stderr,"Tolerance for Simplify %f",tolerance); |
---|
107 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
108 | if(!tmp){ |
---|
109 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
110 | return SERVICE_FAILED; |
---|
111 | } |
---|
112 | map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); |
---|
113 | if(tmp1!=NULL){ |
---|
114 | if(strncmp(tmp1->value,"text/js",7)==0 || |
---|
115 | strncmp(tmp1->value,"application/json",16)==0) |
---|
116 | geometry=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
117 | else |
---|
118 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
119 | } |
---|
120 | else{ |
---|
121 | setMapInMaps(conf,"lenv","message",_ss("Unable to find any geometry for InputPolygon")); |
---|
122 | return SERVICE_FAILED; |
---|
123 | } |
---|
124 | if(geometry==NULL){ |
---|
125 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
126 | return SERVICE_FAILED; |
---|
127 | } |
---|
128 | fprintf(stderr,"Create GEOSGeometry object"); |
---|
129 | GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS(); |
---|
130 | GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance); |
---|
131 | res=OGRGeometryFactory::createFromGEOS(gres); |
---|
132 | tmp1=getMapFromMaps(outputs,"Result","mimeType"); |
---|
133 | if(tmp1!=NULL){ |
---|
134 | if(strncmp(tmp1->value,"text/js",7)==0 || |
---|
135 | strncmp(tmp1->value,"application/json",16)==0){ |
---|
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); |
---|
141 | } |
---|
142 | else{ |
---|
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); |
---|
149 | } |
---|
150 | }else{ |
---|
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); |
---|
156 | } |
---|
157 | outputs->next=NULL; |
---|
158 | //GEOSFree(ggeometry); |
---|
159 | //GEOSFree(gres); |
---|
160 | OGR_G_DestroyGeometry(res); |
---|
161 | OGR_G_DestroyGeometry(geometry); |
---|
162 | return SERVICE_SUCCEEDED; |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){ |
---|
167 | #ifdef DEBUG |
---|
168 | fprintf(stderr,"\nService internal print\n"); |
---|
169 | #endif |
---|
170 | maps* cursor=inputs; |
---|
171 | OGRGeometryH geometry,res; |
---|
172 | #ifdef DEBUG |
---|
173 | dumpMaps(cursor); |
---|
174 | #endif |
---|
175 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
176 | if(!tmp){ |
---|
177 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
178 | return SERVICE_FAILED; |
---|
179 | } |
---|
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); |
---|
191 | else |
---|
192 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
193 | } |
---|
194 | else |
---|
195 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
196 | if(geometry==NULL){ |
---|
197 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
198 | return SERVICE_FAILED; |
---|
199 | } |
---|
200 | res=(*myFunc)(geometry); |
---|
201 | fprintf(stderr,"Service internal print \n"); |
---|
202 | dumpMaps(outputs); |
---|
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){ |
---|
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); |
---|
216 | } |
---|
217 | else{ |
---|
218 | char *tmpS=OGR_G_ExportToGML(res); |
---|
219 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
220 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
221 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
222 | free(tmpS); |
---|
223 | |
---|
224 | } |
---|
225 | }else{ |
---|
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); |
---|
231 | } |
---|
232 | outputs->next=NULL; |
---|
233 | #ifdef DEBUG |
---|
234 | dumpMaps(outputs); |
---|
235 | fprintf(stderr,"\nService internal print\n===\n"); |
---|
236 | #endif |
---|
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"); |
---|
244 | return SERVICE_SUCCEEDED; |
---|
245 | } |
---|
246 | |
---|
247 | #ifdef WIN32 |
---|
248 | __declspec(dllexport) |
---|
249 | #endif |
---|
250 | int Buffer(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
251 | OGRGeometryH geometry,res; |
---|
252 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
253 | if(tmp==NULL){ |
---|
254 | setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry")); |
---|
255 | return SERVICE_FAILED; |
---|
256 | }else |
---|
257 | if(strlen(tmp->value)<=0){ |
---|
258 | setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry")); |
---|
259 | return SERVICE_FAILED; |
---|
260 | } |
---|
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); |
---|
266 | if(geometry==NULL){ |
---|
267 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry")); |
---|
268 | return SERVICE_FAILED; |
---|
269 | } |
---|
270 | double bufferDistance; |
---|
271 | tmp=getMapFromMaps(inputs,"BufferDistance","value"); |
---|
272 | if(tmp==NULL){ |
---|
273 | bufferDistance=atof("10.0"); |
---|
274 | } |
---|
275 | else |
---|
276 | bufferDistance=atof(tmp->value); |
---|
277 | res=OGR_G_Buffer(geometry,bufferDistance,30); |
---|
278 | tmp1=getMapFromMaps(outputs,"Result","mimeType"); |
---|
279 | if(strncmp(tmp1->value,"application/json",16)==0){ |
---|
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); |
---|
285 | } |
---|
286 | else{ |
---|
287 | char *tmpS=OGR_G_ExportToGML(res); |
---|
288 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
289 | free(tmpS); |
---|
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"); |
---|
293 | } |
---|
294 | outputs->next=NULL; |
---|
295 | OGR_G_DestroyGeometry(geometry); |
---|
296 | OGR_G_DestroyGeometry(res); |
---|
297 | return SERVICE_SUCCEEDED; |
---|
298 | } |
---|
299 | |
---|
300 | #ifdef WIN32 |
---|
301 | __declspec(dllexport) |
---|
302 | #endif |
---|
303 | int Boundary(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
304 | return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary); |
---|
305 | } |
---|
306 | |
---|
307 | #ifdef WIN32 |
---|
308 | __declspec(dllexport) |
---|
309 | #endif |
---|
310 | int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
311 | return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull); |
---|
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){ |
---|
330 | return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid); |
---|
331 | } |
---|
332 | |
---|
333 | int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH,OGRGeometryH)){ |
---|
334 | #ifdef DEBUG |
---|
335 | fprintf(stderr,"\nService internal print1\n"); |
---|
336 | fflush(stderr); |
---|
337 | #endif |
---|
338 | fprintf(stderr,"\nService internal print1\n"); |
---|
339 | dumpMaps(inputs); |
---|
340 | fprintf(stderr,"\nService internal print1\n"); |
---|
341 | |
---|
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 | } |
---|
357 | if(geometry1==NULL){ |
---|
358 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1.")); |
---|
359 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
360 | return SERVICE_FAILED; |
---|
361 | } |
---|
362 | fprintf(stderr,"\nService internal print1 InputEntity1\n"); |
---|
363 | { |
---|
364 | map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); |
---|
365 | map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType"); |
---|
366 | //#ifdef DEBUG |
---|
367 | fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16)); |
---|
368 | //dumpMap(tmp); |
---|
369 | fprintf(stderr,"MY MAP\n"); |
---|
370 | ///#endif |
---|
371 | fprintf(stderr,"\nService internal print1 InputEntity2\n"); |
---|
372 | if(tmp1!=NULL){ |
---|
373 | if(strncmp(tmp1->value,"application/json",16)==0){ |
---|
374 | fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n"); |
---|
375 | geometry2=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
376 | } |
---|
377 | else{ |
---|
378 | fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n"); |
---|
379 | geometry2=createGeometryFromGML(conf,tmp->value); |
---|
380 | } |
---|
381 | } |
---|
382 | else |
---|
383 | geometry2=createGeometryFromGML(conf,tmp->value); |
---|
384 | fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n"); |
---|
385 | } |
---|
386 | fprintf(stderr,"\nService internal print1 InputEntity2 Final\n"); |
---|
387 | if(geometry2==NULL){ |
---|
388 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2.")); |
---|
389 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
390 | return SERVICE_FAILED; |
---|
391 | } |
---|
392 | fprintf(stderr,"\nService internal print1\n"); |
---|
393 | res=(*myFunc)(geometry1,geometry2); |
---|
394 | fprintf(stderr,"\nService internal print1\n"); |
---|
395 | char *tmpS=OGR_G_ExportToJson(res); |
---|
396 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
397 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
398 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
399 | free(tmpS); |
---|
400 | OGR_G_DestroyGeometry(geometry1); |
---|
401 | OGR_G_DestroyGeometry(geometry2); |
---|
402 | OGR_G_DestroyGeometry(res); |
---|
403 | return SERVICE_SUCCEEDED; |
---|
404 | } |
---|
405 | |
---|
406 | #ifdef WIN32 |
---|
407 | __declspec(dllexport) |
---|
408 | #endif |
---|
409 | int Difference(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
410 | return applyTwo(conf,inputs,outputs,&OGR_G_Difference); |
---|
411 | } |
---|
412 | |
---|
413 | #ifdef WIN32 |
---|
414 | __declspec(dllexport) |
---|
415 | #endif |
---|
416 | int SymDifference(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
417 | return applyTwo(conf,inputs,outputs,&OGR_G_SymmetricDifference); |
---|
418 | } |
---|
419 | |
---|
420 | #ifdef WIN32 |
---|
421 | __declspec(dllexport) |
---|
422 | #endif |
---|
423 | int Intersection(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
424 | return applyTwo(conf,inputs,outputs,&OGR_G_Intersection); |
---|
425 | } |
---|
426 | |
---|
427 | #ifdef WIN32 |
---|
428 | __declspec(dllexport) |
---|
429 | #endif |
---|
430 | int Union(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
431 | return applyTwo(conf,inputs,outputs,&OGR_G_Union); |
---|
432 | } |
---|
433 | |
---|
434 | #ifdef WIN32 |
---|
435 | __declspec(dllexport) |
---|
436 | #endif |
---|
437 | int Distance(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
438 | #ifdef DEBUG |
---|
439 | fprintf(stderr,"\nService internal print1\n"); |
---|
440 | #endif |
---|
441 | fflush(stderr); |
---|
442 | maps* cursor=inputs; |
---|
443 | OGRGeometryH geometry1,geometry2; |
---|
444 | double res; |
---|
445 | { |
---|
446 | map* tmp=getMapFromMaps(inputs,"InputEntity1","value"); |
---|
447 | map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType"); |
---|
448 | #ifdef DEBUG |
---|
449 | fprintf(stderr,"MY MAP\n"); |
---|
450 | dumpMap(tmp1); |
---|
451 | dumpMaps(inputs); |
---|
452 | fprintf(stderr,"MY MAP\n"); |
---|
453 | #endif |
---|
454 | if(tmp1!=NULL){ |
---|
455 | if(strncmp(tmp1->value,"application/json",16)==0) |
---|
456 | geometry1=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
457 | else |
---|
458 | geometry1=createGeometryFromGML(conf,tmp->value); |
---|
459 | } |
---|
460 | else |
---|
461 | geometry1=createGeometryFromGML(conf,tmp->value); |
---|
462 | } |
---|
463 | if(geometry1==NULL){ |
---|
464 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1.")); |
---|
465 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
466 | return SERVICE_FAILED; |
---|
467 | } |
---|
468 | { |
---|
469 | map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); |
---|
470 | map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType"); |
---|
471 | #ifdef DEBUG |
---|
472 | fprintf(stderr,"MY MAP\n"); |
---|
473 | dumpMap(tmp1); |
---|
474 | dumpMaps(inputs); |
---|
475 | fprintf(stderr,"MY MAP\n"); |
---|
476 | #endif |
---|
477 | if(tmp1!=NULL){ |
---|
478 | if(strncmp(tmp1->value,"application/json",16)==0) |
---|
479 | geometry2=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
480 | else |
---|
481 | geometry2=createGeometryFromGML(conf,tmp->value); |
---|
482 | } |
---|
483 | else |
---|
484 | geometry2=createGeometryFromGML(conf,tmp->value); |
---|
485 | } |
---|
486 | if(geometry2==NULL){ |
---|
487 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2.")); |
---|
488 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
489 | return SERVICE_FAILED; |
---|
490 | } |
---|
491 | res=OGR_G_Distance(geometry1,geometry2); |
---|
492 | char tmpres[100]; |
---|
493 | sprintf(tmpres,"%d",res); |
---|
494 | setMapInMaps(outputs,"Distance","value",tmpres); |
---|
495 | setMapInMaps(outputs,"Distance","dataType","float"); |
---|
496 | #ifdef DEBUG |
---|
497 | dumpMaps(outputs); |
---|
498 | fprintf(stderr,"\nService internal print\n===\n"); |
---|
499 | #endif |
---|
500 | return SERVICE_SUCCEEDED; |
---|
501 | } |
---|
502 | |
---|
503 | #ifdef WIN32 |
---|
504 | __declspec(dllexport) |
---|
505 | #endif |
---|
506 | int GetArea(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
507 | fprintf(stderr,"GETAREA \n"); |
---|
508 | double res; |
---|
509 | /** |
---|
510 | * Extract Geometry from the InputPolygon value |
---|
511 | */ |
---|
512 | OGRGeometryH geometry; |
---|
513 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
514 | if(tmp==NULL){ |
---|
515 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon")); |
---|
516 | return SERVICE_FAILED; |
---|
517 | } |
---|
518 | fprintf(stderr,"geometry creation %s \n",tmp->value); |
---|
519 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
520 | if(geometry==NULL){ |
---|
521 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon")); |
---|
522 | return SERVICE_FAILED; |
---|
523 | } |
---|
524 | fprintf(stderr,"geometry created %s \n",tmp->value); |
---|
525 | res=OGR_G_GetArea(geometry); |
---|
526 | fprintf(stderr,"area %d \n",res); |
---|
527 | /** |
---|
528 | * Filling the outputs |
---|
529 | */ |
---|
530 | char tmp1[100]; |
---|
531 | sprintf(tmp1,"%d",res); |
---|
532 | setMapInMaps(outputs,"Area","value",tmp1); |
---|
533 | setMapInMaps(outputs,"Area","dataType","float"); |
---|
534 | #ifdef DEBUG |
---|
535 | dumpMaps(outputs); |
---|
536 | #endif |
---|
537 | return SERVICE_SUCCEEDED; |
---|
538 | } |
---|
539 | |
---|
540 | } |
---|