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