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