[1] | 1 | /** |
---|
| 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
| 4 | * Copyright 2008-2009 GeoLabs SARL. All rights reserved. |
---|
| 5 | * |
---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 8 | * in the Software without restriction, including without limitation the rights |
---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 11 | * furnished to do so, subject to the following conditions: |
---|
| 12 | * |
---|
| 13 | * The above copyright notice and this permission notice shall be included in |
---|
| 14 | * all copies or substantial portions of the Software. |
---|
| 15 | * |
---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 22 | * THE SOFTWARE. |
---|
| 23 | */ |
---|
| 24 | |
---|
[9] | 25 | #include "cpl_conv.h" |
---|
[1] | 26 | #include "ogr_api.h" |
---|
[9] | 27 | #include "ogr_geometry.h" |
---|
| 28 | #include "geos_c.h" |
---|
[1] | 29 | #include "service.h" |
---|
[36] | 30 | #include "service_internal.h" |
---|
[1] | 31 | |
---|
| 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); |
---|
[9] | 75 | char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char)); |
---|
| 76 | sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2); |
---|
[1] | 77 | xmlXPathFreeObject(xpathObj); |
---|
[9] | 78 | xmlXPathFreeContext(xpathCtx); |
---|
[1] | 79 | xmlFree(xmlbuff); |
---|
| 80 | xmlFreeDoc(doc); |
---|
[9] | 81 | xmlFreeDoc(ndoc); |
---|
[1] | 82 | xmlCleanupParser(); |
---|
| 83 | #ifdef DEBUG |
---|
| 84 | fprintf(stderr,"\nService internal print\n Loading the geometry from GML string ..."); |
---|
| 85 | #endif |
---|
| 86 | OGRGeometryH res=OGR_G_CreateFromGML(tmp); |
---|
[9] | 87 | free(tmp); |
---|
[1] | 88 | if(res==NULL){ |
---|
[36] | 89 | setMapInMaps(conf,"lenv","message",_ss("Unable to call OGR_G_CreatFromGML")); |
---|
[26] | 90 | return NULL; |
---|
[1] | 91 | } |
---|
| 92 | else |
---|
[26] | 93 | return res; |
---|
[1] | 94 | } |
---|
| 95 | |
---|
[9] | 96 | int Simplify(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[1] | 97 | maps* cursor=inputs; |
---|
[9] | 98 | OGRGeometryH geometry,res; |
---|
| 99 | double tolerance; |
---|
| 100 | map* tmp0=getMapFromMaps(cursor,"Tolerance","value"); |
---|
| 101 | if(tmp0==NULL){ |
---|
| 102 | tolerance=atof("2.0"); |
---|
[1] | 103 | } |
---|
[9] | 104 | else |
---|
| 105 | tolerance=atof(tmp0->value); |
---|
| 106 | fprintf(stderr,"Tolerance for Simplify %f",tolerance); |
---|
[1] | 107 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
[26] | 108 | if(!tmp){ |
---|
[36] | 109 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
[1] | 110 | return SERVICE_FAILED; |
---|
[26] | 111 | } |
---|
| 112 | map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); |
---|
[1] | 113 | if(tmp1!=NULL){ |
---|
[9] | 114 | if(strncmp(tmp1->value,"text/js",7)==0 || |
---|
[26] | 115 | strncmp(tmp1->value,"application/json",16)==0) |
---|
[1] | 116 | geometry=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
| 117 | else |
---|
| 118 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
[9] | 119 | } |
---|
[26] | 120 | else{ |
---|
[36] | 121 | setMapInMaps(conf,"lenv","message",_ss("Unable to find any geometry for InputPolygon")); |
---|
[26] | 122 | return SERVICE_FAILED; |
---|
| 123 | } |
---|
| 124 | if(geometry==NULL){ |
---|
[36] | 125 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
[26] | 126 | return SERVICE_FAILED; |
---|
| 127 | } |
---|
| 128 | fprintf(stderr,"Create GEOSGeometry object"); |
---|
[9] | 129 | GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS(); |
---|
| 130 | GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance); |
---|
| 131 | res=OGRGeometryFactory::createFromGEOS(gres); |
---|
[26] | 132 | tmp1=getMapFromMaps(outputs,"Result","mimeType"); |
---|
[1] | 133 | if(tmp1!=NULL){ |
---|
[9] | 134 | if(strncmp(tmp1->value,"text/js",7)==0 || |
---|
| 135 | strncmp(tmp1->value,"application/json",16)==0){ |
---|
[26] | 136 | char *tmpS=OGR_G_ExportToJson(res); |
---|
| 137 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
| 138 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
| 139 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 140 | free(tmpS); |
---|
[1] | 141 | } |
---|
| 142 | else{ |
---|
[26] | 143 | char *tmpS=OGR_G_ExportToGML(res); |
---|
| 144 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
| 145 | setMapInMaps(outputs,"Result","mimeType","text/xml"); |
---|
| 146 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 147 | setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd"); |
---|
| 148 | free(tmpS); |
---|
[1] | 149 | } |
---|
| 150 | }else{ |
---|
[26] | 151 | char *tmpS=OGR_G_ExportToJson(tmp->value); |
---|
| 152 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
| 153 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
| 154 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 155 | free(tmpS); |
---|
[1] | 156 | } |
---|
| 157 | outputs->next=NULL; |
---|
[9] | 158 | //GEOSFree(ggeometry); |
---|
| 159 | //GEOSFree(gres); |
---|
| 160 | OGR_G_DestroyGeometry(res); |
---|
| 161 | OGR_G_DestroyGeometry(geometry); |
---|
[1] | 162 | return SERVICE_SUCCEEDED; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
[9] | 166 | int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){ |
---|
[1] | 167 | #ifdef DEBUG |
---|
[9] | 168 | fprintf(stderr,"\nService internal print\n"); |
---|
[1] | 169 | #endif |
---|
| 170 | maps* cursor=inputs; |
---|
| 171 | OGRGeometryH geometry,res; |
---|
| 172 | #ifdef DEBUG |
---|
[9] | 173 | dumpMaps(cursor); |
---|
[1] | 174 | #endif |
---|
[9] | 175 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
[35] | 176 | if(!tmp){ |
---|
[36] | 177 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
[9] | 178 | return SERVICE_FAILED; |
---|
[35] | 179 | } |
---|
[9] | 180 | fprintf(stderr,"Service internal print \n"); |
---|
| 181 | dumpMaps(inputs); |
---|
| 182 | fprintf(stderr,"/Service internal print \n"); |
---|
| 183 | map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); |
---|
| 184 | fprintf(stderr,"Service internal print \n"); |
---|
| 185 | dumpMap(tmp1); |
---|
| 186 | fprintf(stderr,"/Service internal print \n"); |
---|
| 187 | if(tmp1!=NULL){ |
---|
| 188 | if(strncmp(tmp1->value,"text/js",7)==0 || |
---|
| 189 | strncmp(tmp1->value,"application/json",7)==0) |
---|
| 190 | geometry=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
[1] | 191 | else |
---|
[9] | 192 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
[1] | 193 | } |
---|
[9] | 194 | else |
---|
| 195 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
[35] | 196 | if(geometry==NULL){ |
---|
[36] | 197 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
[26] | 198 | return SERVICE_FAILED; |
---|
[35] | 199 | } |
---|
[9] | 200 | res=(*myFunc)(geometry); |
---|
| 201 | fprintf(stderr,"Service internal print \n"); |
---|
[1] | 202 | dumpMaps(outputs); |
---|
[9] | 203 | fprintf(stderr,"/Service internal print \n"); |
---|
| 204 | map *tmp_2=getMapFromMaps(outputs,"Result","mimeType"); |
---|
| 205 | fprintf(stderr,"Service internal print \n"); |
---|
| 206 | dumpMap(tmp_2); |
---|
| 207 | fprintf(stderr,"/Service internal print \n"); |
---|
| 208 | if(tmp_2!=NULL){ |
---|
| 209 | if(strncmp(tmp_2->value,"text/js",7)==0 || |
---|
| 210 | strncmp(tmp_2->value,"application/json",16)==0){ |
---|
[26] | 211 | char *tmpS=OGR_G_ExportToJson(res); |
---|
| 212 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
| 213 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
| 214 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 215 | free(tmpS); |
---|
[1] | 216 | } |
---|
[9] | 217 | else{ |
---|
[26] | 218 | char *tmpS=OGR_G_ExportToGML(res); |
---|
| 219 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
| 220 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
| 221 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 222 | free(tmpS); |
---|
| 223 | |
---|
[1] | 224 | } |
---|
[9] | 225 | }else{ |
---|
[26] | 226 | char *tmpS=OGR_G_ExportToJson(res); |
---|
| 227 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
| 228 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
| 229 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 230 | free(tmpS); |
---|
[1] | 231 | } |
---|
| 232 | outputs->next=NULL; |
---|
| 233 | #ifdef DEBUG |
---|
| 234 | dumpMaps(outputs); |
---|
| 235 | fprintf(stderr,"\nService internal print\n===\n"); |
---|
| 236 | #endif |
---|
[9] | 237 | OGR_G_DestroyGeometry(res); |
---|
| 238 | OGR_G_DestroyGeometry(geometry); |
---|
| 239 | //CPLFree(res); |
---|
| 240 | //CPLFree(geometry); |
---|
| 241 | fprintf(stderr,"Service internal print \n"); |
---|
| 242 | dumpMaps(outputs); |
---|
| 243 | fprintf(stderr,"/Service internal print \n"); |
---|
[1] | 244 | return SERVICE_SUCCEEDED; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | #ifdef WIN32 |
---|
| 248 | __declspec(dllexport) |
---|
| 249 | #endif |
---|
[9] | 250 | int Buffer(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 251 | OGRGeometryH geometry,res; |
---|
| 252 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
[32] | 253 | if(tmp==NULL){ |
---|
[36] | 254 | setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry")); |
---|
[9] | 255 | return SERVICE_FAILED; |
---|
[32] | 256 | }else |
---|
| 257 | if(strlen(tmp->value)<=0){ |
---|
[36] | 258 | setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry")); |
---|
[32] | 259 | return SERVICE_FAILED; |
---|
| 260 | } |
---|
[9] | 261 | map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); |
---|
| 262 | if(strncmp(tmp1->value,"application/json",16)==0) |
---|
| 263 | geometry=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
| 264 | else |
---|
| 265 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
[26] | 266 | if(geometry==NULL){ |
---|
[36] | 267 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry")); |
---|
[26] | 268 | return SERVICE_FAILED; |
---|
| 269 | } |
---|
| 270 | double bufferDistance; |
---|
[9] | 271 | tmp=getMapFromMaps(inputs,"BufferDistance","value"); |
---|
[26] | 272 | if(tmp==NULL){ |
---|
| 273 | bufferDistance=atof("10.0"); |
---|
| 274 | } |
---|
| 275 | else |
---|
| 276 | bufferDistance=atof(tmp->value); |
---|
[9] | 277 | res=OGR_G_Buffer(geometry,bufferDistance,30); |
---|
| 278 | tmp1=getMapFromMaps(outputs,"Result","mimeType"); |
---|
| 279 | if(strncmp(tmp1->value,"application/json",16)==0){ |
---|
[26] | 280 | char *tmpS=OGR_G_ExportToJson(res); |
---|
| 281 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
| 282 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
| 283 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 284 | free(tmpS); |
---|
[9] | 285 | } |
---|
| 286 | else{ |
---|
[26] | 287 | char *tmpS=OGR_G_ExportToGML(res); |
---|
| 288 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
[35] | 289 | free(tmpS); |
---|
[26] | 290 | setMapInMaps(outputs,"Result","mimeType","text/xml"); |
---|
| 291 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 292 | setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd"); |
---|
[9] | 293 | } |
---|
| 294 | outputs->next=NULL; |
---|
| 295 | OGR_G_DestroyGeometry(geometry); |
---|
| 296 | OGR_G_DestroyGeometry(res); |
---|
| 297 | return SERVICE_SUCCEEDED; |
---|
| 298 | } |
---|
| 299 | |
---|
[1] | 300 | #ifdef WIN32 |
---|
| 301 | __declspec(dllexport) |
---|
| 302 | #endif |
---|
[9] | 303 | int Boundary(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 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)){ |
---|
[1] | 334 | #ifdef DEBUG |
---|
| 335 | fprintf(stderr,"\nService internal print1\n"); |
---|
[26] | 336 | fflush(stderr); |
---|
[9] | 337 | #endif |
---|
[26] | 338 | fprintf(stderr,"\nService internal print1\n"); |
---|
| 339 | dumpMaps(inputs); |
---|
| 340 | fprintf(stderr,"\nService internal print1\n"); |
---|
[9] | 341 | |
---|
[1] | 342 | maps* cursor=inputs; |
---|
| 343 | OGRGeometryH geometry1,geometry2; |
---|
| 344 | OGRGeometryH res; |
---|
| 345 | { |
---|
| 346 | map* tmp=getMapFromMaps(inputs,"InputEntity1","value"); |
---|
| 347 | map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType"); |
---|
| 348 | if(tmp1!=NULL){ |
---|
| 349 | if(strncmp(tmp1->value,"application/json",16)==0) |
---|
| 350 | geometry1=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
| 351 | else |
---|
| 352 | geometry1=createGeometryFromGML(conf,tmp->value); |
---|
| 353 | } |
---|
| 354 | else |
---|
| 355 | geometry1=createGeometryFromGML(conf,tmp->value); |
---|
| 356 | } |
---|
[26] | 357 | if(geometry1==NULL){ |
---|
[36] | 358 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1.")); |
---|
[26] | 359 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
| 360 | return SERVICE_FAILED; |
---|
| 361 | } |
---|
| 362 | fprintf(stderr,"\nService internal print1 InputEntity1\n"); |
---|
[1] | 363 | { |
---|
| 364 | map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); |
---|
| 365 | map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType"); |
---|
[26] | 366 | //#ifdef DEBUG |
---|
| 367 | fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16)); |
---|
| 368 | //dumpMap(tmp); |
---|
[1] | 369 | fprintf(stderr,"MY MAP\n"); |
---|
[26] | 370 | ///#endif |
---|
| 371 | fprintf(stderr,"\nService internal print1 InputEntity2\n"); |
---|
[1] | 372 | if(tmp1!=NULL){ |
---|
[26] | 373 | if(strncmp(tmp1->value,"application/json",16)==0){ |
---|
| 374 | fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n"); |
---|
[1] | 375 | geometry2=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
[26] | 376 | } |
---|
| 377 | else{ |
---|
| 378 | fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n"); |
---|
[1] | 379 | geometry2=createGeometryFromGML(conf,tmp->value); |
---|
[26] | 380 | } |
---|
[1] | 381 | } |
---|
| 382 | else |
---|
| 383 | geometry2=createGeometryFromGML(conf,tmp->value); |
---|
[26] | 384 | fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n"); |
---|
[1] | 385 | } |
---|
[26] | 386 | fprintf(stderr,"\nService internal print1 InputEntity2 Final\n"); |
---|
| 387 | if(geometry2==NULL){ |
---|
[36] | 388 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2.")); |
---|
[26] | 389 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
| 390 | return SERVICE_FAILED; |
---|
| 391 | } |
---|
| 392 | fprintf(stderr,"\nService internal print1\n"); |
---|
[9] | 393 | res=(*myFunc)(geometry1,geometry2); |
---|
[26] | 394 | fprintf(stderr,"\nService internal print1\n"); |
---|
| 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); |
---|
[9] | 400 | OGR_G_DestroyGeometry(geometry1); |
---|
| 401 | OGR_G_DestroyGeometry(geometry2); |
---|
| 402 | OGR_G_DestroyGeometry(res); |
---|
[1] | 403 | return SERVICE_SUCCEEDED; |
---|
| 404 | } |
---|
[9] | 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 | } |
---|
[1] | 412 | |
---|
| 413 | #ifdef WIN32 |
---|
| 414 | __declspec(dllexport) |
---|
| 415 | #endif |
---|
[9] | 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 |
---|
[1] | 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 | } |
---|
[26] | 463 | if(geometry1==NULL){ |
---|
[36] | 464 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1.")); |
---|
[26] | 465 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
| 466 | return SERVICE_FAILED; |
---|
| 467 | } |
---|
[1] | 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 | } |
---|
[26] | 486 | if(geometry2==NULL){ |
---|
[36] | 487 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2.")); |
---|
[26] | 488 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
| 489 | return SERVICE_FAILED; |
---|
| 490 | } |
---|
| 491 | res=OGR_G_Distance(geometry1,geometry2); |
---|
[1] | 492 | char tmpres[100]; |
---|
| 493 | sprintf(tmpres,"%d",res); |
---|
[26] | 494 | setMapInMaps(outputs,"Distance","value",tmpres); |
---|
| 495 | setMapInMaps(outputs,"Distance","dataType","float"); |
---|
[1] | 496 | #ifdef DEBUG |
---|
| 497 | dumpMaps(outputs); |
---|
| 498 | fprintf(stderr,"\nService internal print\n===\n"); |
---|
| 499 | #endif |
---|
| 500 | return SERVICE_SUCCEEDED; |
---|
| 501 | } |
---|
| 502 | |
---|
[9] | 503 | #ifdef WIN32 |
---|
| 504 | __declspec(dllexport) |
---|
| 505 | #endif |
---|
[1] | 506 | int GetArea(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 507 | fprintf(stderr,"GETAREA \n"); |
---|
| 508 | double res; |
---|
| 509 | /** |
---|
[26] | 510 | * Extract Geometry from the InputPolygon value |
---|
[1] | 511 | */ |
---|
[26] | 512 | OGRGeometryH geometry; |
---|
| 513 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
| 514 | if(tmp==NULL){ |
---|
[36] | 515 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon")); |
---|
[26] | 516 | return SERVICE_FAILED; |
---|
| 517 | } |
---|
[1] | 518 | fprintf(stderr,"geometry creation %s \n",tmp->value); |
---|
[26] | 519 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
| 520 | if(geometry==NULL){ |
---|
[36] | 521 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon")); |
---|
[26] | 522 | return SERVICE_FAILED; |
---|
| 523 | } |
---|
[1] | 524 | fprintf(stderr,"geometry created %s \n",tmp->value); |
---|
[26] | 525 | res=OGR_G_GetArea(geometry); |
---|
[1] | 526 | fprintf(stderr,"area %d \n",res); |
---|
| 527 | /** |
---|
[26] | 528 | * Filling the outputs |
---|
[1] | 529 | */ |
---|
| 530 | char tmp1[100]; |
---|
| 531 | sprintf(tmp1,"%d",res); |
---|
[26] | 532 | setMapInMaps(outputs,"Area","value",tmp1); |
---|
| 533 | setMapInMaps(outputs,"Area","dataType","float"); |
---|
[1] | 534 | #ifdef DEBUG |
---|
| 535 | dumpMaps(outputs); |
---|
| 536 | #endif |
---|
| 537 | return SERVICE_SUCCEEDED; |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | } |
---|