Changeset 917 for trunk/zoo-project/zoo-kernel/service_internal_ms.c
- Timestamp:
- May 7, 2019, 2:17:08 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
False
/branches/prototype-v0 merged eligible
-
Property
svn:mergeinfo
set to
False
-
trunk/zoo-project/zoo-kernel/service_internal_ms.c
r781 r917 34 34 #include "server_internal.h" 35 35 #include "response_print.h" 36 #include "caching.h" 36 37 37 38 /** … … 76 77 77 78 /** 79 * Return the current publish_id value 80 * @param elem and maps pointer on which the search occur 81 * @return the integer value of the publish_id field, if any, 0 otherwise 82 */ 83 int getPublishedId(maps* elem){ 84 if(elem!=NULL && elem->content!=NULL){ 85 map* myIndex=getMap(elem->content,"published_id"); 86 if(myIndex!=NULL){ 87 return atoi(myIndex->value); 88 } 89 } 90 return 0; 91 } 92 93 /** 78 94 * Add width and height keys to an output maps containing the maximum width 79 95 * and height for displaying the full data extent. … … 87 103 */ 88 104 void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){ 105 int imyIndex=getPublishedId(output); 89 106 double maxWidth=640; 90 107 double maxHeight=480; … … 118 135 #endif 119 136 if(output!=NULL){ 120 addToMap(output->content,"width",sWidth);121 addToMap(output->content,"height",sHeight);137 setMapArray(output->content,"width",imyIndex,sWidth); 138 setMapArray(output->content,"height",imyIndex,sHeight); 122 139 } 123 140 } … … 131 148 */ 132 149 void setReferenceUrl(maps* m,maps* tmpI){ 150 int imyIndex=getPublishedId(tmpI); 151 if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL) 152 return; 133 153 outputMapfile(m,tmpI); 134 154 map *msUrl=getMapFromMaps(m,"main","mapserverAddress"); … … 138 158 exit(-1); 139 159 } 160 if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL) 161 return; 162 int finalProto=-1; 140 163 map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion"); 141 164 map *dataPath=getMapFromMaps(m,"main","dataPath"); 142 165 map *sid=getMapFromMaps(m,"lenv","usid"); 143 map* format=getMap(tmpI->content,"mimeType"); 144 map* rformat=getMap(tmpI->content,"requestedMimeType"); 145 map* width=getMap(tmpI->content,"width"); 146 map* height=getMap(tmpI->content,"height"); 147 map* protoMap=getMap(tmpI->content,"msOgc"); 148 map* versionMap=getMap(tmpI->content,"msOgcVersion"); 149 char options[3][5][25]={ 166 map* format=getMapArray(tmpI->content,"mimeType",imyIndex); 167 map* rformat=getMapArray(tmpI->content,"requestedMimeType",imyIndex); 168 map* width=getMapArray(tmpI->content,"width",imyIndex); 169 map* height=getMapArray(tmpI->content,"height",imyIndex); 170 map* protoMap=getMapArray(tmpI->content,"msOgc",imyIndex); 171 map* versionMap=getMapArray(tmpI->content,"msOgcVersion",imyIndex); 172 map* datatype=getMapArray(tmpI->content,"geodatatype",imyIndex); 173 map* layerName=getMapArray(tmpI->content,"msLayer",imyIndex); 174 char options[4][5][25]={ 150 175 {"WMS","1.3.0","GetMap","layers=%s","wms_extent"}, 151 {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"}, 152 {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"} 176 {"WFS","1.0.0","GetFeature","typename=%s","wcs_extent"}, 177 {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"}, 178 {"WCS","1.0.0","GetCoverage","coverage=%s","wcs_extent"} 153 179 }; 180 map *nbElements=getMapArray(tmpI->content,"nb_features",imyIndex); 181 if(nbElements==NULL) 182 nbElements=getMapArray(tmpI->content,"nb_pixels",imyIndex); 183 if(datatype==NULL || strncmp(datatype->value,"other",5)==0 || (nbElements!=NULL && atoi(nbElements->value)==0)){ 184 map* minNb=getMap(tmpI->content,"minoccurs"); 185 map* useMs=getMap(tmpI->content,"useMapserver"); 186 if((minNb==NULL || atoi(minNb->value)>=1) && useMs!=NULL && strncasecmp(useMs->value,"true",4)==0){ 187 int lIndex=0; 188 maps* lenv=getMaps(m,"lenv"); 189 if(getMapFromMaps(m,"lenv","mapErrorNb")==NULL) 190 setMapInMaps(m,"lenv","mapErrorNb","0"); 191 else{ 192 map* tmpV=getMapFromMaps(m,"lenv","mapErrorNb"); 193 lIndex=atoi(tmpV->value)+1; 194 addIntToMap(lenv->content,"mapErrorNb",lIndex); 195 } 196 setMapInMaps(m,"lenv","mapError","true"); 197 setMapArray(lenv->content,"locator",lIndex,tmpI->name); 198 if(nbElements==NULL) 199 setMapArray(lenv->content,"message",lIndex,_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data.")); 200 else 201 setMapArray(lenv->content,"message",lIndex,_("The ZOO-Kernel was able to retrieve the data but could not access any feature or pixel in te resulting file.")); 202 if(getMapFromMaps(m,"lenv","state")==NULL) 203 errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name); 204 } 205 return; 206 } 154 207 int proto=0; 155 208 if(rformat==NULL){ 156 rformat=getMap (tmpI->content,"mimeType");209 rformat=getMapArray(tmpI->content,"mimeType",imyIndex); 157 210 } 158 211 if(strncasecmp(rformat->value,"text/xml",8)==0) 159 212 proto=1; 160 if(strncasecmp(rformat->value,"image/tiff",10)==0) 213 if(strncasecmp(rformat->value,"image/tiff",10)==0 || 214 strncasecmp(rformat->value,"image/geotiff",10)==0) 161 215 proto=2; 216 int hasFormat=-1; 162 217 if(protoMap!=NULL){ 163 if(strncasecmp(protoMap->value,"WMS",3)==0) 218 hasFormat=1; 219 if(strncasecmp(protoMap->value,"WMS",3)==0){ 164 220 proto=0; 221 rformat=createMap("value","image/png"); 222 } 165 223 else{ 166 if(strncasecmp(protoMap->value,"WFS",3)==0) 224 if(strncasecmp(protoMap->value,"WFS",3)==0){ 167 225 proto=1; 168 else 226 rformat=createMap("value","text/xml"); 227 } 228 else { 169 229 proto=2; 230 rformat=createMap("value","image/tiff"); 231 } 170 232 } 171 233 } … … 178 240 } 179 241 180 map* extent=getMap(tmpI->content,options[proto][4]); 181 map* crs=getMap(tmpI->content,"crs"); 242 243 map* extent=getMapArray(tmpI->content,options[proto][4],imyIndex); 244 map* crs=getMapArray(tmpI->content,"crs",imyIndex); 182 245 int hasCRS=1; 183 246 if(crs==NULL){ … … 189 252 } 190 253 char layers[128]; 191 sprintf(layers,options[proto][3],tmpI->name); 192 193 char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(format->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char)); 254 if(layerName==NULL) 255 sprintf(layers,options[proto][3],tmpI->name); 256 else 257 sprintf(layers,options[proto][3],layerName->value); 258 259 if(format==NULL || width==NULL || height==NULL || extent==NULL){ 260 char tmpStr[1024]; 261 sprintf(tmpStr,_("Unable to create the mapfile for %s because of missing values."),tmpI->name); 262 errorException (m, tmpStr, 263 "InternalError", NULL); 264 exit(-1); 265 return; 266 } 267 268 if(proto==0){ 269 hasFormat=1; 270 rformat=createMap("mimeType","image/png"); 271 }else{ 272 if(proto==1){ 273 rformat=createMap("mimeType","text/xml"); 274 hasFormat=1; 275 } 276 else 277 if(proto==2){ 278 rformat=createMap("mimeType","image/tiff"); 279 hasFormat=1; 280 finalProto=1; 281 } 282 } 283 284 char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(rformat->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char)); 285 194 286 195 287 if(proto>0){ 288 if(proto==2) 289 finalProto=1; 196 290 sprintf(webService_url, 197 "%s?map=%s/%s_% s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",291 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", 198 292 msUrl->value, 199 293 dataPath->value, 200 294 tmpI->name, 295 imyIndex, 201 296 sid->value, 202 297 options[proto][2], … … 208 303 crs->value 209 304 ); 305 if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ 306 setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url); 307 } 308 else{ 309 setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url); 310 } 311 proto=0; 312 freeMap(&rformat); 313 free(rformat); 314 rformat=createMap("mimeType","image/png"); 210 315 } 211 316 else{ 212 317 sprintf(webService_url, 213 "%s?map=%s/%s_% s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",318 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s", 214 319 msUrl->value, 215 320 dataPath->value, 216 321 tmpI->name, 322 imyIndex, 217 323 sid->value, 218 324 options[proto][2], … … 226 332 crs->value 227 333 ); 334 setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url); 335 if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ 336 proto=2; 337 freeMap(&rformat); 338 free(rformat); 339 rformat=createMap("mimeType","image/tiff"); 340 } 341 else{ 342 proto=1; 343 freeMap(&rformat); 344 free(rformat); 345 rformat=createMap("mimeType","text/xml"); 346 } 347 } 348 setMapArray(tmpI->content,"Reference",imyIndex,webService_url); 349 memset(layers,0,128); 350 sprintf(layers,options[proto][3],tmpI->name); 351 protoVersion=options[proto][1]; 352 extent=getMapArray(tmpI->content,options[proto][4],imyIndex); 353 memset(webService_url,0,strlen(webService_url)); 354 if(proto>0){ 355 if(proto==2) 356 finalProto=1; 357 sprintf(webService_url, 358 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", 359 msUrl->value, 360 dataPath->value, 361 tmpI->name, 362 imyIndex, 363 sid->value, 364 options[proto][2], 365 options[proto][0], 366 protoVersion, 367 layers, 368 rformat->value, 369 extent->value, 370 crs->value 371 ); 372 if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ 373 setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url); 374 } 375 else{ 376 setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url); 377 } 378 }else{ 379 sprintf(webService_url, 380 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s", 381 msUrl->value, 382 dataPath->value, 383 tmpI->name, 384 imyIndex, 385 sid->value, 386 options[proto][2], 387 options[proto][0], 388 protoVersion, 389 layers, 390 width->value, 391 height->value, 392 rformat->value, 393 extent->value, 394 crs->value 395 ); 396 setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url); 397 } 398 if(finalProto>0){ 399 proto=3; 400 memset(layers,0,128); 401 sprintf(layers,options[proto][3],tmpI->name); 402 protoVersion=options[proto][1]; 403 extent=getMapArray(tmpI->content,options[proto][4],imyIndex); 404 memset(webService_url,0,strlen(webService_url)); 405 freeMap(&rformat); 406 free(rformat); 407 rformat=createMap("value","image/tiff"); 408 sprintf(webService_url, 409 "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", 410 msUrl->value, 411 dataPath->value, 412 tmpI->name, 413 imyIndex, 414 sid->value, 415 options[proto][2], 416 options[proto][0], 417 protoVersion, 418 layers, 419 rformat->value, 420 extent->value, 421 crs->value 422 ); 423 setMapArray(tmpI->content,"ref_wcs_preview_link",imyIndex,webService_url); 228 424 } 229 425 if(hasCRS==0){ … … 231 427 free(crs); 232 428 } 233 addToMap(tmpI->content,"Reference",webService_url); 429 freeMap(&rformat); 430 free(rformat); 234 431 free(webService_url); 235 432 } … … 249 446 OGRSpatialReferenceH hSRS; 250 447 map* msSrs=NULL; 448 int imyIndex=getPublishedId(output); 251 449 hSRS = OSRNewSpatialReference(NULL); 252 450 if( pszProjection!=NULL && strlen(pszProjection)>1){ … … 272 470 if(output!=NULL){ 273 471 if(OSRIsGeographic(hSRS)==TRUE) 274 addToMap(output->content,"crs_isGeographic","true");472 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 275 473 else 276 addToMap(output->content,"crs_isGeographic","false");277 addToMap(output->content,"crs",tmpSrs);474 setMapArray(output->content,"crs_isGeographic",imyIndex,"false"); 475 setMapArray(output->content,"crs",imyIndex,tmpSrs); 278 476 } 279 477 } … … 288 486 if(output!=NULL){ 289 487 if(OSRIsGeographic(hSRS)==TRUE) 290 addToMap(output->content,"crs_isGeographic","true");488 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 291 489 else 292 addToMap(output->content,"crs_isGeographic","false");490 setMapArray(output->content,"crs_isGeographic",imyIndex,"false"); 293 491 } 294 492 free(proj4Str); … … 298 496 msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326"); 299 497 if(output!=NULL){ 300 addToMap(output->content,"crs_isGeographic","true");498 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 301 499 } 302 500 } 303 501 if(output!=NULL){ 304 addToMap(output->content,"crs","EPSG:4326");305 addToMap(output->content,"real_extent","true");502 setMapArray(output->content,"crs",imyIndex,"EPSG:4326"); 503 setMapArray(output->content,"real_extent",imyIndex,"true"); 306 504 } 307 505 msInsertHashTable(&(m->web.metadata),"ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857"); … … 312 510 else{ 313 511 if(output!=NULL){ 314 msSrs=getMap (output->content,"msSrs");512 msSrs=getMapArray(output->content,"msSrs",imyIndex); 315 513 } 316 514 if(msSrs!=NULL){ … … 328 526 } 329 527 if(output!=NULL){ 330 addToMap(output->content,"crs",msSrs->value);331 addToMap(output->content,"crs_isGeographic","true");528 setMapArray(output->content,"crs",imyIndex,msSrs->value); 529 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 332 530 } 333 531 } … … 351 549 void setMsExtent(maps* output,mapObj* m,layerObj* myLayer, 352 550 double minX,double minY,double maxX,double maxY){ 551 int imyIndex=getPublishedId(output); 353 552 msMapSetExtent(m,minX,minY,maxX,maxY); 553 //m->maxsize=4096; 354 554 #ifdef DEBUGMS 355 555 fprintf(stderr,"Extent %.15f %.15f %.15f %.15f\n",minX,minY,maxX,maxY); … … 363 563 364 564 if(output!=NULL){ 365 map* test=getMap(output->content,"real_extent"); 565 map* test=getMapArray(output->content,"real_extent",imyIndex); 566 pointObj min, max; 567 projectionObj tempSrs; 568 min.x = m->extent.minx; 569 min.y = m->extent.miny; 570 max.x = m->extent.maxx; 571 max.y = m->extent.maxy; 572 char tmpSrsStr[1024]; 573 msInitProjection(&tempSrs); 574 msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326"); 575 576 msProjectPoint(&(myLayer->projection),&tempSrs,&min); 577 msProjectPoint(&myLayer->projection,&tempSrs,&max); 578 366 579 if(test!=NULL){ 367 pointObj min, max; 368 projectionObj tempSrs; 369 min.x = m->extent.minx; 370 min.y = m->extent.miny; 371 max.x = m->extent.maxx; 372 max.y = m->extent.maxy; 373 char tmpSrsStr[1024]; 374 msInitProjection(&tempSrs); 375 msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326"); 376 377 msProjectPoint(&(m->projection),&tempSrs,&min); 378 msProjectPoint(&m->projection,&tempSrs,&max); 379 380 sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x); 381 map* isGeo=getMap(output->content,"crs_isGeographic"); 580 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.y,min.x,max.y,max.x); 581 map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex); 382 582 #ifdef DEBUGMS 383 583 fprintf(stderr,"isGeo = %s\n",isGeo->value); 384 584 #endif 385 if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0) 386 sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX); 387 addToMap(output->content,"wms_extent",tmpExtent); 388 sprintf(tmpSrsStr,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y); 389 addToMap(output->content,"wcs_extent",tmpExtent); 585 if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0){ 586 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.y,min.x,max.y,max.x); 587 setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent); 588 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f", minY,minX, maxY, maxX); 589 }else{ 590 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y); 591 setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent); 592 } 593 setMapArray(output->content,"wms_extent",imyIndex,tmpExtent); 594 sprintf(tmpSrsStr,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y); 595 setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent); 390 596 }else{ 391 sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY); 392 map* isGeo=getMap(output->content,"crs_isGeographic"); 597 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y); 598 setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent); 599 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",minX, minY, maxX, maxY); 600 map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex); 393 601 if(isGeo!=NULL){ 394 602 #ifdef DEBUGMS … … 396 604 #endif 397 605 if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0) 398 sprintf(tmpExtent,"% f,%f,%f,%f", minY,minX, maxY, maxX);399 } 400 addToMap(output->content,"wms_extent",tmpExtent);401 sprintf(tmpExtent,"%. 3f,%.3f,%.3f,%.3f",minX,minY,maxX,maxY);402 addToMap(output->content,"wcs_extent",tmpExtent);606 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f", minY,minX, maxY, maxX); 607 } 608 setMapArray(output->content,"wms_extent",imyIndex,tmpExtent); 609 sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",minX,minY,maxX,maxY); 610 setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent); 403 611 } 404 612 } … … 415 623 */ 416 624 int tryOgr(maps* conf,maps* output,mapObj* m){ 417 418 map* tmpMap=getMap (output->content,"storage");625 int imyIndex=getPublishedId(output); 626 map* tmpMap=getMapArray(output->content,"storage",imyIndex); 419 627 char *pszDataSource=tmpMap->value; 420 628 … … 425 633 /** 426 634 * Try to load the file as ZIP 427 */ 428 635 * 429 636 OGRDataSourceH poDS1 = NULL; 430 637 OGRSFDriverH *poDriver1 = NULL; … … 467 674 fprintf(stderr,"Unable to access the DataSource as ZIP File\n"); 468 675 setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); 469 OGR_DS_Destroy(poDS1); 676 fprintf(stderr,"Remove ZIP File!\n"); 677 unlink(odsName); 678 //OGR_DS_Destroy(poDS1); 470 679 }else{ 471 680 #ifdef DEBUGMS … … 526 735 i++; 527 736 } 528 } 737 OGR_DS_Destroy(poDS1); 738 } 529 739 free(sdsName); 530 free(dsName); 531 740 free(dsName);*/ 741 532 742 OGRDataSourceH poDS = NULL; 533 743 OGRSFDriverH *poDriver = NULL; … … 538 748 #endif 539 749 setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); 540 OGR_DS_Destroy(poDS);541 OGRCleanupAll();542 750 #ifdef DEBUGMS 543 751 fprintf(stderr,"Unable to access the DataSource, exit! \n"); … … 546 754 } 547 755 756 setMapArray(output->content,"gdalType",imyIndex,OGR_Dr_GetName(OGR_DS_GetDriver(poDS))); 757 setMapArray(output->content,"geodatatype",imyIndex,"vector"); 548 758 int iLayer = 0; 549 759 for( iLayer=0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++ ){ … … 561 771 * Add a new layer set name, data 562 772 */ 563 if(msGrowMapLayers(m)==NULL){ 564 return -1; 565 } 566 if(initLayer((m->layers[m->numlayers]), m) == -1){ 567 return -1; 568 } 569 570 layerObj* myLayer=m->layers[m->numlayers]; 773 layerObj* myLayer=NULL; 774 if(getMapArray(output->content,"msInclude",imyIndex)==NULL){ 775 if(msGrowMapLayers(m)==NULL){ 776 return -1; 777 } 778 if(initLayer((m->layers[m->numlayers]), m) == -1){ 779 return -1; 780 } 781 myLayer=m->layers[m->numlayers]; 782 }else{ 783 myLayer=m->layers[m->numlayers-1]; 784 } 785 571 786 #ifdef DEBUGMS 572 787 dumpMaps(output); … … 580 795 myLayer->status = MS_ON; 581 796 msConnectLayer(myLayer,MS_OGR,pszDataSource); 797 798 addIntToMapArray(output->content,"nb_features",imyIndex,OGR_L_GetFeatureCount(poLayer,1)); 582 799 583 800 /** … … 631 848 } 632 849 else{ 633 addToMap(output->content,"crs","EPSG:4326");634 addToMap(output->content,"crs_isGeographic","true");850 setMapArray(output->content,"crs",imyIndex,"EPSG:4326"); 851 setMapArray(output->content,"crs_isGeographic",imyIndex,"true"); 635 852 msLoadProjectionStringEPSG(&m->projection,"EPSG:4326"); 636 853 msInsertHashTable(&(m->web.metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857"); … … 641 858 if (OGR_L_GetExtent(poLayer,&oExt, TRUE) == OGRERR_NONE){ 642 859 setMsExtent(output,m,myLayer,oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY); 860 char extent[1024]; 861 memset(&extent,0,1024); 862 sprintf(extent,"%d,%d,%d,%d",oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY); 863 setMapArray(output->content,"boundingbox",imyIndex,extent); 643 864 } 644 865 … … 659 880 msInsertHashTable(&(myLayer->metadata), "gml_include_items", "all"); 660 881 msInsertHashTable(&(myLayer->metadata), "ows_name", output->name); 661 map* tmpMap=getMap (output->content,"title");882 map* tmpMap=getMapArray(output->content,"title",imyIndex); 662 883 if(tmpMap!=NULL) 663 884 msInsertHashTable(&(myLayer->metadata), "ows_title", tmpMap->value); 664 885 else 665 886 msInsertHashTable(&(myLayer->metadata), "ows_title", "Default Title"); 887 888 if(getMapArray(output->content,"msInclude",imyIndex)==NULL){ 889 if(msGrowLayerClasses(myLayer) == NULL) 890 return -1; 891 if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1) 892 return -1; 893 if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL) 894 return -1; 895 if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1) 896 return -1; 897 /** 898 * Apply msStyle else fallback to the default style 899 */ 900 tmpMap=getMap(output->content,"msStyle"); 901 if(tmpMap==NULL){ 902 switch(myLayer->type){ 903 case MS_LAYER_POLYGON: 904 tmpMap=getMapFromMaps(conf,"main","msStylePoly"); 905 break; 906 case MS_LAYER_LINE: 907 tmpMap=getMapFromMaps(conf,"main","msStyleLine"); 908 break; 909 default: 910 tmpMap=getMapFromMaps(conf,"main","msStylePoint"); 911 break; 912 } 913 } 914 if(tmpMap!=NULL) 915 msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0); 916 else{ 917 /** 918 * Set style 919 */ 920 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125; 921 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125; 922 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255; 923 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80; 924 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80; 925 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80; 926 927 /** 928 * Set specific style depending on type 929 */ 930 if(myLayer->type == MS_LAYER_POLYGON) 931 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; 932 if(myLayer->type == MS_LAYER_LINE){ 933 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; 934 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5; 935 } 936 if(myLayer->type == MS_LAYER_POINT){ 937 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1; 938 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15; 939 } 940 941 } 942 myLayer->CLASS[myLayer->numclasses]->numstyles++; 943 myLayer->numclasses++; 666 944 667 if(msGrowLayerClasses(myLayer) == NULL) 668 return -1; 669 if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1) 670 return -1; 671 if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL) 672 return -1; 673 if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1) 674 return -1; 675 /** 676 * Apply msStyle else fallback to the default style 677 */ 678 tmpMap=getMap(output->content,"msStyle"); 679 if(tmpMap!=NULL) 680 msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0); 681 else{ 682 /** 683 * Set style 684 */ 685 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125; 686 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125; 687 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255; 688 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80; 689 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80; 690 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80; 691 692 /** 693 * Set specific style depending on type 694 */ 695 if(myLayer->type == MS_LAYER_POLYGON) 696 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; 697 if(myLayer->type == MS_LAYER_LINE){ 698 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; 699 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5; 700 } 701 if(myLayer->type == MS_LAYER_POINT){ 702 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1; 703 myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15; 704 } 705 706 } 707 myLayer->CLASS[myLayer->numclasses]->numstyles++; 708 myLayer->numclasses++; 709 710 m->layerorder[m->numlayers] = m->numlayers; 711 m->numlayers++; 712 713 } 714 945 m->layerorder[m->numlayers] = m->numlayers; 946 m->numlayers++; 947 948 } 949 } 715 950 OGR_DS_Destroy(poDS); 716 OGRCleanupAll();951 //OGRCleanupAll(); 717 952 718 953 return 1; … … 727 962 */ 728 963 int tryGdal(maps* conf,maps* output,mapObj* m){ 729 map* tmpMap=getMap(output->content,"storage"); 964 int imyIndex=getPublishedId(output); 965 map* tmpMap=getMapArray(output->content,"storage",imyIndex); 966 map* styleMap=getMap(output->content,"msStyle"); 730 967 char *pszFilename=tmpMap->value; 731 968 GDALDatasetH hDataset; … … 738 975 */ 739 976 GDALAllRegister(); 740 hDataset = GDALOpen( pszFilename, GA_ ReadOnly );977 hDataset = GDALOpen( pszFilename, GA_Update ); /*GA_ReadOnly*/ 741 978 if( hDataset == NULL ){ 742 979 #ifdef DEBUGMS 743 980 fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename); 744 981 #endif 982 setMapArray(output->content,"geodatatype",imyIndex,"other"); 745 983 setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open"); 746 984 GDALDestroyDriverManager(); … … 751 989 #endif 752 990 991 setMapArray(output->content,"geodatatype",imyIndex,"raster"); 753 992 /** 754 993 * Add a new layer set name, data … … 772 1011 773 1012 char *title=output->name; 774 tmpMap=getMap (output->content,"title");1013 tmpMap=getMapArray(output->content,"title",imyIndex); 775 1014 if(tmpMap!=NULL) 776 1015 title=tmpMap->value; 777 1016 char *abstract=output->name; 778 tmpMap=getMap (output->content,"abstract");1017 tmpMap=getMapArray(output->content,"abstract",imyIndex); 779 1018 if(tmpMap!=NULL) 780 1019 abstract=tmpMap->value; … … 791 1030 m->width=GDALGetRasterXSize( hDataset ); 792 1031 m->height=GDALGetRasterYSize( hDataset ); 793 1032 if(m->width>4096 || m->height>4096){ 1033 if(m->width>m->height) 1034 m->maxsize=m->width; 1035 else 1036 m->maxsize=m->height; 1037 }else 1038 m->maxsize=4096; 1039 addIntToMapArray(output->content,"nb_pixels",imyIndex,GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset )); 1040 int pixel_type=GDALGetRasterDataType( hDataset ); 1041 addIntToMapArray(output->content,"pixel_data_type",imyIndex,pixel_type); 1042 1043 int outputIndex=msGetOutputFormatIndex(m,"tiff"); 1044 if(outputIndex>=0){ 1045 m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE))); 1046 outputIndex=msGetOutputFormatIndex(m,"geotiff"); 1047 if(outputIndex>=0) 1048 m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE))); 1049 } 1050 // 1051 794 1052 /** 795 1053 * Set projection using Authority Code and Name if available or fallback to … … 805 1063 setSrsInformations(output,m,myLayer,pszProjection); 806 1064 }else{ 807 fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset )); 808 } 809 1065 fprintf(stderr,"NO SRS FOUND %s %d ! %s\n",__FILE__,__LINE__,GDALGetProjectionRef( hDataset )); 1066 fflush(stderr); 1067 CPLErr sp=GDALSetProjection( hDataset , "+init=epsg:4326" ); 1068 if(sp!=CE_None){ 1069 fprintf(stderr,"NO SRS SET ! %s\n",CPLGetLastErrorMsg()); 1070 } 1071 } 810 1072 811 1073 /** … … 825 1087 + adfGeoTransform[4] * GDALGetRasterXSize(hDataset); 826 1088 827 setMsExtent(output,m,myLayer,minX,minY,maxX,maxY); 828 829 } 1089 setMsExtent(output,m,myLayer,minX,minY,maxX,maxY); 1090 char extent[1024]; 1091 memset(&extent,0,1024); 1092 sprintf(extent,"%d,%d,%d,%d",minX,minY,maxX,maxY); 1093 setMapArray(output->content,"boundingbox",imyIndex,extent); 1094 } 1095 }else{ 1096 int scale=1; 1097 if(m->width>2048){ 1098 addIntToMapArray(output->content,"width",imyIndex,2048); 1099 scale=2048/m->width; 1100 }else 1101 addIntToMapArray(output->content,"width",imyIndex,m->width); 1102 addIntToMapArray(output->content,"height",imyIndex,m->height*scale); 830 1103 } 831 1104 … … 835 1108 */ 836 1109 char nBands[3]; 1110 memset(&nBands,0,3); 837 1111 int nBandsI=GDALGetRasterCount( hDataset ); 838 sprintf(nBands,"%d",GDALGetRasterCount( hDataset )); 839 msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands); 840 if(nBandsI>=3) 841 msLayerAddProcessing(myLayer,"BANDS=1,2,3"); 842 else if(nBandsI>=2) 843 msLayerAddProcessing(myLayer,"BANDS=1,2"); 844 else 845 msLayerAddProcessing(myLayer,"BANDS=1"); 1112 if(nBandsI<100){ 1113 sprintf(nBands,"%d",GDALGetRasterCount( hDataset )); 1114 msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands); 1115 } 1116 if(styleMap==NULL || strstr(styleMap->value,"BANDS=")==NULL){ 1117 if(nBandsI>=3) 1118 if(nBandsI==4) 1119 msLayerAddProcessing(myLayer,"BANDS=1,2,3,4"); 1120 else 1121 msLayerAddProcessing(myLayer,"BANDS=1,2,3"); 1122 else if(nBandsI>=2) 1123 msLayerAddProcessing(myLayer,"BANDS=1,2"); 1124 else 1125 msLayerAddProcessing(myLayer,"BANDS=1"); 1126 } 846 1127 847 1128 /** … … 851 1132 char *nameBands=NULL; 852 1133 for( iBand = 0; iBand < nBandsI; iBand++ ){ 853 sprintf(lBands,"Band%d",iBand+1); 1134 memset(&lBands,0,7); 1135 sprintf(lBands,"Band%d",iBand+1); 854 1136 if(nameBands==NULL){ 855 1137 nameBands=(char*)malloc((strlen(lBands)+1)*sizeof(char)); 856 1138 sprintf(nameBands,"%s",lBands); 857 1139 }else{ 858 if(iBand<4){1140 /*if(iBand<4)*/{ 859 1141 char *tmpS=zStrdup(nameBands); 860 nameBands=(char*)realloc(nameBands,(strlen( nameBands)+strlen(lBands)+1)*sizeof(char));1142 nameBands=(char*)realloc(nameBands,(strlen(tmpS)+strlen(lBands)+2)*sizeof(char)); 861 1143 sprintf(nameBands,"%s %s",tmpS,lBands); 862 1144 free(tmpS); … … 864 1146 } 865 1147 } 866 msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands); 867 1148 if(nameBands!=NULL){ 1149 msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands); 1150 free(nameBands); 1151 } 1152 868 1153 /** 869 1154 * Loops over metadata information to setup specific information 870 1155 */ 871 1156 for( iBand = 0; iBand < nBandsI; iBand++ ){ 872 //int bGotNodata;//, bSuccess; 873 double adfCMinMax[2]/*, dfNoData*/; 874 //int nBlockXSize, nBlockYSize, nMaskFlags; 875 //double /*dfMean, dfStdDev*/; 1157 double pdfMin, pdfMax, pdfMean, pdfStdDev; 876 1158 hBand = GDALGetRasterBand( hDataset, iBand+1 ); 877 1159 878 1160 CPLErrorReset(); 879 GDAL ComputeRasterMinMax( hBand, FALSE, adfCMinMax);1161 GDALGetRasterStatistics( hBand, TRUE, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev); 880 1162 char tmpN[21]; 881 1163 sprintf(tmpN,"Band%d",iBand+1); 882 1164 if (CPLGetLastErrorType() == CE_None){ 883 char tmpMm[100]; 884 sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]); 885 char tmpI[21]; 1165 char tmpMm[100],tmpMp[100],tmpNb[3]; 1166 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 1167 if(pdfMin!=pdfMax && (styleMap==NULL || strstr(styleMap->value,"SCALE_")==NULL)){ 1168 sprintf(tmpNb,"%d",iBand+1); 1169 if(styleMap==NULL || strstr(styleMap->value,"BANDS=")==NULL || strstr(strstr(styleMap->value,"BANDS="),tmpNb)!=NULL){ 1170 if(pdfMean-(2*pdfStdDev)<0) 1171 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,0.0,pdfMean+(2*pdfStdDev)); 1172 else 1173 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev)); 1174 msLayerAddProcessing(myLayer,tmpMp); 1175 } 1176 } 1177 char tmpI[31]; 886 1178 sprintf(tmpI,"%s_interval",tmpN); 887 1179 msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm); 888 889 1180 map* test=getMap(output->content,"msClassify"); 890 1181 if(test!=NULL && strncasecmp(test->value,"true",4)==0){ … … 906 1197 907 1198 if(nBandsI==1){ 908 double delta= adfCMinMax[1]-adfCMinMax[0];1199 double delta=pdfMax-pdfMin; 909 1200 double interval=delta/10; 910 double cstep= adfCMinMax[0];1201 double cstep=pdfMin; 911 1202 for(i=0;i<10;i++){ 912 1203 /** … … 952 1243 953 1244 char tmpMm[100]; 954 sprintf(tmpMm,"%.3f %.3f", adfCMinMax[0],adfCMinMax[1]);1245 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 955 1246 956 1247 } … … 962 1253 myLayer->offsite.blue=0; 963 1254 } 964 msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");965 1255 } 966 1256 } 967 1257 if( strlen(GDALGetRasterUnitType(hBand)) > 0 ){ 968 char tmpU[ 21];1258 char tmpU[31]; 969 1259 sprintf(tmpU,"%s_band_uom",tmpN); 970 1260 msInsertHashTable(&(myLayer->metadata), tmpU, GDALGetRasterUnitType(hBand)); … … 972 1262 973 1263 } 974 1264 if(styleMap==NULL || strstr(styleMap->value,"RESAMPLE")==NULL) 1265 msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR"); 1266 1267 if(styleMap!=NULL && strlen(styleMap->value)>9){ 1268 msUpdateLayerFromString(myLayer,styleMap->value,MS_FALSE); 1269 } 1270 975 1271 m->layerorder[m->numlayers] = m->numlayers; 976 1272 m->numlayers++; … … 978 1274 GDALDestroyDriverManager(); 979 1275 CPLCleanupTLS(); 1276 storeMd5(pszFilename); 980 1277 return 1; 981 1278 } … … 988 1285 */ 989 1286 void outputMapfile(maps* conf,maps* outputs){ 990 991 1287 /** 992 1288 * First store the value on disk 993 1289 */ 994 map* mime=getMap(outputs->content,"mimeType"); 1290 int imyIndex=getPublishedId(outputs); 1291 map* mime=getMapArray(outputs->content,"mimeType",imyIndex); 1292 map* msUrl=getMapFromMaps(conf,"main","mapserverAddress"); 1293 map* dataPath=getMapFromMaps(conf,"main","dataPath"); 995 1294 char *ext="data"; 996 1295 if(mime!=NULL) … … 998 1297 ext="json"; 999 1298 1000 map* tmpMap=getMapFromMaps(conf,"main","dataPath"); 1001 map* sidMap=getMapFromMaps(conf,"lenv","usid"); 1002 char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); 1003 sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 1004 int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); 1005 map *gfile=getMap(outputs->content,"generated_file"); 1006 if(gfile!=NULL){ 1007 readGeneratedFile(conf,outputs->content,gfile->value); 1008 } 1009 map* sizeMap=getMap(outputs->content,"size"); 1010 map* vData=getMap(outputs->content,"value"); 1011 if(sizeMap!=NULL){ 1012 zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); 1013 } 1014 else{ 1015 zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); 1016 } 1017 close(f); 1018 addToMap(outputs->content,"storage",pszDataSource); 1019 free(pszDataSource); 1299 map* storage=getMapArray(outputs->content,"storage",imyIndex); 1300 if(storage==NULL){ 1301 map* tmpMap=getMapFromMaps(conf,"main","dataPath"); 1302 map* sidMap=getMapFromMaps(conf,"lenv","usid"); 1303 char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); 1304 sprintf(pszDataSource,"%s/ZOO_DATA_%d_%s_%s.%s",tmpMap->value,imyIndex,outputs->name,sidMap->value,ext); 1305 int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); 1306 map *gfile=getMapArray(outputs->content,"generated_file",imyIndex); 1307 if(gfile!=NULL){ 1308 readGeneratedFile(conf,outputs->content,gfile->value); 1309 } 1310 map* sizeMap=getMapArray(outputs->content,"size",imyIndex); 1311 map* vData=getMapArray(outputs->content,"value",imyIndex); 1312 if(sizeMap!=NULL){ 1313 zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); 1314 } 1315 else{ 1316 zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); 1317 } 1318 close(f); 1319 setMapArray(outputs->content,"storage",imyIndex,pszDataSource); 1320 free(pszDataSource); 1321 } 1020 1322 1021 1323 /* 1022 1324 * Create an empty map, set name, default size and extent 1023 1325 */ 1024 mapObj *myMap=msNewMapObj(); 1326 map* mapfileTemplate=getMapArray(outputs->content,"msInclude",imyIndex); 1327 mapObj *myMap=NULL; 1328 if(mapfileTemplate==NULL){ 1329 myMap=msNewMapObj(); 1330 } 1331 else{ 1332 map* dataPath=getMapFromMaps(conf,"main","dataPath"); 1333 map* sid=getMapFromMaps(conf,"lenv","sid"); 1334 char *mapfileTemplatePath=(char*)malloc(((strlen(dataPath->value)+strlen(sid->value)+strlen(outputs->name)+10)*sizeof(char))); 1335 sprintf(mapfileTemplatePath,"%s/%s_%s.map",dataPath->value,outputs->name,sid->value); 1336 myMap=msLoadMap(mapfileTemplate->value,mapfileTemplatePath); 1337 if(myMap==NULL){ 1338 setMapInMaps(conf,"lenv","message",_("Unable to open your template mapfile!")); 1339 return ; 1340 } 1341 } 1025 1342 free(myMap->name); 1026 1343 myMap->name=zStrdup("ZOO-Project_WXS_Server"); … … 1048 1365 #ifdef USE_KML 1049 1366 outputFormatObj *o2=msCreateDefaultOutputFormat(NULL,"KML","kml"); 1050 o2->inmapfile=MS_TRUE; 1051 msAppendOutputFormat(myMap,msCloneOutputFormat(o2)); 1052 msFreeOutputFormat(o2); 1367 if(!o2){ 1368 perror("Unable to initialize KML driver"); 1369 fprintf(stderr,"Unable to initialize KML driver !\n"); 1370 }else{ 1371 o2->inmapfile=MS_TRUE; 1372 msAppendOutputFormat(myMap,msCloneOutputFormat(o2)); 1373 msFreeOutputFormat(o2); 1374 } 1053 1375 #endif 1054 1376 … … 1057 1379 fprintf(stderr,"Unable to initialize GDAL driver !\n"); 1058 1380 else{ 1059 o3->imagemode=MS_IMAGEMODE_ BYTE;1381 o3->imagemode=MS_IMAGEMODE_INT16; 1060 1382 o3->inmapfile=MS_TRUE; 1061 1383 msAppendOutputFormat(myMap,msCloneOutputFormat(o3)); … … 1067 1389 fprintf(stderr,"Unable to initialize GDAL driver !\n"); 1068 1390 else{ 1069 o4->imagemode=MS_IMAGEMODE_ INT16;1391 o4->imagemode=MS_IMAGEMODE_BYTE; 1070 1392 o4->inmapfile=MS_TRUE; 1071 1393 msAppendOutputFormat(myMap,msCloneOutputFormat(o4)); … … 1086 1408 #endif 1087 1409 1410 1411 outputFormatObj *o6=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","geotiff"); 1412 if(!o6) 1413 fprintf(stderr,"Unable to initialize GDAL driver !\n"); 1414 else{ 1415 o6->imagemode=MS_IMAGEMODE_BYTE; 1416 o6->mimetype=strdup("image/geotiff"); 1417 o6->inmapfile=MS_TRUE; 1418 msAppendOutputFormat(myMap,msCloneOutputFormat(o6)); 1419 msFreeOutputFormat(o6); 1420 } 1421 1422 1088 1423 /* 1089 1424 * Set default projection to EPSG:4326 … … 1091 1426 msLoadProjectionStringEPSG(&myMap->projection,"EPSG:4326"); 1092 1427 myMap->transparent=1; 1093 1094 /**1095 * Set metadata extracted from main.cfg file maps1096 */1097 maps* cursor=conf;1098 map* correspondance=getCorrespondance();1099 while(cursor!=NULL){1100 map* _cursor=cursor->content;1101 map* vMap;1102 while(_cursor!=NULL){1103 if((vMap=getMap(correspondance,_cursor->name))!=NULL){1104 if (msInsertHashTable(&(myMap->web.metadata), vMap->value, _cursor->value) == NULL){1105 #ifdef DEBUGMS1106 fprintf(stderr,"Unable to add metadata");1107 #endif1108 return;1109 }1110 }1111 _cursor=_cursor->next;1112 }1113 cursor=cursor->next;1114 }1115 freeMap(&correspondance);1116 free(correspondance);1117 1428 1118 1429 /* … … 1157 1468 msInsertHashTable(&(myMap->web.metadata), "ows_srs", "EPSG:4326"); 1158 1469 1470 /** 1471 * Set metadata extracted from main.cfg file maps 1472 */ 1473 maps* cursor=conf; 1474 map* correspondance=getCorrespondance(); 1475 while(cursor!=NULL){ 1476 if(strstr(cursor->name,"_help")==NULL){ 1477 map* _cursor=cursor->content; 1478 map* vMap; 1479 while(_cursor!=NULL){ 1480 if((vMap=getMap(correspondance,_cursor->name))!=NULL){ 1481 if (msInsertHashTable(&(myMap->web.metadata), vMap->value, _cursor->value) == NULL){ 1482 #ifdef DEBUGMS 1483 fprintf(stderr,"Unable to add metadata"); 1484 #endif 1485 freeMap(&correspondance); 1486 free(correspondance); 1487 return; 1488 } 1489 } 1490 _cursor=_cursor->next; 1491 } 1492 } 1493 cursor=cursor->next; 1494 } 1495 freeMap(&correspondance); 1496 free(correspondance); 1497 1498 map* sid=getMapFromMaps(conf,"lenv","usid"); 1499 char *mapPath= 1500 (char*)malloc((14+strlen(sid->value)+strlen(outputs->name)+strlen(dataPath->value))*sizeof(char)); 1501 sprintf(mapPath,"%s/%s_%d_%s.map",dataPath->value,outputs->name,imyIndex,sid->value); 1502 char *mapUrl= 1503 (char*)malloc((6+strlen(mapPath)+strlen(msUrl->value))*sizeof(char)); 1504 sprintf(mapUrl,"%s?map=%s",msUrl->value,mapPath); 1505 1506 if (msInsertHashTable(&(myMap->web.metadata), "ows_onlineresource", mapUrl) == NULL){ 1507 #ifdef DEBUGMS 1508 fprintf(stderr,"Unable to add metadata"); 1509 #endif 1510 return; 1511 } 1512 1159 1513 if(tryOgr(conf,outputs,myMap)<0) 1160 1514 if(tryGdal(conf,outputs,myMap)<0) 1161 1515 return ; 1162 1516 1163 tmp1=getMapFromMaps(conf,"main","dataPath"); 1164 char *tmpPath=(char*)malloc((13+strlen(tmp1->value))*sizeof(char)); 1165 sprintf(tmpPath,"%s/symbols.sym",tmp1->value); 1517 char *tmpPath=(char*)malloc((13+strlen(dataPath->value))*sizeof(char)); 1518 sprintf(tmpPath,"%s/symbols.sym",dataPath->value); 1166 1519 msInitSymbolSet(&myMap->symbolset); 1167 1520 myMap->symbolset.filename=zStrdup(tmpPath); 1168 1521 free(tmpPath); 1169 1522 1170 map* sid=getMapFromMaps(conf,"lenv","usid");1171 char *mapPath=1172 (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));1173 sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);1174 1523 msSaveMap(myMap,mapPath); 1524 saveMapNames(conf,outputs,mapPath); 1175 1525 free(mapPath); 1526 //free(myMap->symbolset.filename); 1527 //msFreeSymbolSet(&myMap->symbolset); 1528 msFreeMap(myMap); 1529 //msFree(myMap); 1176 1530 msGDALCleanup(); 1177 msFreeMap(myMap);1178 1531 } 1179 1532 1533 /** 1534 * Save the map fullpath in a text file (.maps) 1535 * @param conf the main configuration map pointer 1536 * @param output the current output for which a mapfile has been generated 1537 * @param mapfile the mapfile saved to store in the text file 1538 */ 1539 void saveMapNames(maps* conf,maps* output,char* mapfile){ 1540 map* storage=getMap(output->content,"storage"); 1541 char *tmp=zStrdup(storage->value); 1542 tmp[strlen(tmp)-strlen(strrchr(tmp,'.'))]=0; 1543 char* mapName=(char*)malloc((strlen(tmp)+6)*sizeof(char*)); 1544 sprintf(mapName,"%s.maps",tmp); 1545 FILE* myMaps=fopen(mapName,"a"); 1546 if(myMaps!=NULL){ 1547 fprintf(myMaps,"%s\n",mapfile); 1548 fclose(myMaps); 1549 } 1550 free(mapName); 1551 free(tmp); 1552 }
Note: See TracChangeset
for help on using the changeset viewer.