- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-services/ogr/base-vect-ops/service.c
r26 r9 74 74 char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char)); 75 75 sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2); 76 //strdup(strstr((char*)xmlbuff,"?>")+2); 76 77 xmlXPathFreeObject(xpathObj); 77 78 xmlXPathFreeContext(xpathCtx); … … 86 87 free(tmp); 87 88 if(res==NULL){ 88 setMapInMaps(conf,"lenv","message","Unable to call OGR_G_CreatFromGML"); 89 return NULL; 89 map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML"); 90 addToMap(tmp,"code","NoApplicableCode"); 91 printExceptionReportResponse(conf,tmp); 92 exit(0); 90 93 } 91 94 else 92 return res; 95 return res;//OGR_G_CreateFromGML(tmp); 93 96 } 94 97 … … 105 108 fprintf(stderr,"Tolerance for Simplify %f",tolerance); 106 109 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 107 if(!tmp){ 108 setMapInMaps(conf,"lenv","message","Unagle to parse the input geometry from InputPolygon"); 110 if(!tmp) 109 111 return SERVICE_FAILED; 110 } 111 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); 112 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime"); 112 113 if(tmp1!=NULL){ 113 114 if(strncmp(tmp1->value,"text/js",7)==0 || 114 strncmp(tmp1->value,"application/json", 16)==0)115 strncmp(tmp1->value,"application/json",7)==0) 115 116 geometry=OGR_G_CreateGeometryFromJson(tmp->value); 116 117 else 117 118 geometry=createGeometryFromGML(conf,tmp->value); 118 119 } 119 else{ 120 setMapInMaps(conf,"lenv","message","Unable to find any geometry for InputPolygon"); 121 return SERVICE_FAILED; 122 } 123 if(geometry==NULL){ 124 setMapInMaps(conf,"lenv","message","Unagle to parse the input geometry from InputPolygon"); 125 return SERVICE_FAILED; 126 } 127 fprintf(stderr,"Create GEOSGeometry object"); 120 else 121 geometry=createGeometryFromGML(conf,tmp->value); 128 122 GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS(); 129 123 GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance); 130 124 res=OGRGeometryFactory::createFromGEOS(gres); 131 tmp1=getMapFromMaps(outputs,"Result","mimeType");132 125 if(tmp1!=NULL){ 133 126 if(strncmp(tmp1->value,"text/js",7)==0 || 134 127 strncmp(tmp1->value,"application/json",16)==0){ 135 char *tmpS=OGR_G_ExportToJson(res); 136 setMapInMaps(outputs,"Result","value",tmpS); 137 setMapInMaps(outputs,"Result","mimeType","text/plain"); 138 setMapInMaps(outputs,"Result","encoding","UTF-8"); 139 free(tmpS); 128 outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value)); 129 addMapToMap(&outputs->content,createMap("mimeType","text/plain")); 130 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 140 131 } 141 132 else{ 142 char *tmpS=OGR_G_ExportToGML(res); 143 setMapInMaps(outputs,"Result","value",tmpS); 144 setMapInMaps(outputs,"Result","mimeType","text/xml"); 145 setMapInMaps(outputs,"Result","encoding","UTF-8"); 146 setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd"); 147 free(tmpS); 133 outputs->content=createMap("value",OGR_G_ExportToGML(res)); 134 addMapToMap(&outputs->content,createMap("mimeType","text/xml")); 135 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 136 addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd")); 148 137 } 149 138 }else{ 150 char *tmpS=OGR_G_ExportToJson(tmp->value); 151 setMapInMaps(outputs,"Result","value",tmpS); 152 setMapInMaps(outputs,"Result","mimeType","text/plain"); 153 setMapInMaps(outputs,"Result","encoding","UTF-8"); 154 free(tmpS); 139 outputs->content=createMap("value",OGR_G_ExportToJson(res)); 140 addMapToMap(&outputs->content,createMap("mimeType","text/plain")); 141 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 155 142 } 156 143 outputs->next=NULL; … … 191 178 else 192 179 geometry=createGeometryFromGML(conf,tmp->value); 193 if(geometry==NULL)194 return SERVICE_FAILED;195 180 res=(*myFunc)(geometry); 196 181 fprintf(stderr,"Service internal print \n"); … … 204 189 if(strncmp(tmp_2->value,"text/js",7)==0 || 205 190 strncmp(tmp_2->value,"application/json",16)==0){ 206 char *t mpS=OGR_G_ExportToJson(res);207 setMapInMaps(outputs,"Result","value",tmpS);208 setMapInMaps(outputs,"Result","mimeType","text/plain");209 setMapInMaps(outputs,"Result","encoding","UTF-8");210 free(tmpS);191 char *tres=OGR_G_ExportToJson(res); 192 addToMap(outputs->content,"value",tres); 193 free(tres); 194 addToMap(outputs->content,"mimeType","text/plain"); 195 addToMap(outputs->content,"encoding","UTF-8"); 211 196 } 212 197 else{ 213 char *tmpS=OGR_G_ExportToGML(res); 214 setMapInMaps(outputs,"Result","value",tmpS); 215 setMapInMaps(outputs,"Result","mimeType","text/plain"); 216 setMapInMaps(outputs,"Result","encoding","UTF-8"); 217 free(tmpS); 218 198 char *tres=OGR_G_ExportToGML(res); 199 addToMap(outputs->content,"value",tres); 200 free(tres); 219 201 } 220 202 }else{ 221 char *t mpS=OGR_G_ExportToJson(res);222 setMapInMaps(outputs,"Result","value",tmpS);223 setMapInMaps(outputs,"Result","mimeType","text/plain");224 setMapInMaps(outputs,"Result","encoding","UTF-8");225 free(tmpS);203 char *tres=OGR_G_ExportToJson(res); 204 addToMap(outputs->content,"value",tres); 205 free(tres); 206 addToMap(outputs->content,"mimeType","text/plain"); 207 addToMap(outputs->content,"encoding","UTF-8"); 226 208 } 227 209 outputs->next=NULL; … … 253 235 else 254 236 geometry=createGeometryFromGML(conf,tmp->value); 255 if(geometry==NULL){ 256 setMapInMaps(conf,"lenv","message","Unable to parse input geometry"); 257 return SERVICE_FAILED; 258 } 259 double bufferDistance; 237 int bufferDistance=1; 260 238 tmp=getMapFromMaps(inputs,"BufferDistance","value"); 261 if(tmp==NULL){ 262 bufferDistance=atof("10.0"); 263 } 264 else 265 bufferDistance=atof(tmp->value); 239 if(tmp!=NULL) 240 bufferDistance=atoi(tmp->value); 266 241 res=OGR_G_Buffer(geometry,bufferDistance,30); 267 242 tmp1=getMapFromMaps(outputs,"Result","mimeType"); 268 243 if(strncmp(tmp1->value,"application/json",16)==0){ 269 char *tmpS=OGR_G_ExportToJson(res); 270 setMapInMaps(outputs,"Result","value",tmpS); 271 setMapInMaps(outputs,"Result","mimeType","text/plain"); 272 setMapInMaps(outputs,"Result","encoding","UTF-8"); 273 free(tmpS); 244 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 245 addToMap(outputs->content,"mimeType","text/plain"); 274 246 } 275 247 else{ 276 char *tmpS=OGR_G_ExportToGML(res); 277 setMapInMaps(outputs,"Result","value",tmpS); 278 setMapInMaps(outputs,"Result","mimeType","text/xml"); 279 setMapInMaps(outputs,"Result","encoding","UTF-8"); 280 setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd"); 248 addToMap(outputs->content,"value",OGR_G_ExportToGML(res)); 281 249 } 282 250 outputs->next=NULL; … … 286 254 } 287 255 256 /* int Buffer(maps*& conf,maps*& inputs,maps*& outputs){ 257 #ifdef DEBUG 258 fprintf(stderr,"\nService internal print\n"); 259 #endif 260 maps* cursor=inputs; 261 OGRGeometryH geometry,res; 262 int bufferDistance; 263 if(cursor!=NULL){ 264 #ifdef DEBUG 265 fprintf(stderr,"\nService internal print\n"); 266 dumpMaps(cursor); 267 fprintf(stderr,"\nService internal print\n"); 268 dumpMaps(inputs); 269 fprintf(stderr,"\nService internal print\n"); 270 #endif 271 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 272 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); 273 if(tmp1!=NULL){ 274 if(strncmp(tmp1->value,"application/json",16)==0 || 275 strncmp(tmp1->value,"text/js",7)==0) 276 geometry=OGR_G_CreateGeometryFromJson(tmp->value); 277 else 278 geometry=createGeometryFromGML(conf,tmp->value); 279 } 280 else 281 geometry=createGeometryFromGML(conf,tmp->value); 282 } 283 if(cursor!=NULL){ 284 map* tmp=getMapFromMaps(cursor,"BufferDistance","value"); 285 if(tmp==NULL){ 286 bufferDistance=10; 287 } 288 else 289 bufferDistance=atoi(tmp->value); 290 #ifdef DEBUG 291 fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance); 292 #endif 293 } 294 #ifdef DEBUG 295 dumpMaps(outputs); 296 #endif 297 map* tmp=getMapFromMaps(outputs,"Result","mimeType"); 298 res=OGR_G_Buffer(geometry,bufferDistance,30); 299 #ifdef DEBUG 300 dumpMap(tmp); 301 #endif 302 if(tmp!=NULL){ 303 #ifdef DEBUG 304 dumpMap(tmp); 305 #endif 306 if(strncmp(tmp->value,"application/json",16)==0){ 307 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 308 addToMap(outputs->content,"mimeType","text/plain"); 309 addToMap(outputs->content,"encoding","UTF-8"); 310 } 311 else if(strcmp(tmp->value,"text/xml")==0){ 312 xmlInitParser(); 313 xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value)); 314 xmlChar *xmlbuff; 315 int buffersize; 316 char *buff=OGR_G_ExportToGML(res); 317 addToMap(outputs->content,"value",buff); 318 map* tmp1=getMapFromMaps(outputs,"Result","encoding"); 319 if(tmp1!=NULL) 320 addToMap(outputs->content,"encoding",tmp1->value); 321 else 322 addToMap(outputs->content,"encoding","UTF-8"); 323 xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); 324 xmlFree(xmlbuff); 325 xmlFreeDoc(doc); 326 xmlCleanupParser(); 327 } 328 else{ 329 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 330 addToMap(outputs->content,"mimeType","text/plain"); 331 addToMap(outputs->content,"encoding","UTF-8"); 332 outputs->next=NULL; 333 } 334 outputs->next=NULL; 335 } 336 else{ 337 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 338 addToMap(outputs->content,"mimeType","text/plain"); 339 addToMap(outputs->content,"encoding","UTF-8"); 340 outputs->next=NULL; 341 } 342 outputs->next=NULL; 343 #ifdef DEBUG 344 dumpMaps(outputs); 345 fprintf(stderr,"\nService internal print\n===\n"); 346 #endif 347 OGR_G_DestroyGeometry(geometry); 348 OGR_G_DestroyGeometry(res); 349 return SERVICE_SUCCEEDED; 350 } 351 */ 352 288 353 #ifdef WIN32 289 354 __declspec(dllexport) … … 322 387 #ifdef DEBUG 323 388 fprintf(stderr,"\nService internal print1\n"); 389 #endif 324 390 fflush(stderr); 325 #endif326 fprintf(stderr,"\nService internal print1\n");327 dumpMaps(inputs);328 fprintf(stderr,"\nService internal print1\n");329 391 330 392 maps* cursor=inputs; … … 343 405 geometry1=createGeometryFromGML(conf,tmp->value); 344 406 } 345 if(geometry1==NULL){346 setMapInMaps(conf,"lenv","message","Unable to parse input geometry for InputEntity1.");347 fprintf(stderr,"SERVICE FAILED !\n");348 return SERVICE_FAILED;349 }350 fprintf(stderr,"\nService internal print1 InputEntity1\n");351 407 { 352 408 map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); 353 409 map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType"); 354 //#ifdef DEBUG 355 fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16)); 356 //dumpMap(tmp); 410 #ifdef DEBUG 357 411 fprintf(stderr,"MY MAP\n"); 358 ///#endif 359 fprintf(stderr,"\nService internal print1 InputEntity2\n"); 412 dumpMap(tmp1); 413 fprintf(stderr,"MY MAP\n"); 414 #endif 360 415 if(tmp1!=NULL){ 361 if(strncmp(tmp1->value,"application/json",16)==0){ 362 fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n"); 416 if(strncmp(tmp1->value,"application/json",16)==0) 363 417 geometry2=OGR_G_CreateGeometryFromJson(tmp->value); 364 } 365 else{ 366 fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n"); 418 else 367 419 geometry2=createGeometryFromGML(conf,tmp->value); 368 }369 420 } 370 421 else 371 422 geometry2=createGeometryFromGML(conf,tmp->value); 372 fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n"); 373 } 374 fprintf(stderr,"\nService internal print1 InputEntity2 Final\n"); 375 if(geometry2==NULL){ 376 setMapInMaps(conf,"lenv","message","Unable to parse input geometry for InputEntity2."); 377 fprintf(stderr,"SERVICE FAILED !\n"); 378 return SERVICE_FAILED; 379 } 380 fprintf(stderr,"\nService internal print1\n"); 423 } 381 424 res=(*myFunc)(geometry1,geometry2); 382 fprintf(stderr,"\nService internal print1\n"); 383 char *tmpS=OGR_G_ExportToJson(res); 384 setMapInMaps(outputs,"Result","value",tmpS); 385 setMapInMaps(outputs,"Result","mimeType","text/plain"); 386 setMapInMaps(outputs,"Result","encoding","UTF-8"); 387 free(tmpS); 425 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 426 addToMap(outputs->content,"mimeType","text/plain"); 427 addToMap(outputs->content,"encoding","UTF-8"); 428 outputs->next=NULL; 388 429 OGR_G_DestroyGeometry(geometry1); 389 430 OGR_G_DestroyGeometry(geometry2); … … 428 469 #endif 429 470 fflush(stderr); 471 430 472 maps* cursor=inputs; 431 473 OGRGeometryH geometry1,geometry2; … … 449 491 geometry1=createGeometryFromGML(conf,tmp->value); 450 492 } 451 if(geometry1==NULL){452 setMapInMaps(conf,"lenv","message","Unable to parse input geometry for InputEntity1.");453 fprintf(stderr,"SERVICE FAILED !\n");454 return SERVICE_FAILED;455 }456 493 { 457 494 map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); … … 472 509 geometry2=createGeometryFromGML(conf,tmp->value); 473 510 } 474 if(geometry2==NULL){ 475 setMapInMaps(conf,"lenv","message","Unable to parse input geometry for InputEntity2."); 476 fprintf(stderr,"SERVICE FAILED !\n"); 477 return SERVICE_FAILED; 478 } 479 res=OGR_G_Distance(geometry1,geometry2); 511 res=OGR_G_Distance(geometry1,geometry2); 512 outputs=(maps*)malloc(sizeof(maps*)); 513 outputs->name="Distance"; 480 514 char tmpres[100]; 481 515 sprintf(tmpres,"%d",res); 482 setMapInMaps(outputs,"Distance","value",tmpres); 483 setMapInMaps(outputs,"Distance","dataType","float"); 516 outputs->content=createMap("value",tmpres); 517 addMapToMap(&outputs->content,createMap("datatype","float")); 518 outputs->next=NULL; 484 519 #ifdef DEBUG 485 520 dumpMaps(outputs); … … 496 531 double res; 497 532 /** 498 * Extract Geometry from the Input Polygonvalue533 * Extract Geometry from the InputEntity1 value 499 534 */ 500 OGRGeometryH geometry; 501 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 502 if(tmp==NULL){ 503 setMapInMaps(conf,"lenv","message","Unable to parse input geometry from InputPolygon"); 504 return SERVICE_FAILED; 505 } 535 OGRGeometryH geometry1; 536 map* tmp=getMapFromMaps(inputs,"InputEntity1","value"); 506 537 fprintf(stderr,"geometry creation %s \n",tmp->value); 507 geometry=createGeometryFromGML(conf,tmp->value); 508 if(geometry==NULL){ 509 setMapInMaps(conf,"lenv","message","Unable to parse input geometry from InputPolygon"); 510 return SERVICE_FAILED; 511 } 538 geometry1=createGeometryFromGML(conf,tmp->value); 512 539 fprintf(stderr,"geometry created %s \n",tmp->value); 513 res=OGR_G_GetArea(geometry );540 res=OGR_G_GetArea(geometry1); 514 541 fprintf(stderr,"area %d \n",res); 515 542 /** 516 * Filling the outputs543 * Creating the outputs 517 544 */ 545 outputs=(maps*)malloc(sizeof(maps*)); 546 outputs->name="Area"; 518 547 char tmp1[100]; 519 548 sprintf(tmp1,"%d",res); 520 setMapInMaps(outputs,"Area","value",tmp1); 521 setMapInMaps(outputs,"Area","dataType","float"); 549 outputs->content=createMap("value",tmp1); 550 addMapToMap(&outputs->content,createMap("datatype","float")); 551 outputs->next=NULL; 522 552 #ifdef DEBUG 523 553 dumpMaps(outputs);
Note: See TracChangeset
for help on using the changeset viewer.