[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" |
---|
[491] | 28 | |
---|
| 29 | #include "cpl_minixml.h" |
---|
| 30 | #include "ogr_api.h" |
---|
| 31 | #include "ogrsf_frmts.h" |
---|
| 32 | |
---|
[9] | 33 | #include "geos_c.h" |
---|
[1] | 34 | #include "service.h" |
---|
[36] | 35 | #include "service_internal.h" |
---|
[1] | 36 | |
---|
| 37 | extern "C" { |
---|
| 38 | #include <libxml/tree.h> |
---|
| 39 | #include <libxml/parser.h> |
---|
| 40 | #include <libxml/xpath.h> |
---|
| 41 | #include <libxml/xpathInternals.h> |
---|
| 42 | |
---|
| 43 | #include <openssl/sha.h> |
---|
| 44 | #include <openssl/hmac.h> |
---|
| 45 | #include <openssl/evp.h> |
---|
| 46 | #include <openssl/bio.h> |
---|
| 47 | #include <openssl/buffer.h> |
---|
| 48 | |
---|
| 49 | void printExceptionReportResponse(maps*,map*); |
---|
[216] | 50 | char *base64(const char *input, int length); |
---|
[1] | 51 | |
---|
| 52 | OGRGeometryH createGeometryFromGML(maps* conf,char* inputStr){ |
---|
| 53 | xmlInitParser(); |
---|
| 54 | xmlDocPtr doc = xmlParseMemory(inputStr,strlen(inputStr)); |
---|
| 55 | xmlChar *xmlbuff; |
---|
| 56 | int buffersize; |
---|
| 57 | xmlXPathContextPtr xpathCtx; |
---|
| 58 | xmlXPathObjectPtr xpathObj; |
---|
[491] | 59 | const char * xpathExpr="/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']"; |
---|
[1] | 60 | xpathCtx = xmlXPathNewContext(doc); |
---|
| 61 | xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr,xpathCtx); |
---|
| 62 | if(!xpathObj->nodesetval){ |
---|
[216] | 63 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse Input Polygon")); |
---|
| 64 | setMapInMaps(conf,"lenv","code","InvalidParameterValue"); |
---|
| 65 | return NULL; |
---|
[1] | 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); |
---|
[216] | 86 | #ifndef WIN32 |
---|
[1] | 87 | xmlCleanupParser(); |
---|
[216] | 88 | #endif |
---|
[1] | 89 | #ifdef DEBUG |
---|
| 90 | fprintf(stderr,"\nService internal print\n Loading the geometry from GML string ..."); |
---|
| 91 | #endif |
---|
| 92 | OGRGeometryH res=OGR_G_CreateFromGML(tmp); |
---|
[9] | 93 | free(tmp); |
---|
[1] | 94 | if(res==NULL){ |
---|
[36] | 95 | setMapInMaps(conf,"lenv","message",_ss("Unable to call OGR_G_CreatFromGML")); |
---|
[26] | 96 | return NULL; |
---|
[1] | 97 | } |
---|
| 98 | else |
---|
[26] | 99 | return res; |
---|
[1] | 100 | } |
---|
| 101 | |
---|
[216] | 102 | #ifdef WIN32 |
---|
| 103 | __declspec(dllexport) |
---|
| 104 | #endif |
---|
[9] | 105 | int Simplify(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[1] | 106 | maps* cursor=inputs; |
---|
[9] | 107 | OGRGeometryH geometry,res; |
---|
| 108 | double tolerance; |
---|
| 109 | map* tmp0=getMapFromMaps(cursor,"Tolerance","value"); |
---|
| 110 | if(tmp0==NULL){ |
---|
| 111 | tolerance=atof("2.0"); |
---|
[1] | 112 | } |
---|
[9] | 113 | else |
---|
| 114 | tolerance=atof(tmp0->value); |
---|
[216] | 115 | #ifdef DEBUG |
---|
[9] | 116 | fprintf(stderr,"Tolerance for Simplify %f",tolerance); |
---|
[216] | 117 | #endif |
---|
[1] | 118 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
[26] | 119 | if(!tmp){ |
---|
[36] | 120 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
[1] | 121 | return SERVICE_FAILED; |
---|
[26] | 122 | } |
---|
| 123 | map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); |
---|
[1] | 124 | if(tmp1!=NULL){ |
---|
[9] | 125 | if(strncmp(tmp1->value,"text/js",7)==0 || |
---|
[26] | 126 | strncmp(tmp1->value,"application/json",16)==0) |
---|
[1] | 127 | geometry=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
| 128 | else |
---|
| 129 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
[9] | 130 | } |
---|
[26] | 131 | else{ |
---|
[36] | 132 | setMapInMaps(conf,"lenv","message",_ss("Unable to find any geometry for InputPolygon")); |
---|
[26] | 133 | return SERVICE_FAILED; |
---|
| 134 | } |
---|
| 135 | if(geometry==NULL){ |
---|
[36] | 136 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
[26] | 137 | return SERVICE_FAILED; |
---|
| 138 | } |
---|
[216] | 139 | #ifdef DEBUG |
---|
[26] | 140 | fprintf(stderr,"Create GEOSGeometry object"); |
---|
[216] | 141 | #endif |
---|
[9] | 142 | GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS(); |
---|
| 143 | GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance); |
---|
[216] | 144 | res=(OGRGeometryH)OGRGeometryFactory::createFromGEOS(gres); |
---|
[26] | 145 | tmp1=getMapFromMaps(outputs,"Result","mimeType"); |
---|
[1] | 146 | if(tmp1!=NULL){ |
---|
[9] | 147 | if(strncmp(tmp1->value,"text/js",7)==0 || |
---|
| 148 | strncmp(tmp1->value,"application/json",16)==0){ |
---|
[26] | 149 | char *tmpS=OGR_G_ExportToJson(res); |
---|
| 150 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
[216] | 151 | #ifndef WIN32 |
---|
[26] | 152 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
| 153 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 154 | free(tmpS); |
---|
[216] | 155 | #endif |
---|
[1] | 156 | } |
---|
| 157 | else{ |
---|
[26] | 158 | char *tmpS=OGR_G_ExportToGML(res); |
---|
| 159 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
[216] | 160 | #ifndef WIN32 |
---|
[26] | 161 | setMapInMaps(outputs,"Result","mimeType","text/xml"); |
---|
| 162 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 163 | setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd"); |
---|
| 164 | free(tmpS); |
---|
[216] | 165 | #endif |
---|
[1] | 166 | } |
---|
| 167 | }else{ |
---|
[216] | 168 | char *tmpS=OGR_G_ExportToJson(res); |
---|
[26] | 169 | setMapInMaps(outputs,"Result","value",tmpS); |
---|
[216] | 170 | #ifndef WIN32 |
---|
[26] | 171 | setMapInMaps(outputs,"Result","mimeType","text/plain"); |
---|
| 172 | setMapInMaps(outputs,"Result","encoding","UTF-8"); |
---|
| 173 | free(tmpS); |
---|
[216] | 174 | #endif |
---|
[1] | 175 | } |
---|
| 176 | outputs->next=NULL; |
---|
[9] | 177 | //GEOSFree(ggeometry); |
---|
| 178 | //GEOSFree(gres); |
---|
| 179 | OGR_G_DestroyGeometry(res); |
---|
| 180 | OGR_G_DestroyGeometry(geometry); |
---|
[1] | 181 | return SERVICE_SUCCEEDED; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | |
---|
[491] | 185 | int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometry* (OGRGeometry::*myFunc)() const,const char* schema){ |
---|
| 186 | OGRRegisterAll(); |
---|
| 187 | |
---|
[1] | 188 | maps* cursor=inputs; |
---|
| 189 | OGRGeometryH geometry,res; |
---|
[491] | 190 | OGRLayer *poDstLayer; |
---|
| 191 | const char *oDriver1; |
---|
| 192 | OGRDataSource *poODS; |
---|
[9] | 193 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
[35] | 194 | if(!tmp){ |
---|
[36] | 195 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
[9] | 196 | return SERVICE_FAILED; |
---|
[35] | 197 | } |
---|
[491] | 198 | char filename[1024]; |
---|
[9] | 199 | map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); |
---|
[491] | 200 | const char *oDriver; |
---|
| 201 | oDriver="GeoJSON"; |
---|
| 202 | sprintf(filename,"/vsimem/input_%d.json",getpid()); |
---|
[9] | 203 | if(tmp1!=NULL){ |
---|
[491] | 204 | if(strcmp(tmp1->value,"text/xml")==0){ |
---|
| 205 | sprintf(filename,"/vsimem/input_%d.xml",getpid()); |
---|
| 206 | oDriver="GML"; |
---|
| 207 | } |
---|
[1] | 208 | } |
---|
[491] | 209 | VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE); |
---|
| 210 | VSIFCloseL(ifile); |
---|
| 211 | OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE); |
---|
| 212 | char pszDestDataSource[100]; |
---|
| 213 | if( ipoDS == NULL ) |
---|
| 214 | { |
---|
| 215 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 216 | |
---|
| 217 | fprintf( stderr, "FAILURE:\n" |
---|
| 218 | "Unable to open datasource `%s' with the following drivers.\n", |
---|
| 219 | filename ); |
---|
| 220 | |
---|
| 221 | for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 222 | { |
---|
| 223 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetName() ); |
---|
| 224 | } |
---|
| 225 | char tmp[1024]; |
---|
| 226 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename); |
---|
| 227 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 228 | return SERVICE_FAILED; |
---|
[1] | 229 | } |
---|
[491] | 230 | for( int iLayer = 0; iLayer < ipoDS->GetLayerCount(); |
---|
| 231 | iLayer++ ) |
---|
| 232 | { |
---|
| 233 | OGRLayer *poLayer = ipoDS->GetLayer(iLayer); |
---|
| 234 | |
---|
| 235 | if( poLayer == NULL ) |
---|
| 236 | { |
---|
| 237 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
| 238 | iLayer ); |
---|
| 239 | char tmp[1024]; |
---|
| 240 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer); |
---|
| 241 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 242 | return SERVICE_FAILED; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | OGRFeature *poFeature; |
---|
| 246 | |
---|
| 247 | /* -------------------------------------------------------------------- */ |
---|
| 248 | /* Try opening the output datasource as an existing, writable */ |
---|
| 249 | /* -------------------------------------------------------------------- */ |
---|
| 250 | |
---|
| 251 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 252 | OGRSFDriver *poDriver = NULL; |
---|
| 253 | int iDriver; |
---|
| 254 | |
---|
| 255 | map* tmpMap=getMapFromMaps(outputs,"Result","mimeType"); |
---|
| 256 | oDriver1="GeoJSON"; |
---|
| 257 | sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid()); |
---|
| 258 | if(tmpMap!=NULL){ |
---|
| 259 | if(strcmp(tmpMap->value,"text/xml")==0){ |
---|
| 260 | sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid()); |
---|
| 261 | oDriver1="GML"; |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | for( iDriver = 0; |
---|
| 266 | iDriver < poR->GetDriverCount() && poDriver == NULL; |
---|
| 267 | iDriver++ ) |
---|
| 268 | { |
---|
| 269 | if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver1) ) |
---|
| 270 | { |
---|
| 271 | poDriver = poR->GetDriver(iDriver); |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | if( poDriver == NULL ) |
---|
| 276 | { |
---|
| 277 | char emessage[8192]; |
---|
| 278 | sprintf( emessage, "Unable to find driver `%s'.\n", oDriver ); |
---|
| 279 | sprintf( emessage, "%sThe following drivers are available:\n",emessage ); |
---|
| 280 | |
---|
| 281 | for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 282 | { |
---|
| 283 | sprintf( emessage, "%s -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() ); |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 287 | return SERVICE_FAILED; |
---|
| 288 | |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | if( !poDriver->TestCapability( ODrCCreateDataSource ) ){ |
---|
| 292 | char emessage[1024]; |
---|
| 293 | sprintf( emessage, "%s driver does not support data source creation.\n", |
---|
| 294 | "json" ); |
---|
| 295 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 296 | return SERVICE_FAILED; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | /* -------------------------------------------------------------------- */ |
---|
| 300 | /* Create the output data source. */ |
---|
| 301 | /* -------------------------------------------------------------------- */ |
---|
| 302 | //map* tpath=getMapFromMaps(conf,"main","tmpPath"); |
---|
| 303 | char **papszDSCO=NULL; |
---|
| 304 | poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO ); |
---|
| 305 | if( poODS == NULL ){ |
---|
| 306 | char emessage[1024]; |
---|
| 307 | sprintf( emessage, "%s driver failed to create %s\n", |
---|
| 308 | "json", pszDestDataSource ); |
---|
| 309 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 310 | return SERVICE_FAILED; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | /* -------------------------------------------------------------------- */ |
---|
| 314 | /* Create the layer. */ |
---|
| 315 | /* -------------------------------------------------------------------- */ |
---|
| 316 | if( !poODS->TestCapability( ODsCCreateLayer ) ) |
---|
| 317 | { |
---|
| 318 | char emessage[1024]; |
---|
| 319 | sprintf( emessage, |
---|
| 320 | "Layer %s not found, and CreateLayer not supported by driver.", |
---|
| 321 | "Result" ); |
---|
| 322 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 323 | return SERVICE_FAILED; |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | //CPLErrorReset(); |
---|
| 327 | |
---|
| 328 | poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL); |
---|
| 329 | if( poDstLayer == NULL ){ |
---|
| 330 | setMapInMaps(conf,"lenv","message","Layer creation failed.\n"); |
---|
| 331 | return SERVICE_FAILED; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn(); |
---|
| 335 | int iField; |
---|
| 336 | int hasMmField=0; |
---|
| 337 | |
---|
| 338 | for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ ) |
---|
| 339 | { |
---|
| 340 | OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField); |
---|
| 341 | if (iField >= 0) |
---|
| 342 | poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) ); |
---|
| 343 | else |
---|
| 344 | { |
---|
| 345 | fprintf( stderr, "Field '%s' not found in source layer.\n", |
---|
| 346 | iField ); |
---|
| 347 | return SERVICE_FAILED; |
---|
| 348 | } |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | while(TRUE){ |
---|
| 352 | OGRFeature *poDstFeature = NULL; |
---|
| 353 | poFeature = poLayer->GetNextFeature(); |
---|
| 354 | if( poFeature == NULL ) |
---|
| 355 | break; |
---|
| 356 | if(poFeature->GetGeometryRef() != NULL){ |
---|
| 357 | // DO SOMETHING HERE !! |
---|
| 358 | poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() ); |
---|
| 359 | if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE ) |
---|
| 360 | { |
---|
| 361 | char tmpMsg[1024]; |
---|
| 362 | sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n", |
---|
| 363 | poFeature->GetFID(), poFDefn->GetName() ); |
---|
| 364 | |
---|
| 365 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 366 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 367 | return SERVICE_FAILED; |
---|
| 368 | } |
---|
| 369 | if(poDstFeature->SetGeometryDirectly((poDstFeature->GetGeometryRef()->*myFunc)()) != OGRERR_NONE ) |
---|
| 370 | { |
---|
| 371 | char tmpMsg[1024]; |
---|
| 372 | sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n", |
---|
| 373 | poFeature->GetFID(), poFDefn->GetName() ); |
---|
| 374 | |
---|
| 375 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 376 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 377 | return SERVICE_FAILED; |
---|
| 378 | } |
---|
| 379 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 380 | if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE ) |
---|
| 381 | { |
---|
| 382 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 383 | return SERVICE_FAILED; |
---|
| 384 | } |
---|
| 385 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 386 | } |
---|
| 387 | } |
---|
| 388 | |
---|
[1] | 389 | } |
---|
[491] | 390 | |
---|
| 391 | delete poODS; |
---|
| 392 | delete ipoDS; |
---|
| 393 | |
---|
| 394 | char *res1=readVSIFile(conf,pszDestDataSource); |
---|
| 395 | if(res1==NULL) |
---|
| 396 | return SERVICE_FAILED; |
---|
| 397 | setMapInMaps(outputs,"Result","value",res1); |
---|
| 398 | free(res1); |
---|
| 399 | |
---|
| 400 | OGRCleanupAll(); |
---|
[1] | 401 | return SERVICE_SUCCEEDED; |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | #ifdef WIN32 |
---|
| 405 | __declspec(dllexport) |
---|
| 406 | #endif |
---|
[9] | 407 | int Buffer(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[491] | 408 | OGRRegisterAll(); |
---|
| 409 | |
---|
| 410 | double bufferDistance; |
---|
| 411 | map* tmp0=getMapFromMaps(inputs,"BufferDistance","value"); |
---|
| 412 | if(tmp0==NULL){ |
---|
| 413 | bufferDistance=atof("10.0"); |
---|
| 414 | } |
---|
| 415 | else |
---|
| 416 | bufferDistance=atof(tmp0->value); |
---|
| 417 | |
---|
| 418 | maps* cursor=inputs; |
---|
| 419 | OGRGeometryH geometry,res; |
---|
| 420 | OGRLayer *poDstLayer; |
---|
| 421 | const char *oDriver1; |
---|
| 422 | OGRDataSource *poODS; |
---|
| 423 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
| 424 | if(!tmp){ |
---|
| 425 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
| 426 | return SERVICE_FAILED; |
---|
| 427 | } |
---|
| 428 | char filename[1024]; |
---|
| 429 | map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); |
---|
| 430 | const char *oDriver; |
---|
| 431 | oDriver="GeoJSON"; |
---|
| 432 | sprintf(filename,"/vsimem/input_%d.json",getpid()); |
---|
| 433 | if(tmp1!=NULL){ |
---|
| 434 | if(strcmp(tmp1->value,"text/xml")==0){ |
---|
| 435 | sprintf(filename,"/vsimem/input_%d.xml",getpid()); |
---|
| 436 | oDriver="GML"; |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE); |
---|
| 440 | VSIFCloseL(ifile); |
---|
| 441 | OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE); |
---|
| 442 | char pszDestDataSource[100]; |
---|
| 443 | if( ipoDS == NULL ) |
---|
| 444 | { |
---|
| 445 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 446 | |
---|
| 447 | fprintf( stderr, "FAILURE:\n" |
---|
| 448 | "Unable to open datasource `%s' with the following drivers.\n", |
---|
| 449 | filename ); |
---|
| 450 | |
---|
| 451 | for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 452 | { |
---|
| 453 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetName() ); |
---|
| 454 | } |
---|
| 455 | char tmp[1024]; |
---|
| 456 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename); |
---|
| 457 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 458 | return SERVICE_FAILED; |
---|
| 459 | } |
---|
| 460 | for( int iLayer = 0; iLayer < ipoDS->GetLayerCount(); |
---|
| 461 | iLayer++ ) |
---|
| 462 | { |
---|
| 463 | OGRLayer *poLayer = ipoDS->GetLayer(iLayer); |
---|
| 464 | |
---|
| 465 | if( poLayer == NULL ) |
---|
| 466 | { |
---|
| 467 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
| 468 | iLayer ); |
---|
| 469 | char tmp[1024]; |
---|
| 470 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer); |
---|
| 471 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 472 | return SERVICE_FAILED; |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | OGRFeature *poFeature; |
---|
| 476 | |
---|
| 477 | /* -------------------------------------------------------------------- */ |
---|
| 478 | /* Try opening the output datasource as an existing, writable */ |
---|
| 479 | /* -------------------------------------------------------------------- */ |
---|
| 480 | |
---|
| 481 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 482 | OGRSFDriver *poDriver = NULL; |
---|
| 483 | int iDriver; |
---|
| 484 | |
---|
| 485 | map* tmpMap=getMapFromMaps(outputs,"Result","mimeType"); |
---|
| 486 | oDriver1="GeoJSON"; |
---|
| 487 | sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid()); |
---|
| 488 | if(tmpMap!=NULL){ |
---|
| 489 | if(strcmp(tmpMap->value,"text/xml")==0){ |
---|
| 490 | sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid()); |
---|
| 491 | oDriver1="GML"; |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | for( iDriver = 0; |
---|
| 496 | iDriver < poR->GetDriverCount() && poDriver == NULL; |
---|
| 497 | iDriver++ ) |
---|
| 498 | { |
---|
| 499 | if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver1) ) |
---|
| 500 | { |
---|
| 501 | poDriver = poR->GetDriver(iDriver); |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | if( poDriver == NULL ) |
---|
| 506 | { |
---|
| 507 | char emessage[8192]; |
---|
| 508 | sprintf( emessage, "Unable to find driver `%s'.\n", oDriver ); |
---|
| 509 | sprintf( emessage, "%sThe following drivers are available:\n",emessage ); |
---|
| 510 | |
---|
| 511 | for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 512 | { |
---|
| 513 | sprintf( emessage, "%s -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() ); |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 517 | return SERVICE_FAILED; |
---|
| 518 | |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | if( !poDriver->TestCapability( ODrCCreateDataSource ) ){ |
---|
| 522 | char emessage[1024]; |
---|
| 523 | sprintf( emessage, "%s driver does not support data source creation.\n", |
---|
| 524 | "json" ); |
---|
| 525 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 526 | return SERVICE_FAILED; |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | /* -------------------------------------------------------------------- */ |
---|
| 530 | /* Create the output data source. */ |
---|
| 531 | /* -------------------------------------------------------------------- */ |
---|
| 532 | //map* tpath=getMapFromMaps(conf,"main","tmpPath"); |
---|
| 533 | char **papszDSCO=NULL; |
---|
| 534 | poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO ); |
---|
| 535 | if( poODS == NULL ){ |
---|
| 536 | char emessage[1024]; |
---|
| 537 | sprintf( emessage, "%s driver failed to create %s\n", |
---|
| 538 | "json", pszDestDataSource ); |
---|
| 539 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 540 | return SERVICE_FAILED; |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | /* -------------------------------------------------------------------- */ |
---|
| 544 | /* Create the layer. */ |
---|
| 545 | /* -------------------------------------------------------------------- */ |
---|
| 546 | if( !poODS->TestCapability( ODsCCreateLayer ) ) |
---|
| 547 | { |
---|
| 548 | char emessage[1024]; |
---|
| 549 | sprintf( emessage, |
---|
| 550 | "Layer %s not found, and CreateLayer not supported by driver.", |
---|
| 551 | "Result" ); |
---|
| 552 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 553 | return SERVICE_FAILED; |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | //CPLErrorReset(); |
---|
| 557 | |
---|
| 558 | poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL); |
---|
| 559 | if( poDstLayer == NULL ){ |
---|
| 560 | setMapInMaps(conf,"lenv","message","Layer creation failed.\n"); |
---|
| 561 | return SERVICE_FAILED; |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn(); |
---|
| 565 | int iField; |
---|
| 566 | int hasMmField=0; |
---|
| 567 | |
---|
| 568 | for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ ) |
---|
| 569 | { |
---|
| 570 | OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField); |
---|
| 571 | if (iField >= 0) |
---|
| 572 | poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) ); |
---|
| 573 | else |
---|
| 574 | { |
---|
| 575 | fprintf( stderr, "Field '%s' not found in source layer.\n", |
---|
| 576 | iField ); |
---|
| 577 | return SERVICE_FAILED; |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | while(TRUE){ |
---|
| 582 | OGRFeature *poDstFeature = NULL; |
---|
| 583 | poFeature = poLayer->GetNextFeature(); |
---|
| 584 | if( poFeature == NULL ) |
---|
| 585 | break; |
---|
| 586 | if(poFeature->GetGeometryRef() != NULL){ |
---|
| 587 | // DO SOMETHING HERE !! |
---|
| 588 | poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() ); |
---|
| 589 | if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE ) |
---|
| 590 | { |
---|
| 591 | char tmpMsg[1024]; |
---|
| 592 | sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n", |
---|
| 593 | poFeature->GetFID(), poFDefn->GetName() ); |
---|
| 594 | |
---|
| 595 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 596 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 597 | return SERVICE_FAILED; |
---|
| 598 | } |
---|
| 599 | if(poDstFeature->SetGeometryDirectly(poDstFeature->GetGeometryRef()->Buffer(bufferDistance,30)) != OGRERR_NONE ) |
---|
| 600 | { |
---|
| 601 | char tmpMsg[1024]; |
---|
| 602 | sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n", |
---|
| 603 | poFeature->GetFID(), poFDefn->GetName() ); |
---|
| 604 | |
---|
| 605 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 606 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 607 | return SERVICE_FAILED; |
---|
| 608 | } |
---|
| 609 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 610 | if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE ) |
---|
| 611 | { |
---|
| 612 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 613 | return SERVICE_FAILED; |
---|
| 614 | } |
---|
| 615 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 616 | } |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | delete poODS; |
---|
| 622 | delete ipoDS; |
---|
| 623 | |
---|
| 624 | char *res1=readVSIFile(conf,pszDestDataSource); |
---|
| 625 | if(res1==NULL) |
---|
| 626 | return SERVICE_FAILED; |
---|
| 627 | setMapInMaps(outputs,"Result","value",res1); |
---|
| 628 | free(res1); |
---|
| 629 | |
---|
| 630 | OGRCleanupAll(); |
---|
| 631 | return SERVICE_SUCCEEDED; |
---|
| 632 | |
---|
[9] | 633 | } |
---|
| 634 | |
---|
[1] | 635 | #ifdef WIN32 |
---|
| 636 | __declspec(dllexport) |
---|
| 637 | #endif |
---|
[9] | 638 | int Boundary(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[491] | 639 | return applyOne(conf,inputs,outputs,&OGRGeometry::Boundary,"http://fooa/gml/3.1.0/polygon.xsd"); |
---|
[9] | 640 | } |
---|
| 641 | |
---|
| 642 | #ifdef WIN32 |
---|
| 643 | __declspec(dllexport) |
---|
| 644 | #endif |
---|
| 645 | int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[491] | 646 | return applyOne(conf,inputs,outputs,&OGRGeometry::ConvexHull,"http://fooa/gml/3.1.0/polygon.xsd"); |
---|
[9] | 647 | } |
---|
| 648 | |
---|
| 649 | |
---|
[491] | 650 | OGRDataSource* loadEntity(maps* conf,maps* inputs,char **filename,const char **oDriver,const char *entity,int iter){ |
---|
| 651 | map* tmp=getMapFromMaps(inputs,entity,"value"); |
---|
| 652 | map* tmp1=getMapFromMaps(inputs,entity,"mimeType"); |
---|
| 653 | *oDriver="GeoJSON"; |
---|
| 654 | sprintf(*filename,"/vsimem/input_%d.json",getpid()+iter); |
---|
| 655 | if(tmp1!=NULL){ |
---|
| 656 | if(strcmp(tmp1->value,"text/xml")==0){ |
---|
| 657 | sprintf(*filename,"/vsimem/input_%d.xml",getpid()+iter); |
---|
| 658 | *oDriver="GML"; |
---|
| 659 | } |
---|
[9] | 660 | } |
---|
[491] | 661 | VSILFILE *ifile=VSIFileFromMemBuffer(*filename,(GByte*)tmp->value,strlen(tmp->value),FALSE); |
---|
| 662 | VSIFCloseL(ifile); |
---|
| 663 | return OGRSFDriverRegistrar::Open(*filename,FALSE); |
---|
[9] | 664 | } |
---|
| 665 | |
---|
[491] | 666 | int applyOneBool(maps*& conf,maps*& inputs,maps*& outputs,OGRBoolean (OGRGeometry::*myFunc)() const){ |
---|
[1] | 667 | #ifdef DEBUG |
---|
[491] | 668 | fprintf(stderr,"\nService internal print\n"); |
---|
[216] | 669 | #endif |
---|
[491] | 670 | OGRRegisterAll(); |
---|
[9] | 671 | |
---|
[1] | 672 | maps* cursor=inputs; |
---|
[491] | 673 | OGRGeometryH geometry,res; |
---|
| 674 | OGRLayer *poDstLayer; |
---|
| 675 | const char *oDriver1; |
---|
| 676 | OGRDataSource *poODS; |
---|
[216] | 677 | #ifdef DEBUG |
---|
[491] | 678 | dumpMaps(cursor); |
---|
[216] | 679 | #endif |
---|
[491] | 680 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
| 681 | if(!tmp){ |
---|
| 682 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon")); |
---|
[26] | 683 | return SERVICE_FAILED; |
---|
| 684 | } |
---|
[491] | 685 | char filename[1024]; |
---|
| 686 | map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); |
---|
| 687 | const char *oDriver; |
---|
| 688 | oDriver="GeoJSON"; |
---|
| 689 | sprintf(filename,"/vsimem/input_%d.json",getpid()); |
---|
| 690 | if(tmp1!=NULL){ |
---|
| 691 | if(strcmp(tmp1->value,"text/xml")==0){ |
---|
| 692 | sprintf(filename,"/vsimem/input_%d.xml",getpid()); |
---|
| 693 | oDriver="GML"; |
---|
| 694 | } |
---|
| 695 | } |
---|
| 696 | VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE); |
---|
| 697 | VSIFCloseL(ifile); |
---|
| 698 | OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE); |
---|
| 699 | char pszDestDataSource[100]; |
---|
| 700 | if( ipoDS == NULL ) |
---|
| 701 | { |
---|
| 702 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 703 | |
---|
| 704 | fprintf( stderr, "FAILURE:\n" |
---|
| 705 | "Unable to open datasource `%s' with the following drivers.\n", |
---|
| 706 | filename ); |
---|
| 707 | |
---|
| 708 | for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 709 | { |
---|
| 710 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetName() ); |
---|
| 711 | } |
---|
| 712 | char tmp[1024]; |
---|
| 713 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename); |
---|
| 714 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 715 | return SERVICE_FAILED; |
---|
| 716 | } |
---|
| 717 | for( int iLayer = 0; iLayer < ipoDS->GetLayerCount(); |
---|
| 718 | iLayer++ ) |
---|
| 719 | { |
---|
| 720 | OGRLayer *poLayer = ipoDS->GetLayer(iLayer); |
---|
| 721 | |
---|
| 722 | if( poLayer == NULL ) |
---|
| 723 | { |
---|
| 724 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
| 725 | iLayer ); |
---|
| 726 | char tmp[1024]; |
---|
| 727 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer); |
---|
| 728 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 729 | return SERVICE_FAILED; |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | OGRFeature *poFeature; |
---|
| 733 | |
---|
| 734 | |
---|
| 735 | while(TRUE){ |
---|
| 736 | OGRFeature *poDstFeature = NULL; |
---|
| 737 | poFeature = poLayer->GetNextFeature(); |
---|
| 738 | if( poFeature == NULL ) |
---|
| 739 | break; |
---|
| 740 | if(poFeature->GetGeometryRef() != NULL){ |
---|
| 741 | // DO SOMETHING HERE !! |
---|
| 742 | if((poFeature->GetGeometryRef()->*myFunc)()==0){ |
---|
| 743 | setMapInMaps(outputs,"Result","value","false"); |
---|
| 744 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 745 | delete ipoDS; |
---|
| 746 | return SERVICE_SUCCEEDED; |
---|
| 747 | } |
---|
| 748 | } |
---|
| 749 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | delete ipoDS; |
---|
| 755 | setMapInMaps(outputs,"Result","value","true"); |
---|
| 756 | |
---|
| 757 | OGRCleanupAll(); |
---|
| 758 | return SERVICE_SUCCEEDED; |
---|
| 759 | } |
---|
| 760 | |
---|
| 761 | #ifdef WIN32 |
---|
| 762 | __declspec(dllexport) |
---|
[216] | 763 | #endif |
---|
[491] | 764 | int IsSimple(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 765 | return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsSimple); |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | #ifdef WIN32 |
---|
| 769 | __declspec(dllexport) |
---|
[216] | 770 | #endif |
---|
[491] | 771 | int IsClosed(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 772 | return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsRing); |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | #ifdef WIN32 |
---|
| 776 | __declspec(dllexport) |
---|
| 777 | #endif |
---|
| 778 | int IsValid(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 779 | return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsValid); |
---|
| 780 | } |
---|
| 781 | |
---|
| 782 | |
---|
| 783 | int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometry* (OGRGeometry::*myFunc)(const OGRGeometry*) const){ |
---|
[216] | 784 | #ifdef DEBUG |
---|
[491] | 785 | fprintf(stderr,"\nService internal print\n"); |
---|
[216] | 786 | #endif |
---|
[491] | 787 | OGRRegisterAll(); |
---|
| 788 | |
---|
| 789 | maps* cursor=inputs; |
---|
| 790 | OGRGeometryH geometry,res; |
---|
| 791 | OGRLayer *poDstLayer; |
---|
| 792 | //const char *oDriver1; |
---|
| 793 | OGRDataSource *poODS; |
---|
[216] | 794 | #ifdef DEBUG |
---|
[491] | 795 | dumpMaps(cursor); |
---|
[216] | 796 | #endif |
---|
[491] | 797 | |
---|
| 798 | char *filename=(char*)malloc(1024*sizeof(char)); |
---|
| 799 | const char *oDriver1; |
---|
| 800 | OGRDataSource* ipoDS1 = loadEntity(conf,inputs,&filename,&oDriver1,"InputEntity1",1); |
---|
| 801 | |
---|
| 802 | char *filename1=(char*)malloc(1024*sizeof(char)); |
---|
| 803 | const char *oDriver2; |
---|
| 804 | OGRDataSource* ipoDS2 = loadEntity(conf,inputs,&filename1,&oDriver2,"InputEntity2",2); |
---|
| 805 | const char *oDriver3; |
---|
| 806 | char pszDestDataSource[100]; |
---|
| 807 | if( ipoDS1 == NULL || ipoDS2 == NULL ) |
---|
| 808 | { |
---|
| 809 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 810 | |
---|
| 811 | fprintf( stderr, "FAILURE:\n" |
---|
| 812 | "Unable to open datasource `%s' with the following drivers.\n", |
---|
| 813 | filename ); |
---|
| 814 | |
---|
| 815 | for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 816 | { |
---|
| 817 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetName() ); |
---|
| 818 | } |
---|
| 819 | char tmp[1024]; |
---|
| 820 | if( ipoDS1 == NULL ) |
---|
| 821 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename); |
---|
| 822 | if( ipoDS2 == NULL ) |
---|
| 823 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename1); |
---|
| 824 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 825 | return SERVICE_FAILED; |
---|
[1] | 826 | } |
---|
[491] | 827 | for( int iLayer = 0; iLayer < ipoDS1->GetLayerCount(); |
---|
| 828 | iLayer++ ) |
---|
| 829 | { |
---|
| 830 | OGRLayer *poLayer1 = ipoDS1->GetLayer(iLayer); |
---|
| 831 | |
---|
| 832 | if( poLayer1 == NULL ) |
---|
| 833 | { |
---|
| 834 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
| 835 | iLayer ); |
---|
| 836 | char tmp[1024]; |
---|
| 837 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer); |
---|
| 838 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 839 | return SERVICE_FAILED; |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | for( int iLayer1 = 0; iLayer1 < ipoDS2->GetLayerCount(); |
---|
| 843 | iLayer1++ ) |
---|
| 844 | { |
---|
| 845 | OGRLayer *poLayer2 = ipoDS2->GetLayer(iLayer1); |
---|
| 846 | |
---|
| 847 | if( poLayer1 == NULL ) |
---|
| 848 | { |
---|
| 849 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
| 850 | iLayer1 ); |
---|
| 851 | char tmp[1024]; |
---|
| 852 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer1); |
---|
| 853 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 854 | return SERVICE_FAILED; |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | OGRFeature *poFeature1,*poFeature2; |
---|
| 858 | |
---|
| 859 | /* -------------------------------------------------------------------- */ |
---|
| 860 | /* Try opening the output datasource as an existing, writable */ |
---|
| 861 | /* -------------------------------------------------------------------- */ |
---|
| 862 | |
---|
| 863 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 864 | OGRSFDriver *poDriver = NULL; |
---|
| 865 | int iDriver; |
---|
| 866 | |
---|
| 867 | map* tmpMap=getMapFromMaps(outputs,"Result","mimeType"); |
---|
| 868 | oDriver3="GeoJSON"; |
---|
| 869 | sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid()); |
---|
| 870 | if(tmpMap!=NULL){ |
---|
| 871 | if(strcmp(tmpMap->value,"text/xml")==0){ |
---|
| 872 | sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid()); |
---|
| 873 | oDriver3="GML"; |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | for( iDriver = 0; |
---|
| 878 | iDriver < poR->GetDriverCount() && poDriver == NULL; |
---|
| 879 | iDriver++ ) |
---|
| 880 | { |
---|
[216] | 881 | #ifdef DEBUG |
---|
[491] | 882 | fprintf(stderr,"D:%s\n",poR->GetDriver(iDriver)->GetName()); |
---|
[216] | 883 | #endif |
---|
[491] | 884 | if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver3) ) |
---|
| 885 | { |
---|
| 886 | poDriver = poR->GetDriver(iDriver); |
---|
| 887 | } |
---|
| 888 | } |
---|
| 889 | |
---|
| 890 | if( poDriver == NULL ) |
---|
| 891 | { |
---|
| 892 | char emessage[8192]; |
---|
| 893 | sprintf( emessage, "Unable to find driver `%s'.\n", oDriver1 ); |
---|
| 894 | sprintf( emessage, "%sThe following drivers are available:\n",emessage ); |
---|
| 895 | |
---|
| 896 | for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 897 | { |
---|
| 898 | sprintf( emessage, "%s -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() ); |
---|
| 899 | } |
---|
| 900 | |
---|
| 901 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 902 | return SERVICE_FAILED; |
---|
| 903 | |
---|
| 904 | } |
---|
| 905 | |
---|
| 906 | if( !poDriver->TestCapability( ODrCCreateDataSource ) ){ |
---|
| 907 | char emessage[1024]; |
---|
| 908 | sprintf( emessage, "%s driver does not support data source creation.\n", |
---|
| 909 | "json" ); |
---|
| 910 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 911 | return SERVICE_FAILED; |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | /* -------------------------------------------------------------------- */ |
---|
| 915 | /* Create the output data source. */ |
---|
| 916 | /* -------------------------------------------------------------------- */ |
---|
| 917 | //map* tpath=getMapFromMaps(conf,"main","tmpPath"); |
---|
| 918 | char **papszDSCO=NULL; |
---|
| 919 | poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO ); |
---|
| 920 | if( poODS == NULL ){ |
---|
| 921 | char emessage[1024]; |
---|
| 922 | sprintf( emessage, "%s driver failed to create %s\n", |
---|
| 923 | "json", pszDestDataSource ); |
---|
| 924 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 925 | return SERVICE_FAILED; |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | /* -------------------------------------------------------------------- */ |
---|
| 929 | /* Create the layer. */ |
---|
| 930 | /* -------------------------------------------------------------------- */ |
---|
| 931 | if( !poODS->TestCapability( ODsCCreateLayer ) ) |
---|
| 932 | { |
---|
| 933 | char emessage[1024]; |
---|
| 934 | sprintf( emessage, |
---|
| 935 | "Layer %s not found, and CreateLayer not supported by driver.", |
---|
| 936 | "Result" ); |
---|
| 937 | setMapInMaps(conf,"lenv","message",emessage); |
---|
| 938 | return SERVICE_FAILED; |
---|
| 939 | } |
---|
| 940 | |
---|
| 941 | //CPLErrorReset(); |
---|
| 942 | |
---|
| 943 | poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL); |
---|
| 944 | if( poDstLayer == NULL ){ |
---|
| 945 | setMapInMaps(conf,"lenv","message","Layer creation failed.\n"); |
---|
| 946 | return SERVICE_FAILED; |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | OGRFeatureDefn *poFDefn = poLayer1->GetLayerDefn(); |
---|
| 950 | int iField; |
---|
| 951 | int hasMmField=0; |
---|
| 952 | |
---|
| 953 | for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ ) |
---|
| 954 | { |
---|
| 955 | OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField); |
---|
| 956 | if (iField >= 0) |
---|
| 957 | poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) ); |
---|
| 958 | else |
---|
| 959 | { |
---|
| 960 | fprintf( stderr, "Field '%s' not found in source layer.\n", |
---|
| 961 | iField ); |
---|
| 962 | return SERVICE_FAILED; |
---|
| 963 | } |
---|
| 964 | } |
---|
| 965 | |
---|
| 966 | while(TRUE){ |
---|
| 967 | OGRFeature *poDstFeature = NULL; |
---|
| 968 | poFeature1 = poLayer1->GetNextFeature(); |
---|
| 969 | if( poFeature1 == NULL ) |
---|
| 970 | break; |
---|
| 971 | while(TRUE){ |
---|
| 972 | poFeature2 = poLayer2->GetNextFeature(); |
---|
| 973 | if( poFeature2 == NULL ) |
---|
| 974 | break; |
---|
| 975 | |
---|
| 976 | if(poFeature1->GetGeometryRef() != NULL && poFeature2->GetGeometryRef() != NULL){ |
---|
| 977 | // DO SOMETHING HERE !! |
---|
| 978 | poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() ); |
---|
| 979 | if( poDstFeature->SetFrom( poFeature2, TRUE ) != OGRERR_NONE ) |
---|
| 980 | { |
---|
| 981 | char tmpMsg[1024]; |
---|
| 982 | sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n", |
---|
| 983 | poFeature2->GetFID(), poFDefn->GetName() ); |
---|
| 984 | |
---|
| 985 | OGRFeature::DestroyFeature( poFeature1 ); |
---|
| 986 | OGRFeature::DestroyFeature( poFeature2 ); |
---|
| 987 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 988 | return SERVICE_FAILED; |
---|
| 989 | } |
---|
| 990 | if(poDstFeature->SetGeometryDirectly((poFeature1->GetGeometryRef()->*myFunc)(poFeature2->GetGeometryRef())) != OGRERR_NONE ) |
---|
| 991 | { |
---|
| 992 | char tmpMsg[1024]; |
---|
| 993 | sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n", |
---|
| 994 | poFeature2->GetFID(), poFDefn->GetName() ); |
---|
| 995 | |
---|
| 996 | OGRFeature::DestroyFeature( poFeature1 ); |
---|
| 997 | OGRFeature::DestroyFeature( poFeature2 ); |
---|
| 998 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 999 | return SERVICE_FAILED; |
---|
| 1000 | } |
---|
| 1001 | OGRFeature::DestroyFeature( poFeature1 ); |
---|
| 1002 | OGRFeature::DestroyFeature( poFeature2 ); |
---|
| 1003 | if(!poDstFeature->GetGeometryRef()->IsEmpty()) |
---|
| 1004 | if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE ) |
---|
| 1005 | { |
---|
| 1006 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 1007 | return SERVICE_FAILED; |
---|
| 1008 | } |
---|
| 1009 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 1010 | } |
---|
| 1011 | } |
---|
| 1012 | } |
---|
| 1013 | } |
---|
| 1014 | } |
---|
| 1015 | |
---|
| 1016 | delete poODS; |
---|
| 1017 | delete ipoDS1; |
---|
| 1018 | delete ipoDS2; |
---|
| 1019 | free(filename); |
---|
| 1020 | free(filename1); |
---|
| 1021 | |
---|
| 1022 | char *res1=readVSIFile(conf,pszDestDataSource); |
---|
| 1023 | if(res1==NULL) |
---|
[26] | 1024 | return SERVICE_FAILED; |
---|
[491] | 1025 | setMapInMaps(outputs,"Result","value",res1); |
---|
| 1026 | free(res1); |
---|
| 1027 | OGRCleanupAll(); |
---|
[1] | 1028 | return SERVICE_SUCCEEDED; |
---|
| 1029 | } |
---|
[9] | 1030 | |
---|
| 1031 | #ifdef WIN32 |
---|
| 1032 | __declspec(dllexport) |
---|
| 1033 | #endif |
---|
| 1034 | int Difference(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[491] | 1035 | return applyTwo(conf,inputs,outputs,&OGRGeometry::Difference); |
---|
[9] | 1036 | } |
---|
[1] | 1037 | |
---|
| 1038 | #ifdef WIN32 |
---|
| 1039 | __declspec(dllexport) |
---|
| 1040 | #endif |
---|
[9] | 1041 | int SymDifference(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[491] | 1042 | return applyTwo(conf,inputs,outputs,&OGRGeometry::SymDifference); |
---|
[9] | 1043 | } |
---|
| 1044 | |
---|
| 1045 | #ifdef WIN32 |
---|
| 1046 | __declspec(dllexport) |
---|
| 1047 | #endif |
---|
| 1048 | int Intersection(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[491] | 1049 | return applyTwo(conf,inputs,outputs,&OGRGeometry::Intersection); |
---|
[9] | 1050 | } |
---|
| 1051 | |
---|
| 1052 | #ifdef WIN32 |
---|
| 1053 | __declspec(dllexport) |
---|
| 1054 | #endif |
---|
| 1055 | int Union(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
[491] | 1056 | return applyTwo(conf,inputs,outputs,&OGRGeometry::Union); |
---|
[9] | 1057 | } |
---|
| 1058 | |
---|
[491] | 1059 | int applyTwoBool(maps*& conf,maps*& inputs,maps*& outputs,OGRBoolean (OGRGeometry::*myFunc)(const OGRGeometry*) const){ |
---|
| 1060 | OGRRegisterAll(); |
---|
| 1061 | |
---|
| 1062 | maps* cursor=inputs; |
---|
| 1063 | OGRGeometryH geometry,res; |
---|
| 1064 | OGRLayer *poDstLayer; |
---|
| 1065 | OGRDataSource *poODS; |
---|
| 1066 | |
---|
| 1067 | char *filename=(char*)malloc(1024*sizeof(char)); |
---|
| 1068 | const char *oDriver1; |
---|
| 1069 | OGRDataSource* ipoDS1 = loadEntity(conf,inputs,&filename,&oDriver1,"InputEntity1",1); |
---|
| 1070 | |
---|
| 1071 | char *filename1=(char*)malloc(1024*sizeof(char)); |
---|
| 1072 | const char *oDriver2; |
---|
| 1073 | OGRDataSource* ipoDS2 = loadEntity(conf,inputs,&filename1,&oDriver2,"InputEntity2",2); |
---|
| 1074 | const char *oDriver3; |
---|
| 1075 | char pszDestDataSource[100]; |
---|
| 1076 | if( ipoDS1 == NULL || ipoDS2 == NULL ) |
---|
| 1077 | { |
---|
| 1078 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 1079 | |
---|
| 1080 | fprintf( stderr, "FAILURE:\n" |
---|
| 1081 | "Unable to open datasource `%s' with the following drivers.\n", |
---|
| 1082 | filename ); |
---|
| 1083 | |
---|
| 1084 | for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 1085 | { |
---|
| 1086 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetName() ); |
---|
| 1087 | } |
---|
| 1088 | char tmp[1024]; |
---|
| 1089 | if( ipoDS1 == NULL ) |
---|
| 1090 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename); |
---|
| 1091 | if( ipoDS2 == NULL ) |
---|
| 1092 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename1); |
---|
| 1093 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 1094 | return SERVICE_FAILED; |
---|
| 1095 | } |
---|
| 1096 | for( int iLayer = 0; iLayer < ipoDS1->GetLayerCount(); |
---|
| 1097 | iLayer++ ) |
---|
| 1098 | { |
---|
| 1099 | OGRLayer *poLayer1 = ipoDS1->GetLayer(iLayer); |
---|
| 1100 | |
---|
| 1101 | if( poLayer1 == NULL ) |
---|
| 1102 | { |
---|
| 1103 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
| 1104 | iLayer ); |
---|
| 1105 | char tmp[1024]; |
---|
| 1106 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer); |
---|
| 1107 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 1108 | return SERVICE_FAILED; |
---|
| 1109 | } |
---|
| 1110 | |
---|
| 1111 | for( int iLayer1 = 0; iLayer1 < ipoDS2->GetLayerCount(); |
---|
| 1112 | iLayer1++ ) |
---|
| 1113 | { |
---|
| 1114 | OGRLayer *poLayer2 = ipoDS2->GetLayer(iLayer1); |
---|
| 1115 | |
---|
| 1116 | if( poLayer1 == NULL ) |
---|
| 1117 | { |
---|
| 1118 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
| 1119 | iLayer1 ); |
---|
| 1120 | char tmp[1024]; |
---|
| 1121 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer1); |
---|
| 1122 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 1123 | return SERVICE_FAILED; |
---|
| 1124 | } |
---|
| 1125 | |
---|
| 1126 | OGRFeature *poFeature1,*poFeature2; |
---|
| 1127 | |
---|
| 1128 | |
---|
| 1129 | while(TRUE){ |
---|
| 1130 | OGRFeature *poDstFeature = NULL; |
---|
| 1131 | poFeature1 = poLayer1->GetNextFeature(); |
---|
| 1132 | if( poFeature1 == NULL ) |
---|
| 1133 | break; |
---|
| 1134 | while(TRUE){ |
---|
| 1135 | poFeature2 = poLayer2->GetNextFeature(); |
---|
| 1136 | if( poFeature2 == NULL ) |
---|
| 1137 | break; |
---|
| 1138 | if(poFeature1->GetGeometryRef() != NULL && poFeature2->GetGeometryRef() != NULL){ |
---|
| 1139 | // DO SOMETHING HERE !! |
---|
| 1140 | if((poFeature1->GetGeometryRef()->*myFunc)(poFeature2->GetGeometryRef())==0){ |
---|
| 1141 | setMapInMaps(outputs,"Result","value","false"); |
---|
| 1142 | OGRFeature::DestroyFeature( poFeature1 ); |
---|
| 1143 | OGRFeature::DestroyFeature( poFeature2 ); |
---|
| 1144 | delete ipoDS1; |
---|
| 1145 | delete ipoDS2; |
---|
| 1146 | free(filename); |
---|
| 1147 | free(filename1); |
---|
| 1148 | return SERVICE_SUCCEEDED; |
---|
| 1149 | } |
---|
| 1150 | } |
---|
| 1151 | OGRFeature::DestroyFeature( poFeature2 ); |
---|
| 1152 | } |
---|
| 1153 | OGRFeature::DestroyFeature( poFeature1 ); |
---|
| 1154 | } |
---|
| 1155 | } |
---|
| 1156 | } |
---|
| 1157 | |
---|
| 1158 | delete ipoDS1; |
---|
| 1159 | delete ipoDS2; |
---|
| 1160 | free(filename); |
---|
| 1161 | free(filename1); |
---|
| 1162 | |
---|
| 1163 | setMapInMaps(outputs,"Result","value","true"); |
---|
| 1164 | |
---|
| 1165 | OGRCleanupAll(); |
---|
| 1166 | return SERVICE_SUCCEEDED; |
---|
| 1167 | } |
---|
| 1168 | |
---|
| 1169 | |
---|
[9] | 1170 | #ifdef WIN32 |
---|
| 1171 | __declspec(dllexport) |
---|
| 1172 | #endif |
---|
[491] | 1173 | int Equals(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1174 | return applyTwoBool(conf,inputs,outputs,(OGRBoolean (OGRGeometry::*)(const OGRGeometry *) const)&OGRGeometry::Equals); |
---|
| 1175 | } |
---|
| 1176 | |
---|
| 1177 | #ifdef WIN32 |
---|
| 1178 | __declspec(dllexport) |
---|
| 1179 | #endif |
---|
| 1180 | int Disjoint(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1181 | return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Disjoint); |
---|
| 1182 | } |
---|
| 1183 | |
---|
| 1184 | #ifdef WIN32 |
---|
| 1185 | __declspec(dllexport) |
---|
| 1186 | #endif |
---|
| 1187 | int Touches(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1188 | return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Touches); |
---|
| 1189 | } |
---|
| 1190 | |
---|
| 1191 | #ifdef WIN32 |
---|
| 1192 | __declspec(dllexport) |
---|
| 1193 | #endif |
---|
| 1194 | int Crosses(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1195 | return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Crosses); |
---|
| 1196 | } |
---|
| 1197 | |
---|
| 1198 | #ifdef WIN32 |
---|
| 1199 | __declspec(dllexport) |
---|
| 1200 | #endif |
---|
| 1201 | int Within(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1202 | return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Within); |
---|
| 1203 | } |
---|
| 1204 | |
---|
| 1205 | #ifdef WIN32 |
---|
| 1206 | __declspec(dllexport) |
---|
| 1207 | #endif |
---|
| 1208 | int Contains(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1209 | return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Contains); |
---|
| 1210 | } |
---|
| 1211 | |
---|
| 1212 | #ifdef WIN32 |
---|
| 1213 | __declspec(dllexport) |
---|
| 1214 | #endif |
---|
| 1215 | int Overlaps(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1216 | return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Overlaps); |
---|
| 1217 | } |
---|
| 1218 | |
---|
| 1219 | #ifdef WIN32 |
---|
| 1220 | __declspec(dllexport) |
---|
| 1221 | #endif |
---|
| 1222 | int Intersects(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1223 | return applyTwoBool(conf,inputs,outputs,(OGRBoolean (OGRGeometry::*)(const OGRGeometry *) const)&OGRGeometry::Intersects); |
---|
| 1224 | } |
---|
| 1225 | |
---|
| 1226 | #ifdef WIN32 |
---|
| 1227 | __declspec(dllexport) |
---|
| 1228 | #endif |
---|
[1] | 1229 | int Distance(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1230 | #ifdef DEBUG |
---|
| 1231 | fprintf(stderr,"\nService internal print1\n"); |
---|
| 1232 | #endif |
---|
| 1233 | fflush(stderr); |
---|
| 1234 | maps* cursor=inputs; |
---|
| 1235 | OGRGeometryH geometry1,geometry2; |
---|
| 1236 | double res; |
---|
| 1237 | { |
---|
| 1238 | map* tmp=getMapFromMaps(inputs,"InputEntity1","value"); |
---|
| 1239 | map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType"); |
---|
| 1240 | #ifdef DEBUG |
---|
| 1241 | fprintf(stderr,"MY MAP\n"); |
---|
| 1242 | dumpMap(tmp1); |
---|
| 1243 | dumpMaps(inputs); |
---|
| 1244 | fprintf(stderr,"MY MAP\n"); |
---|
| 1245 | #endif |
---|
| 1246 | if(tmp1!=NULL){ |
---|
| 1247 | if(strncmp(tmp1->value,"application/json",16)==0) |
---|
| 1248 | geometry1=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
| 1249 | else |
---|
| 1250 | geometry1=createGeometryFromGML(conf,tmp->value); |
---|
| 1251 | } |
---|
| 1252 | else |
---|
| 1253 | geometry1=createGeometryFromGML(conf,tmp->value); |
---|
| 1254 | } |
---|
[26] | 1255 | if(geometry1==NULL){ |
---|
[36] | 1256 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1.")); |
---|
[26] | 1257 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
| 1258 | return SERVICE_FAILED; |
---|
| 1259 | } |
---|
[1] | 1260 | { |
---|
| 1261 | map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); |
---|
| 1262 | map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType"); |
---|
| 1263 | #ifdef DEBUG |
---|
| 1264 | fprintf(stderr,"MY MAP\n"); |
---|
| 1265 | dumpMap(tmp1); |
---|
| 1266 | dumpMaps(inputs); |
---|
| 1267 | fprintf(stderr,"MY MAP\n"); |
---|
| 1268 | #endif |
---|
| 1269 | if(tmp1!=NULL){ |
---|
| 1270 | if(strncmp(tmp1->value,"application/json",16)==0) |
---|
| 1271 | geometry2=OGR_G_CreateGeometryFromJson(tmp->value); |
---|
| 1272 | else |
---|
| 1273 | geometry2=createGeometryFromGML(conf,tmp->value); |
---|
| 1274 | } |
---|
| 1275 | else |
---|
| 1276 | geometry2=createGeometryFromGML(conf,tmp->value); |
---|
| 1277 | } |
---|
[26] | 1278 | if(geometry2==NULL){ |
---|
[36] | 1279 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2.")); |
---|
[26] | 1280 | fprintf(stderr,"SERVICE FAILED !\n"); |
---|
| 1281 | return SERVICE_FAILED; |
---|
| 1282 | } |
---|
| 1283 | res=OGR_G_Distance(geometry1,geometry2); |
---|
[1] | 1284 | char tmpres[100]; |
---|
[55] | 1285 | sprintf(tmpres,"%f",res); |
---|
[26] | 1286 | setMapInMaps(outputs,"Distance","value",tmpres); |
---|
| 1287 | setMapInMaps(outputs,"Distance","dataType","float"); |
---|
[1] | 1288 | #ifdef DEBUG |
---|
| 1289 | dumpMaps(outputs); |
---|
| 1290 | fprintf(stderr,"\nService internal print\n===\n"); |
---|
| 1291 | #endif |
---|
| 1292 | return SERVICE_SUCCEEDED; |
---|
| 1293 | } |
---|
| 1294 | |
---|
[9] | 1295 | #ifdef WIN32 |
---|
| 1296 | __declspec(dllexport) |
---|
| 1297 | #endif |
---|
[1] | 1298 | int GetArea(maps*& conf,maps*& inputs,maps*& outputs){ |
---|
| 1299 | fprintf(stderr,"GETAREA \n"); |
---|
| 1300 | double res; |
---|
| 1301 | /** |
---|
[26] | 1302 | * Extract Geometry from the InputPolygon value |
---|
[1] | 1303 | */ |
---|
[26] | 1304 | OGRGeometryH geometry; |
---|
| 1305 | map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); |
---|
| 1306 | if(tmp==NULL){ |
---|
[36] | 1307 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon")); |
---|
[26] | 1308 | return SERVICE_FAILED; |
---|
| 1309 | } |
---|
[1] | 1310 | fprintf(stderr,"geometry creation %s \n",tmp->value); |
---|
[26] | 1311 | geometry=createGeometryFromGML(conf,tmp->value); |
---|
| 1312 | if(geometry==NULL){ |
---|
[36] | 1313 | setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry from InputPolygon")); |
---|
[26] | 1314 | return SERVICE_FAILED; |
---|
| 1315 | } |
---|
[1] | 1316 | fprintf(stderr,"geometry created %s \n",tmp->value); |
---|
[491] | 1317 | res=OGR_G_Area(geometry); |
---|
[1] | 1318 | fprintf(stderr,"area %d \n",res); |
---|
| 1319 | /** |
---|
[26] | 1320 | * Filling the outputs |
---|
[1] | 1321 | */ |
---|
| 1322 | char tmp1[100]; |
---|
[55] | 1323 | sprintf(tmp1,"%f",res); |
---|
[26] | 1324 | setMapInMaps(outputs,"Area","value",tmp1); |
---|
| 1325 | setMapInMaps(outputs,"Area","dataType","float"); |
---|
[1] | 1326 | #ifdef DEBUG |
---|
| 1327 | dumpMaps(outputs); |
---|
| 1328 | #endif |
---|
| 1329 | return SERVICE_SUCCEEDED; |
---|
| 1330 | } |
---|
| 1331 | |
---|
| 1332 | } |
---|