Changeset 26 for trunk/zoo-services
- Timestamp:
- Sep 24, 2010, 5:11:43 AM (14 years ago)
- Location:
- trunk/zoo-services
- Files:
-
- 7 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-services/ogr/base-vect-ops/Makefile
r9 r26 1 CFLAGS=-I../../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags` `gdal-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG 2 CC=gcc 1 CFLAGS=-I../../../zoo-kernel/ -I./ `xsl-config --cflags` `gdal-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG 2 # if JS_ENABLED flag is set to true in your ZOO-Kernel Makefile then you'll have 3 # uncomment the following line 4 # JS_LDFLAGS=../../../zoo-kernel/ulinet.o ../../../zoo-kernel/service_internal_js.o 3 5 4 cgi-env/ service.zo: service.c5 g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o `gdal-config --libs`6 cgi-env/ogr_service.zo: service.c 7 g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o ${JS_LDFLAGS} `xsl-config --libs` `gdal-config --libs` `geos-config --libs` 6 8 7 9 clean: -
trunk/zoo-services/ogr/base-vect-ops/service.c
r9 r26 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);77 76 xmlXPathFreeObject(xpathObj); 78 77 xmlXPathFreeContext(xpathCtx); … … 87 86 free(tmp); 88 87 if(res==NULL){ 89 map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML"); 90 addToMap(tmp,"code","NoApplicableCode"); 91 printExceptionReportResponse(conf,tmp); 92 exit(0); 88 setMapInMaps(conf,"lenv","message","Unable to call OGR_G_CreatFromGML"); 89 return NULL; 93 90 } 94 91 else 95 return res; //OGR_G_CreateFromGML(tmp);92 return res; 96 93 } 97 94 … … 108 105 fprintf(stderr,"Tolerance for Simplify %f",tolerance); 109 106 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 110 if(!tmp) 111 return SERVICE_FAILED; 112 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime"); 107 if(!tmp){ 108 setMapInMaps(conf,"lenv","message","Unagle to parse the input geometry from InputPolygon"); 109 return SERVICE_FAILED; 110 } 111 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); 113 112 if(tmp1!=NULL){ 114 113 if(strncmp(tmp1->value,"text/js",7)==0 || 115 strncmp(tmp1->value,"application/json", 7)==0)114 strncmp(tmp1->value,"application/json",16)==0) 116 115 geometry=OGR_G_CreateGeometryFromJson(tmp->value); 117 116 else 118 117 geometry=createGeometryFromGML(conf,tmp->value); 119 118 } 120 else 121 geometry=createGeometryFromGML(conf,tmp->value); 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"); 122 128 GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS(); 123 129 GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance); 124 130 res=OGRGeometryFactory::createFromGEOS(gres); 131 tmp1=getMapFromMaps(outputs,"Result","mimeType"); 125 132 if(tmp1!=NULL){ 126 133 if(strncmp(tmp1->value,"text/js",7)==0 || 127 134 strncmp(tmp1->value,"application/json",16)==0){ 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")); 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); 131 140 } 132 141 else{ 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")); 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); 137 148 } 138 149 }else{ 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")); 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); 142 155 } 143 156 outputs->next=NULL; … … 178 191 else 179 192 geometry=createGeometryFromGML(conf,tmp->value); 193 if(geometry==NULL) 194 return SERVICE_FAILED; 180 195 res=(*myFunc)(geometry); 181 196 fprintf(stderr,"Service internal print \n"); … … 189 204 if(strncmp(tmp_2->value,"text/js",7)==0 || 190 205 strncmp(tmp_2->value,"application/json",16)==0){ 191 char *t res=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");206 char *tmpS=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); 196 211 } 197 212 else{ 198 char *tres=OGR_G_ExportToGML(res); 199 addToMap(outputs->content,"value",tres); 200 free(tres); 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 201 219 } 202 220 }else{ 203 char *t res=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");221 char *tmpS=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); 208 226 } 209 227 outputs->next=NULL; … … 235 253 else 236 254 geometry=createGeometryFromGML(conf,tmp->value); 237 int bufferDistance=1; 255 if(geometry==NULL){ 256 setMapInMaps(conf,"lenv","message","Unable to parse input geometry"); 257 return SERVICE_FAILED; 258 } 259 double bufferDistance; 238 260 tmp=getMapFromMaps(inputs,"BufferDistance","value"); 239 if(tmp!=NULL) 240 bufferDistance=atoi(tmp->value); 261 if(tmp==NULL){ 262 bufferDistance=atof("10.0"); 263 } 264 else 265 bufferDistance=atof(tmp->value); 241 266 res=OGR_G_Buffer(geometry,bufferDistance,30); 242 267 tmp1=getMapFromMaps(outputs,"Result","mimeType"); 243 268 if(strncmp(tmp1->value,"application/json",16)==0){ 244 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 245 addToMap(outputs->content,"mimeType","text/plain"); 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); 246 274 } 247 275 else{ 248 addToMap(outputs->content,"value",OGR_G_ExportToGML(res)); 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"); 249 281 } 250 282 outputs->next=NULL; … … 254 286 } 255 287 256 /* int Buffer(maps*& conf,maps*& inputs,maps*& outputs){257 #ifdef DEBUG258 fprintf(stderr,"\nService internal print\n");259 #endif260 maps* cursor=inputs;261 OGRGeometryH geometry,res;262 int bufferDistance;263 if(cursor!=NULL){264 #ifdef DEBUG265 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 #endif271 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 else278 geometry=createGeometryFromGML(conf,tmp->value);279 }280 else281 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 else289 bufferDistance=atoi(tmp->value);290 #ifdef DEBUG291 fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);292 #endif293 }294 #ifdef DEBUG295 dumpMaps(outputs);296 #endif297 map* tmp=getMapFromMaps(outputs,"Result","mimeType");298 res=OGR_G_Buffer(geometry,bufferDistance,30);299 #ifdef DEBUG300 dumpMap(tmp);301 #endif302 if(tmp!=NULL){303 #ifdef DEBUG304 dumpMap(tmp);305 #endif306 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 else322 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 DEBUG344 dumpMaps(outputs);345 fprintf(stderr,"\nService internal print\n===\n");346 #endif347 OGR_G_DestroyGeometry(geometry);348 OGR_G_DestroyGeometry(res);349 return SERVICE_SUCCEEDED;350 }351 */352 353 288 #ifdef WIN32 354 289 __declspec(dllexport) … … 387 322 #ifdef DEBUG 388 323 fprintf(stderr,"\nService internal print1\n"); 389 #endif390 324 fflush(stderr); 325 #endif 326 fprintf(stderr,"\nService internal print1\n"); 327 dumpMaps(inputs); 328 fprintf(stderr,"\nService internal print1\n"); 391 329 392 330 maps* cursor=inputs; … … 405 343 geometry1=createGeometryFromGML(conf,tmp->value); 406 344 } 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"); 407 351 { 408 352 map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); 409 353 map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType"); 410 #ifdef DEBUG 354 //#ifdef DEBUG 355 fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16)); 356 //dumpMap(tmp); 411 357 fprintf(stderr,"MY MAP\n"); 412 dumpMap(tmp1); 413 fprintf(stderr,"MY MAP\n"); 414 #endif 358 ///#endif 359 fprintf(stderr,"\nService internal print1 InputEntity2\n"); 415 360 if(tmp1!=NULL){ 416 if(strncmp(tmp1->value,"application/json",16)==0) 361 if(strncmp(tmp1->value,"application/json",16)==0){ 362 fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n"); 417 363 geometry2=OGR_G_CreateGeometryFromJson(tmp->value); 418 else 364 } 365 else{ 366 fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n"); 419 367 geometry2=createGeometryFromGML(conf,tmp->value); 368 } 420 369 } 421 370 else 422 371 geometry2=createGeometryFromGML(conf,tmp->value); 423 } 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"); 424 381 res=(*myFunc)(geometry1,geometry2); 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; 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); 429 388 OGR_G_DestroyGeometry(geometry1); 430 389 OGR_G_DestroyGeometry(geometry2); … … 469 428 #endif 470 429 fflush(stderr); 471 472 430 maps* cursor=inputs; 473 431 OGRGeometryH geometry1,geometry2; … … 491 449 geometry1=createGeometryFromGML(conf,tmp->value); 492 450 } 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 } 493 456 { 494 457 map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); … … 509 472 geometry2=createGeometryFromGML(conf,tmp->value); 510 473 } 511 res=OGR_G_Distance(geometry1,geometry2); 512 outputs=(maps*)malloc(sizeof(maps*)); 513 outputs->name="Distance"; 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); 514 480 char tmpres[100]; 515 481 sprintf(tmpres,"%d",res); 516 outputs->content=createMap("value",tmpres); 517 addMapToMap(&outputs->content,createMap("datatype","float")); 518 outputs->next=NULL; 482 setMapInMaps(outputs,"Distance","value",tmpres); 483 setMapInMaps(outputs,"Distance","dataType","float"); 519 484 #ifdef DEBUG 520 485 dumpMaps(outputs); … … 531 496 double res; 532 497 /** 533 * Extract Geometry from the Input Entity1value498 * Extract Geometry from the InputPolygon value 534 499 */ 535 OGRGeometryH geometry1; 536 map* tmp=getMapFromMaps(inputs,"InputEntity1","value"); 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 } 537 506 fprintf(stderr,"geometry creation %s \n",tmp->value); 538 geometry1=createGeometryFromGML(conf,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 } 539 512 fprintf(stderr,"geometry created %s \n",tmp->value); 540 res=OGR_G_GetArea(geometry 1);513 res=OGR_G_GetArea(geometry); 541 514 fprintf(stderr,"area %d \n",res); 542 515 /** 543 * Creating the outputs516 * Filling the outputs 544 517 */ 545 outputs=(maps*)malloc(sizeof(maps*));546 outputs->name="Area";547 518 char tmp1[100]; 548 519 sprintf(tmp1,"%d",res); 549 outputs->content=createMap("value",tmp1); 550 addMapToMap(&outputs->content,createMap("datatype","float")); 551 outputs->next=NULL; 520 setMapInMaps(outputs,"Area","value",tmp1); 521 setMapInMaps(outputs,"Area","dataType","float"); 552 522 #ifdef DEBUG 553 523 dumpMaps(outputs);
Note: See TracChangeset
for help on using the changeset viewer.