[579] | 1 | /* |
---|
[379] | 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
| 4 | * Copyright 2010-2011 Fondazione Edmund Mach. 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 | |
---|
[586] | 25 | /** |
---|
| 26 | * Cross platform definition of layerObj->class |
---|
| 27 | */ |
---|
[370] | 28 | #ifndef WIN32 |
---|
| 29 | #define CLASS class |
---|
| 30 | #else |
---|
| 31 | #define CLASS _class |
---|
| 32 | #endif |
---|
[297] | 33 | #include "service_internal_ms.h" |
---|
[640] | 34 | #include "server_internal.h" |
---|
| 35 | #include "response_print.h" |
---|
[297] | 36 | |
---|
| 37 | /** |
---|
[586] | 38 | * Get a list of configuration keys having a corresponding mandatory ows_*. |
---|
[297] | 39 | * Map composed by a main.cfg maps name as key and the corresponding |
---|
| 40 | * MapServer Mafile Metadata name to use |
---|
| 41 | * see doc from here : |
---|
| 42 | * - http://mapserver.org/ogc/wms_server.html |
---|
| 43 | * - http://mapserver.org/ogc/wfs_server.html |
---|
| 44 | * - http://mapserver.org/ogc/wcs_server.html |
---|
[586] | 45 | * |
---|
| 46 | * @return a new map containing a table linking a name of a configuration key |
---|
| 47 | * to a corresponding mandatory ows_* keyword (ie. "fees" => "ows_fees"). |
---|
[297] | 48 | */ |
---|
| 49 | map* getCorrespondance(){ |
---|
| 50 | map* res=createMap("encoding","ows_encoding"); |
---|
| 51 | addToMap(res,"abstract","ows_abstract"); |
---|
| 52 | addToMap(res,"title","ows_title"); |
---|
| 53 | addToMap(res,"keywords","ows_keywordlist"); |
---|
| 54 | addToMap(res,"fees","ows_fees"); |
---|
| 55 | addToMap(res,"accessConstraints","ows_accessconstraints"); |
---|
| 56 | addToMap(res,"providerName","ows_attribution_title"); |
---|
| 57 | addToMap(res,"providerSite","ows_service_onlineresource"); |
---|
| 58 | addToMap(res,"individualName","ows_contactperson"); |
---|
| 59 | addToMap(res,"positionName","ows_contactposition"); |
---|
| 60 | addToMap(res,"providerName","ows_contactorganization"); |
---|
| 61 | addToMap(res,"role","ows_role"); |
---|
| 62 | addToMap(res,"addressType","ows_addresstype"); |
---|
| 63 | addToMap(res,"addressCity","ows_city"); |
---|
| 64 | addToMap(res,"addressDeliveryPoint","ows_address"); |
---|
| 65 | addToMap(res,"addressPostalCode","ows_postcode"); |
---|
| 66 | addToMap(res,"addressAdministrativeArea","ows_stateorprovince"); |
---|
| 67 | addToMap(res,"addressCountry","ows_country"); |
---|
| 68 | addToMap(res,"phoneVoice","ows_contactvoicetelephone"); |
---|
| 69 | addToMap(res,"phoneFacsimile","ows_contactfacsimiletelephone"); |
---|
| 70 | addToMap(res,"addressElectronicMailAddress","ows_contactelectronicmailaddress"); |
---|
| 71 | // Missing Madatory Informations |
---|
| 72 | addToMap(res,"hoursOfService","ows_hoursofservice"); |
---|
| 73 | addToMap(res,"contactInstructions","ows_contactinstructions"); |
---|
| 74 | return res; |
---|
| 75 | } |
---|
| 76 | |
---|
[586] | 77 | /** |
---|
| 78 | * Add width and height keys to an output maps containing the maximum width |
---|
| 79 | * and height for displaying the full data extent. |
---|
| 80 | * Restriction to an image having a size of 640x480 (width * height) |
---|
| 81 | * |
---|
| 82 | * @param output |
---|
| 83 | * @param minx the lower left x coordinate |
---|
| 84 | * @param miny the lower left y coordinate |
---|
| 85 | * @param maxx the upper right x coordinate |
---|
| 86 | * @param maxy the upper right y coordinate |
---|
| 87 | */ |
---|
[297] | 88 | void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){ |
---|
| 89 | double maxWidth=640; |
---|
| 90 | double maxHeight=480; |
---|
| 91 | double deltaX=maxx-minx; |
---|
| 92 | double deltaY=maxy-miny; |
---|
| 93 | double qWidth; |
---|
| 94 | qWidth=maxWidth/deltaX; |
---|
| 95 | double qHeight; |
---|
| 96 | qHeight=maxHeight/deltaY; |
---|
| 97 | #ifdef DEBUGMS |
---|
| 98 | fprintf(stderr,"deltaX : %.15f \ndeltaY : %.15f\n",deltaX,deltaY); |
---|
| 99 | fprintf(stderr,"qWidth : %.15f \nqHeight : %.15f\n",qWidth,qHeight); |
---|
| 100 | #endif |
---|
| 101 | |
---|
| 102 | double width=deltaX*qWidth; |
---|
| 103 | double height=height=deltaY*qWidth; |
---|
| 104 | if(deltaX<deltaY){ |
---|
| 105 | width=deltaX*qHeight; |
---|
| 106 | height=deltaY*qHeight; |
---|
| 107 | } |
---|
| 108 | if(height<0) |
---|
| 109 | height=-height; |
---|
| 110 | if(width<0) |
---|
| 111 | width=-width; |
---|
| 112 | char sWidth[1024]; |
---|
| 113 | char sHeight[1024]; |
---|
| 114 | sprintf(sWidth,"%.3f",width); |
---|
| 115 | sprintf(sHeight,"%.3f",height); |
---|
| 116 | #ifdef DEBUGMS |
---|
| 117 | fprintf(stderr,"sWidth : %.15f \nsHeight : %.15f\n",sWidth,sHeight); |
---|
| 118 | #endif |
---|
| 119 | if(output!=NULL){ |
---|
| 120 | addToMap(output->content,"width",sWidth); |
---|
| 121 | addToMap(output->content,"height",sHeight); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
[586] | 125 | /** |
---|
| 126 | * Add a Reference key to an output containing the WMFS/WFS/WCS request for |
---|
| 127 | * accessing service result |
---|
| 128 | * |
---|
| 129 | * @param m the conf maps containing the main.cfg settings |
---|
| 130 | * @param tmpI the specific output maps to add the Reference key |
---|
| 131 | */ |
---|
[297] | 132 | void setReferenceUrl(maps* m,maps* tmpI){ |
---|
| 133 | outputMapfile(m,tmpI); |
---|
| 134 | map *msUrl=getMapFromMaps(m,"main","mapserverAddress"); |
---|
[607] | 135 | if(msUrl==NULL){ |
---|
| 136 | errorException (m, _("Unable to find any mapserverAddress defined in the main.cfg file"), |
---|
| 137 | "InternalError", NULL); |
---|
| 138 | exit(-1); |
---|
| 139 | } |
---|
[854] | 140 | int finalProto=-1; |
---|
[297] | 141 | map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion"); |
---|
| 142 | map *dataPath=getMapFromMaps(m,"main","dataPath"); |
---|
[453] | 143 | map *sid=getMapFromMaps(m,"lenv","usid"); |
---|
[297] | 144 | map* format=getMap(tmpI->content,"mimeType"); |
---|
| 145 | map* rformat=getMap(tmpI->content,"requestedMimeType"); |
---|
| 146 | map* width=getMap(tmpI->content,"width"); |
---|
| 147 | map* height=getMap(tmpI->content,"height"); |
---|
| 148 | map* protoMap=getMap(tmpI->content,"msOgc"); |
---|
| 149 | map* versionMap=getMap(tmpI->content,"msOgcVersion"); |
---|
[854] | 150 | char options[4][5][25]={ |
---|
[297] | 151 | {"WMS","1.3.0","GetMap","layers=%s","wms_extent"}, |
---|
[434] | 152 | {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"}, |
---|
[854] | 153 | {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"}, |
---|
| 154 | {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"} |
---|
[297] | 155 | }; |
---|
[854] | 156 | map* datatype=getMap(tmpI->content,"geodatatype"); |
---|
| 157 | if(datatype==NULL || strncmp(datatype->value,"other",5)==0){ |
---|
| 158 | setMapInMaps(m,"lenv","mapError","true"); |
---|
| 159 | setMapInMaps(m,"lenv","locator",tmpI->name); |
---|
| 160 | setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data.")); |
---|
| 161 | if(getMapFromMaps(m,"lenv","state")==NULL) |
---|
| 162 | errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name); |
---|
| 163 | return; |
---|
| 164 | } |
---|
[297] | 165 | int proto=0; |
---|
| 166 | if(rformat==NULL){ |
---|
| 167 | rformat=getMap(tmpI->content,"mimeType"); |
---|
| 168 | } |
---|
| 169 | if(strncasecmp(rformat->value,"text/xml",8)==0) |
---|
| 170 | proto=1; |
---|
[839] | 171 | if(strncasecmp(rformat->value,"image/tiff",10)==0 || |
---|
| 172 | strncasecmp(rformat->value,"image/geotiff",10)==0) |
---|
[297] | 173 | proto=2; |
---|
[490] | 174 | if(protoMap!=NULL){ |
---|
[297] | 175 | if(strncasecmp(protoMap->value,"WMS",3)==0) |
---|
| 176 | proto=0; |
---|
[490] | 177 | else{ |
---|
| 178 | if(strncasecmp(protoMap->value,"WFS",3)==0) |
---|
| 179 | proto=1; |
---|
| 180 | else |
---|
| 181 | proto=2; |
---|
| 182 | } |
---|
| 183 | } |
---|
[297] | 184 | char *protoVersion=options[proto][1]; |
---|
| 185 | if(proto==1){ |
---|
| 186 | if(msOgcVersion!=NULL) |
---|
| 187 | protoVersion=msOgcVersion->value; |
---|
| 188 | if(versionMap!=NULL) |
---|
| 189 | protoVersion=versionMap->value; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | map* extent=getMap(tmpI->content,options[proto][4]); |
---|
| 193 | map* crs=getMap(tmpI->content,"crs"); |
---|
[402] | 194 | int hasCRS=1; |
---|
| 195 | if(crs==NULL){ |
---|
| 196 | crs=getMapFromMaps(m,"main","crs"); |
---|
| 197 | if(crs==NULL){ |
---|
| 198 | crs=createMap("crs","epsg:4326"); |
---|
| 199 | hasCRS=0; |
---|
| 200 | } |
---|
| 201 | } |
---|
[297] | 202 | char layers[128]; |
---|
| 203 | sprintf(layers,options[proto][3],tmpI->name); |
---|
| 204 | |
---|
| 205 | 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)); |
---|
[850] | 206 | |
---|
[357] | 207 | if(proto>0){ |
---|
[854] | 208 | if(proto==2) |
---|
| 209 | finalProto=1; |
---|
[851] | 210 | sprintf(webService_url, |
---|
| 211 | "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", |
---|
| 212 | msUrl->value, |
---|
| 213 | dataPath->value, |
---|
| 214 | tmpI->name, |
---|
| 215 | sid->value, |
---|
| 216 | options[proto][2], |
---|
| 217 | options[proto][0], |
---|
| 218 | protoVersion, |
---|
| 219 | layers, |
---|
| 220 | rformat->value, |
---|
| 221 | extent->value, |
---|
| 222 | crs->value |
---|
| 223 | ); |
---|
| 224 | if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ |
---|
| 225 | addToMap(tmpI->content,"ref_wcs_link",webService_url); |
---|
| 226 | } |
---|
| 227 | else{ |
---|
| 228 | addToMap(tmpI->content,"ref_wfs_link",webService_url); |
---|
| 229 | } |
---|
[850] | 230 | proto=0; |
---|
| 231 | rformat=createMap("mimeType","image/png"); |
---|
[357] | 232 | } |
---|
| 233 | else{ |
---|
[851] | 234 | sprintf(webService_url, |
---|
| 235 | "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s", |
---|
| 236 | msUrl->value, |
---|
| 237 | dataPath->value, |
---|
| 238 | tmpI->name, |
---|
| 239 | sid->value, |
---|
| 240 | options[proto][2], |
---|
| 241 | options[proto][0], |
---|
| 242 | protoVersion, |
---|
| 243 | layers, |
---|
| 244 | width->value, |
---|
| 245 | height->value, |
---|
| 246 | rformat->value, |
---|
| 247 | extent->value, |
---|
| 248 | crs->value |
---|
| 249 | ); |
---|
| 250 | addToMap(tmpI->content,"ref_wms_link",webService_url); |
---|
[850] | 251 | if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ |
---|
| 252 | proto=2; |
---|
| 253 | rformat=createMap("mimeType","image/tiff"); |
---|
| 254 | } |
---|
| 255 | else{ |
---|
| 256 | proto=1; |
---|
| 257 | rformat=createMap("mimeType","text/xml"); |
---|
| 258 | } |
---|
[357] | 259 | } |
---|
[851] | 260 | addToMap(tmpI->content,"Reference",webService_url); |
---|
[854] | 261 | memset(layers,0,128); |
---|
| 262 | sprintf(layers,options[proto][3],tmpI->name); |
---|
[850] | 263 | protoVersion=options[proto][1]; |
---|
| 264 | extent=getMap(tmpI->content,options[proto][4]); |
---|
| 265 | memset(webService_url,0,strlen(webService_url)); |
---|
| 266 | if(proto>0){ |
---|
[854] | 267 | if(proto==2) |
---|
| 268 | finalProto=1; |
---|
[851] | 269 | sprintf(webService_url, |
---|
| 270 | "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", |
---|
| 271 | msUrl->value, |
---|
| 272 | dataPath->value, |
---|
| 273 | tmpI->name, |
---|
| 274 | sid->value, |
---|
| 275 | options[proto][2], |
---|
| 276 | options[proto][0], |
---|
| 277 | protoVersion, |
---|
| 278 | layers, |
---|
| 279 | rformat->value, |
---|
| 280 | extent->value, |
---|
| 281 | crs->value |
---|
| 282 | ); |
---|
| 283 | if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){ |
---|
| 284 | addToMap(tmpI->content,"ref_wcs_link",webService_url); |
---|
| 285 | } |
---|
| 286 | else{ |
---|
| 287 | addToMap(tmpI->content,"ref_wfs_link",webService_url); |
---|
| 288 | } |
---|
| 289 | }else{ |
---|
| 290 | sprintf(webService_url, |
---|
| 291 | "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s", |
---|
| 292 | msUrl->value, |
---|
| 293 | dataPath->value, |
---|
| 294 | tmpI->name, |
---|
| 295 | sid->value, |
---|
| 296 | options[proto][2], |
---|
| 297 | options[proto][0], |
---|
| 298 | protoVersion, |
---|
| 299 | layers, |
---|
| 300 | width->value, |
---|
| 301 | height->value, |
---|
| 302 | rformat->value, |
---|
| 303 | extent->value, |
---|
| 304 | crs->value |
---|
| 305 | ); |
---|
| 306 | addToMap(tmpI->content,"ref_wms_link",webService_url); |
---|
[850] | 307 | } |
---|
[854] | 308 | if(finalProto>0){ |
---|
| 309 | proto=3; |
---|
| 310 | memset(layers,0,128); |
---|
| 311 | sprintf(layers,options[proto][3],tmpI->name); |
---|
| 312 | protoVersion=options[proto][1]; |
---|
| 313 | extent=getMap(tmpI->content,options[proto][4]); |
---|
| 314 | memset(webService_url,0,strlen(webService_url)); |
---|
| 315 | sprintf(webService_url, |
---|
| 316 | "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", |
---|
| 317 | msUrl->value, |
---|
| 318 | dataPath->value, |
---|
| 319 | tmpI->name, |
---|
| 320 | sid->value, |
---|
| 321 | options[proto][2], |
---|
| 322 | options[proto][0], |
---|
| 323 | protoVersion, |
---|
| 324 | layers, |
---|
| 325 | rformat->value, |
---|
| 326 | extent->value, |
---|
| 327 | crs->value |
---|
| 328 | ); |
---|
| 329 | addToMap(tmpI->content,"ref_wcs_preview_link",webService_url); |
---|
| 330 | } |
---|
[402] | 331 | if(hasCRS==0){ |
---|
| 332 | freeMap(&crs); |
---|
| 333 | free(crs); |
---|
| 334 | } |
---|
[851] | 335 | freeMap(&rformat); |
---|
| 336 | free(rformat); |
---|
[492] | 337 | free(webService_url); |
---|
[297] | 338 | } |
---|
| 339 | |
---|
| 340 | /** |
---|
[586] | 341 | * Set projection for a layer in a MAPFILE using Authority Code and Name if |
---|
| 342 | * available or fallback to proj4 definition if available or fallback to |
---|
| 343 | * default EPSG:4326 |
---|
| 344 | * |
---|
| 345 | * @param output the output maps |
---|
| 346 | * @param m the opened mapObj |
---|
| 347 | * @param myLayer the layerObj |
---|
| 348 | * @param pszProjection a char* containing the SRS definition in WKT format |
---|
[297] | 349 | */ |
---|
| 350 | void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer, |
---|
| 351 | char* pszProjection){ |
---|
| 352 | OGRSpatialReferenceH hSRS; |
---|
| 353 | map* msSrs=NULL; |
---|
| 354 | hSRS = OSRNewSpatialReference(NULL); |
---|
[451] | 355 | if( pszProjection!=NULL && strlen(pszProjection)>1){ |
---|
| 356 | if(OSRImportFromWkt( hSRS, &pszProjection ) == CE_None ){ |
---|
| 357 | char *proj4Str=NULL; |
---|
| 358 | if(OSRGetAuthorityName(hSRS,NULL)!=NULL && |
---|
| 359 | OSRGetAuthorityCode(hSRS,NULL)!=NULL){ |
---|
| 360 | char tmpSrs[20]; |
---|
| 361 | sprintf(tmpSrs,"%s:%s", |
---|
| 362 | OSRGetAuthorityName(hSRS,NULL),OSRGetAuthorityCode(hSRS,NULL)); |
---|
| 363 | msLoadProjectionStringEPSG(&m->projection,tmpSrs); |
---|
| 364 | msLoadProjectionStringEPSG(&myLayer->projection,tmpSrs); |
---|
| 365 | |
---|
| 366 | char tmpSrss[256]; |
---|
[776] | 367 | sprintf(tmpSrss,"EPSG:4326 EPSG:900913 EPSG:3857 %s",tmpSrs); |
---|
[451] | 368 | |
---|
| 369 | msInsertHashTable(&(m->web.metadata), "ows_srs", tmpSrss); |
---|
| 370 | msInsertHashTable(&(myLayer->metadata), "ows_srs", tmpSrss); |
---|
| 371 | |
---|
[297] | 372 | #ifdef DEBUGMS |
---|
[451] | 373 | fprintf(stderr,"isGeo %b\n\n",OSRIsGeographic(hSRS)==TRUE); |
---|
[297] | 374 | #endif |
---|
[451] | 375 | if(output!=NULL){ |
---|
[297] | 376 | if(OSRIsGeographic(hSRS)==TRUE) |
---|
| 377 | addToMap(output->content,"crs_isGeographic","true"); |
---|
| 378 | else |
---|
| 379 | addToMap(output->content,"crs_isGeographic","false"); |
---|
[451] | 380 | addToMap(output->content,"crs",tmpSrs); |
---|
[297] | 381 | } |
---|
| 382 | } |
---|
| 383 | else{ |
---|
[451] | 384 | OSRExportToProj4(hSRS,&proj4Str); |
---|
[475] | 385 | if(proj4Str!=NULL && strlen(proj4Str)>0){ |
---|
[451] | 386 | #ifdef DEBUGMS |
---|
| 387 | fprintf(stderr,"PROJ (%s)\n",proj4Str); |
---|
| 388 | #endif |
---|
| 389 | msLoadProjectionString(&(m->projection),proj4Str); |
---|
| 390 | msLoadProjectionString(&(myLayer->projection),proj4Str); |
---|
| 391 | if(output!=NULL){ |
---|
| 392 | if(OSRIsGeographic(hSRS)==TRUE) |
---|
| 393 | addToMap(output->content,"crs_isGeographic","true"); |
---|
| 394 | else |
---|
| 395 | addToMap(output->content,"crs_isGeographic","false"); |
---|
| 396 | } |
---|
[492] | 397 | free(proj4Str); |
---|
[451] | 398 | } |
---|
| 399 | else{ |
---|
| 400 | msLoadProjectionStringEPSG(&m->projection,"EPSG:4326"); |
---|
| 401 | msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326"); |
---|
| 402 | if(output!=NULL){ |
---|
| 403 | addToMap(output->content,"crs_isGeographic","true"); |
---|
| 404 | } |
---|
| 405 | } |
---|
[297] | 406 | if(output!=NULL){ |
---|
[451] | 407 | addToMap(output->content,"crs","EPSG:4326"); |
---|
| 408 | addToMap(output->content,"real_extent","true"); |
---|
[297] | 409 | } |
---|
[776] | 410 | msInsertHashTable(&(m->web.metadata),"ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857"); |
---|
| 411 | msInsertHashTable(&(myLayer->metadata),"ows_srs","EPSG:4326 EPSG:900913 EPSG:3857"); |
---|
[297] | 412 | } |
---|
| 413 | } |
---|
| 414 | } |
---|
| 415 | else{ |
---|
| 416 | if(output!=NULL){ |
---|
| 417 | msSrs=getMap(output->content,"msSrs"); |
---|
| 418 | } |
---|
| 419 | if(msSrs!=NULL){ |
---|
| 420 | msLoadProjectionStringEPSG(&m->projection,msSrs->value); |
---|
[330] | 421 | msLoadProjectionStringEPSG(&myLayer->projection,msSrs->value); |
---|
[297] | 422 | char tmpSrs[128]; |
---|
[776] | 423 | sprintf(tmpSrs,"%s EPSG:4326 EPSG:900913 EPSG:3857",msSrs->value); |
---|
[297] | 424 | msInsertHashTable(&(m->web.metadata),"ows_srs",tmpSrs); |
---|
| 425 | msInsertHashTable(&(myLayer->metadata),"ows_srs",tmpSrs); |
---|
| 426 | }else{ |
---|
| 427 | msLoadProjectionStringEPSG(&m->projection,"EPSG:4326"); |
---|
[330] | 428 | msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326"); |
---|
[776] | 429 | msInsertHashTable(&(m->web.metadata),"ows_srs","EPSG:4326 EPSG:900913 EPSG:3857"); |
---|
| 430 | msInsertHashTable(&(myLayer->metadata),"ows_srs","EPSG:4326 EPSG:900913 EPSG:3857"); |
---|
[297] | 431 | } |
---|
[362] | 432 | if(output!=NULL){ |
---|
| 433 | addToMap(output->content,"crs",msSrs->value); |
---|
| 434 | addToMap(output->content,"crs_isGeographic","true"); |
---|
| 435 | } |
---|
[297] | 436 | } |
---|
| 437 | |
---|
| 438 | OSRDestroySpatialReference( hSRS ); |
---|
| 439 | } |
---|
| 440 | |
---|
[586] | 441 | /** |
---|
| 442 | * Set the MAPFILE extent, the the ows_extent for the layer, add wms_extent and |
---|
| 443 | * wfs_extent to the output maps and call setMapSize. |
---|
| 444 | * |
---|
| 445 | * @param output the specific output |
---|
| 446 | * @param m the mapObj |
---|
| 447 | * @param myLayer the layerObj |
---|
| 448 | * @param minX the lower left x coordinate |
---|
| 449 | * @param minY the lower left y coordinate |
---|
| 450 | * @param maxX the upper right x coordinate |
---|
| 451 | * @param maxY the upper right y coordinate |
---|
| 452 | * @see setMapSize |
---|
| 453 | */ |
---|
[297] | 454 | void setMsExtent(maps* output,mapObj* m,layerObj* myLayer, |
---|
| 455 | double minX,double minY,double maxX,double maxY){ |
---|
| 456 | msMapSetExtent(m,minX,minY,maxX,maxY); |
---|
| 457 | #ifdef DEBUGMS |
---|
| 458 | fprintf(stderr,"Extent %.15f %.15f %.15f %.15f\n",minX,minY,maxX,maxY); |
---|
| 459 | #endif |
---|
| 460 | char tmpExtent[1024]; |
---|
| 461 | sprintf(tmpExtent,"%.15f %.15f %.15f %.15f",minX,minY,maxX,maxY); |
---|
| 462 | #ifdef DEBUGMS |
---|
| 463 | fprintf(stderr,"Extent %s\n",tmpExtent); |
---|
| 464 | #endif |
---|
| 465 | msInsertHashTable(&(myLayer->metadata), "ows_extent", tmpExtent); |
---|
| 466 | |
---|
| 467 | if(output!=NULL){ |
---|
[357] | 468 | map* test=getMap(output->content,"real_extent"); |
---|
| 469 | if(test!=NULL){ |
---|
| 470 | pointObj min, max; |
---|
| 471 | projectionObj tempSrs; |
---|
| 472 | min.x = m->extent.minx; |
---|
| 473 | min.y = m->extent.miny; |
---|
| 474 | max.x = m->extent.maxx; |
---|
| 475 | max.y = m->extent.maxy; |
---|
| 476 | char tmpSrsStr[1024]; |
---|
| 477 | msInitProjection(&tempSrs); |
---|
| 478 | msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326"); |
---|
[360] | 479 | |
---|
[357] | 480 | msProjectPoint(&(m->projection),&tempSrs,&min); |
---|
| 481 | msProjectPoint(&m->projection,&tempSrs,&max); |
---|
| 482 | |
---|
| 483 | sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x); |
---|
[360] | 484 | map* isGeo=getMap(output->content,"crs_isGeographic"); |
---|
[434] | 485 | #ifdef DEBUGMS |
---|
[360] | 486 | fprintf(stderr,"isGeo = %s\n",isGeo->value); |
---|
[434] | 487 | #endif |
---|
[360] | 488 | if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0) |
---|
| 489 | sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX); |
---|
[357] | 490 | addToMap(output->content,"wms_extent",tmpExtent); |
---|
[360] | 491 | sprintf(tmpSrsStr,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y); |
---|
[357] | 492 | addToMap(output->content,"wcs_extent",tmpExtent); |
---|
| 493 | }else{ |
---|
| 494 | sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY); |
---|
| 495 | map* isGeo=getMap(output->content,"crs_isGeographic"); |
---|
[402] | 496 | if(isGeo!=NULL){ |
---|
[434] | 497 | #ifdef DEBUGMS |
---|
[402] | 498 | fprintf(stderr,"isGeo = %s\n",isGeo->value); |
---|
[434] | 499 | #endif |
---|
[402] | 500 | if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0) |
---|
| 501 | sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX); |
---|
| 502 | } |
---|
[357] | 503 | addToMap(output->content,"wms_extent",tmpExtent); |
---|
| 504 | sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",minX,minY,maxX,maxY); |
---|
[360] | 505 | addToMap(output->content,"wcs_extent",tmpExtent); |
---|
[357] | 506 | } |
---|
[297] | 507 | } |
---|
| 508 | |
---|
| 509 | setMapSize(output,minX,minY,maxX,maxY); |
---|
| 510 | } |
---|
| 511 | |
---|
[586] | 512 | /** |
---|
| 513 | * Try to open a vector output and define the corresponding layer in the MAPFILE |
---|
| 514 | * |
---|
| 515 | * @param conf the conf maps containing the main.cfg settings |
---|
| 516 | * @param output the specific output maps |
---|
| 517 | * @param m the mapObj |
---|
| 518 | */ |
---|
[297] | 519 | int tryOgr(maps* conf,maps* output,mapObj* m){ |
---|
| 520 | |
---|
| 521 | map* tmpMap=getMap(output->content,"storage"); |
---|
| 522 | char *pszDataSource=tmpMap->value; |
---|
| 523 | |
---|
| 524 | /** |
---|
| 525 | * Try to open the DataSource using OGR |
---|
| 526 | */ |
---|
| 527 | OGRRegisterAll(); |
---|
| 528 | /** |
---|
| 529 | * Try to load the file as ZIP |
---|
[854] | 530 | * |
---|
[364] | 531 | OGRDataSourceH poDS1 = NULL; |
---|
[297] | 532 | OGRSFDriverH *poDriver1 = NULL; |
---|
| 533 | char *dsName=(char*)malloc((8+strlen(pszDataSource)+1)*sizeof(char)); |
---|
[453] | 534 | char *odsName=zStrdup(pszDataSource); |
---|
| 535 | char *sdsName=zStrdup(pszDataSource); |
---|
[623] | 536 | char *demo=".data"; |
---|
[297] | 537 | sdsName[strlen(sdsName)-(strlen(demo)-1)]='d'; |
---|
| 538 | sdsName[strlen(sdsName)-(strlen(demo)-2)]='i'; |
---|
| 539 | sdsName[strlen(sdsName)-(strlen(demo)-3)]='r'; |
---|
| 540 | sdsName[strlen(sdsName)-(strlen(demo)-4)]=0; |
---|
| 541 | |
---|
| 542 | odsName[strlen(odsName)-(strlen(demo)-1)]='z'; |
---|
| 543 | odsName[strlen(odsName)-(strlen(demo)-2)]='i'; |
---|
| 544 | odsName[strlen(odsName)-(strlen(demo)-3)]='p'; |
---|
| 545 | odsName[strlen(odsName)-(strlen(demo)-4)]=0; |
---|
| 546 | sprintf(dsName,"/vsizip/%s",odsName); |
---|
| 547 | |
---|
| 548 | #ifdef DEBUGMS |
---|
| 549 | fprintf(stderr,"Try loading %s, %s, %s\n",dsName,odsName,dsName); |
---|
| 550 | #endif |
---|
| 551 | |
---|
| 552 | FILE* file = fopen(pszDataSource, "rb"); |
---|
| 553 | FILE* fileZ = fopen(odsName, "wb"); |
---|
[492] | 554 | free(odsName); |
---|
[297] | 555 | fseek(file, 0, SEEK_END); |
---|
| 556 | unsigned long fileLen=ftell(file); |
---|
| 557 | fseek(file, 0, SEEK_SET); |
---|
| 558 | char *buffer=(char *)malloc(fileLen+1); |
---|
| 559 | fread(buffer, fileLen, 1, file); |
---|
| 560 | fwrite(buffer,fileLen, 1, fileZ); |
---|
| 561 | fclose(file); |
---|
| 562 | fclose(fileZ); |
---|
| 563 | free(buffer); |
---|
[434] | 564 | #ifdef DEBUGMS |
---|
[297] | 565 | fprintf(stderr,"Try loading %s",dsName); |
---|
[434] | 566 | #endif |
---|
[297] | 567 | poDS1 = OGROpen( dsName, FALSE, poDriver1 ); |
---|
| 568 | if( poDS1 == NULL ){ |
---|
| 569 | fprintf(stderr,"Unable to access the DataSource as ZIP File\n"); |
---|
| 570 | setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); |
---|
[854] | 571 | fprintf(stderr,"Remove ZIP File!\n"); |
---|
| 572 | unlink(odsName); |
---|
[839] | 573 | //OGR_DS_Destroy(poDS1); |
---|
[297] | 574 | }else{ |
---|
[434] | 575 | #ifdef DEBUGMS |
---|
[297] | 576 | fprintf(stderr,"The DataSource is a ZIP File\n"); |
---|
[434] | 577 | #endif |
---|
[297] | 578 | char** demo=VSIReadDir(dsName); |
---|
| 579 | int i=0; |
---|
[453] | 580 | zMkdir(sdsName |
---|
[364] | 581 | #ifndef WIN32 |
---|
| 582 | ,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH |
---|
| 583 | #endif |
---|
| 584 | ); |
---|
[297] | 585 | while(demo[i]!=NULL){ |
---|
[434] | 586 | #ifdef DEBUGMS |
---|
[297] | 587 | fprintf(stderr,"ZIP File content : %s\n",demo[i]); |
---|
[434] | 588 | #endif |
---|
[297] | 589 | char *tmpDs=(char*)malloc((strlen(dsName)+strlen(demo[i])+2)*sizeof(char)); |
---|
| 590 | sprintf(tmpDs,"%s/%s",dsName,demo[i]); |
---|
| 591 | fprintf(stderr,"read : %s\n",tmpDs); |
---|
| 592 | |
---|
| 593 | VSILFILE* vsif=VSIFOpenL(tmpDs,"rb"); |
---|
[434] | 594 | #ifdef DEBUGMS |
---|
[297] | 595 | fprintf(stderr,"open : %s\n",tmpDs); |
---|
[434] | 596 | #endif |
---|
[297] | 597 | VSIFSeekL(vsif,0,SEEK_END); |
---|
[453] | 598 | vsi_l_offset size=VSIFTellL(vsif); |
---|
[434] | 599 | #ifdef DEBUGMS |
---|
[297] | 600 | fprintf(stderr,"size : %d\n",size); |
---|
[434] | 601 | #endif |
---|
[297] | 602 | VSIFSeekL(vsif,0,SEEK_SET); |
---|
[453] | 603 | char *vsifcontent=(char*) malloc(((int)size+1)*sizeof(char)); |
---|
| 604 | VSIFReadL(vsifcontent,1,(size_t)size,vsif); |
---|
[297] | 605 | char *fpath=(char*) malloc((strlen(sdsName)+strlen(demo[1])+2)*sizeof(char)); |
---|
| 606 | sprintf(fpath,"%s/%s",sdsName,demo[i]); |
---|
[453] | 607 | int f=zOpen(fpath,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); |
---|
| 608 | zWrite(f,vsifcontent,(int)size); |
---|
[297] | 609 | close(f); |
---|
| 610 | chmod(fpath,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH); |
---|
| 611 | char* tmpP=strstr(fpath,".shp"); |
---|
| 612 | if(tmpP==NULL) |
---|
| 613 | tmpP=strstr(fpath,".SHP"); |
---|
| 614 | if(tmpP!=NULL){ |
---|
[434] | 615 | #ifdef DEBUGMS |
---|
[297] | 616 | fprintf(stderr,"*** DEBUG %s\n",strstr(tmpP,".")); |
---|
[434] | 617 | #endif |
---|
[297] | 618 | if( strcmp(tmpP,".shp")==0 || strcmp(tmpP,".SHP")==0 ){ |
---|
| 619 | tmpMap=getMap(output->content,"storage"); |
---|
| 620 | free(tmpMap->value); |
---|
| 621 | tmpMap->value=(char*) malloc((strlen(fpath)+1)*sizeof(char)); |
---|
| 622 | sprintf(tmpMap->value,"%s",fpath); |
---|
| 623 | pszDataSource=tmpMap->value; |
---|
[434] | 624 | #ifdef DEBUGMS |
---|
[297] | 625 | fprintf(stderr,"*** DEBUG %s\n",pszDataSource); |
---|
[434] | 626 | #endif |
---|
[297] | 627 | } |
---|
| 628 | } |
---|
| 629 | VSIFCloseL(vsif); |
---|
| 630 | i++; |
---|
| 631 | } |
---|
[851] | 632 | OGR_DS_Destroy(poDS1); |
---|
[854] | 633 | } |
---|
[492] | 634 | free(sdsName); |
---|
[854] | 635 | free(dsName);*/ |
---|
[850] | 636 | |
---|
[364] | 637 | OGRDataSourceH poDS = NULL; |
---|
[297] | 638 | OGRSFDriverH *poDriver = NULL; |
---|
| 639 | poDS = OGROpen( pszDataSource, FALSE, poDriver ); |
---|
| 640 | if( poDS == NULL ){ |
---|
| 641 | #ifdef DEBUGMS |
---|
| 642 | fprintf(stderr,"Unable to access the DataSource %s\n",pszDataSource); |
---|
| 643 | #endif |
---|
| 644 | setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); |
---|
[839] | 645 | //OGR_DS_Destroy(poDS); |
---|
| 646 | //OGRCleanupAll(); |
---|
[297] | 647 | #ifdef DEBUGMS |
---|
| 648 | fprintf(stderr,"Unable to access the DataSource, exit! \n"); |
---|
| 649 | #endif |
---|
| 650 | return -1; |
---|
| 651 | } |
---|
| 652 | |
---|
[851] | 653 | addToMap(output->content,"geodatatype","vector"); |
---|
[297] | 654 | int iLayer = 0; |
---|
| 655 | for( iLayer=0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++ ){ |
---|
[364] | 656 | OGRLayerH poLayer = OGR_DS_GetLayer(poDS,iLayer); |
---|
[297] | 657 | |
---|
| 658 | if( poLayer == NULL ){ |
---|
| 659 | #ifdef DEBUGMS |
---|
| 660 | fprintf(stderr,"Unable to access the DataSource Layer \n"); |
---|
| 661 | #endif |
---|
| 662 | setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); |
---|
| 663 | return -1; |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | /** |
---|
| 667 | * Add a new layer set name, data |
---|
| 668 | */ |
---|
| 669 | if(msGrowMapLayers(m)==NULL){ |
---|
| 670 | return -1; |
---|
| 671 | } |
---|
| 672 | if(initLayer((m->layers[m->numlayers]), m) == -1){ |
---|
| 673 | return -1; |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | layerObj* myLayer=m->layers[m->numlayers]; |
---|
[434] | 677 | #ifdef DEBUGMS |
---|
[297] | 678 | dumpMaps(output); |
---|
[434] | 679 | #endif |
---|
[453] | 680 | myLayer->name = zStrdup(output->name); |
---|
[297] | 681 | myLayer->tileitem=NULL; |
---|
[453] | 682 | myLayer->data = zStrdup(OGR_L_GetName(poLayer)); |
---|
| 683 | myLayer->connection = zStrdup(pszDataSource); |
---|
[297] | 684 | myLayer->index = m->numlayers; |
---|
| 685 | myLayer->dump = MS_TRUE; |
---|
| 686 | myLayer->status = MS_ON; |
---|
| 687 | msConnectLayer(myLayer,MS_OGR,pszDataSource); |
---|
| 688 | |
---|
[854] | 689 | addIntToMap(output->content,"nb_features",OGR_L_GetFeatureCount(poLayer,1)); |
---|
| 690 | |
---|
[297] | 691 | /** |
---|
| 692 | * Detect the Geometry Type or use Polygon |
---|
| 693 | */ |
---|
| 694 | if(OGR_L_GetGeomType(poLayer) != wkbUnknown){ |
---|
| 695 | switch(OGR_L_GetGeomType(poLayer)){ |
---|
| 696 | case wkbPoint: |
---|
| 697 | case wkbMultiPoint: |
---|
| 698 | case wkbPoint25D: |
---|
| 699 | case wkbMultiPoint25D: |
---|
| 700 | #ifdef DEBUGMS |
---|
| 701 | fprintf(stderr,"POINT DataSource Layer \n"); |
---|
| 702 | #endif |
---|
| 703 | myLayer->type = MS_LAYER_POINT; |
---|
| 704 | break; |
---|
| 705 | case wkbLineString : |
---|
| 706 | case wkbMultiLineString : |
---|
| 707 | case wkbLineString25D: |
---|
| 708 | case wkbMultiLineString25D: |
---|
| 709 | #ifdef DEBUGMS |
---|
| 710 | fprintf(stderr,"LINE DataSource Layer \n"); |
---|
| 711 | #endif |
---|
| 712 | myLayer->type = MS_LAYER_LINE; |
---|
| 713 | break; |
---|
| 714 | case wkbPolygon: |
---|
| 715 | case wkbMultiPolygon: |
---|
| 716 | case wkbPolygon25D: |
---|
| 717 | case wkbMultiPolygon25D: |
---|
| 718 | #ifdef DEBUGMS |
---|
| 719 | fprintf(stderr,"POLYGON DataSource Layer \n"); |
---|
| 720 | #endif |
---|
| 721 | myLayer->type = MS_LAYER_POLYGON; |
---|
| 722 | break; |
---|
| 723 | default: |
---|
| 724 | myLayer->type = MS_LAYER_POLYGON; |
---|
| 725 | break; |
---|
| 726 | } |
---|
| 727 | }else |
---|
| 728 | myLayer->type = MS_LAYER_POLYGON; |
---|
| 729 | |
---|
| 730 | /** |
---|
| 731 | * Detect spatial reference or use WGS84 |
---|
| 732 | */ |
---|
| 733 | OGRSpatialReferenceH srs=OGR_L_GetSpatialRef(poLayer); |
---|
| 734 | if(srs!=NULL){ |
---|
| 735 | char *wkt=NULL; |
---|
| 736 | OSRExportToWkt(srs,&wkt); |
---|
| 737 | setSrsInformations(output,m,myLayer,wkt); |
---|
[492] | 738 | free(wkt); |
---|
[297] | 739 | } |
---|
| 740 | else{ |
---|
| 741 | addToMap(output->content,"crs","EPSG:4326"); |
---|
| 742 | addToMap(output->content,"crs_isGeographic","true"); |
---|
| 743 | msLoadProjectionStringEPSG(&m->projection,"EPSG:4326"); |
---|
[776] | 744 | msInsertHashTable(&(m->web.metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857"); |
---|
| 745 | msInsertHashTable(&(myLayer->metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857"); |
---|
[297] | 746 | } |
---|
| 747 | |
---|
| 748 | OGREnvelope oExt; |
---|
| 749 | if (OGR_L_GetExtent(poLayer,&oExt, TRUE) == OGRERR_NONE){ |
---|
| 750 | setMsExtent(output,m,myLayer,oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY); |
---|
[839] | 751 | char extent[1024]; |
---|
| 752 | memset(&extent,0,1024); |
---|
| 753 | sprintf(extent,"%d,%d,%d,%d",oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY); |
---|
| 754 | addToMap(output->content,"boundingbox",extent); |
---|
[297] | 755 | } |
---|
| 756 | |
---|
| 757 | /** |
---|
| 758 | * Detect the FID column or use the first attribute field as FID |
---|
| 759 | */ |
---|
[364] | 760 | char *fid=(char*)OGR_L_GetFIDColumn(poLayer); |
---|
[297] | 761 | if(strlen(fid)==0){ |
---|
| 762 | OGRFeatureDefnH def=OGR_L_GetLayerDefn(poLayer); |
---|
| 763 | int fIndex=0; |
---|
| 764 | for(fIndex=0;fIndex<OGR_FD_GetFieldCount(def);fIndex++){ |
---|
| 765 | OGRFieldDefnH fdef=OGR_FD_GetFieldDefn(def,fIndex); |
---|
[364] | 766 | fid=(char*)OGR_Fld_GetNameRef(fdef); |
---|
[297] | 767 | break; |
---|
| 768 | } |
---|
| 769 | } |
---|
| 770 | msInsertHashTable(&(myLayer->metadata), "gml_featureid", fid); |
---|
| 771 | msInsertHashTable(&(myLayer->metadata), "gml_include_items", "all"); |
---|
| 772 | msInsertHashTable(&(myLayer->metadata), "ows_name", output->name); |
---|
| 773 | map* tmpMap=getMap(output->content,"title"); |
---|
| 774 | if(tmpMap!=NULL) |
---|
| 775 | msInsertHashTable(&(myLayer->metadata), "ows_title", tmpMap->value); |
---|
| 776 | else |
---|
| 777 | msInsertHashTable(&(myLayer->metadata), "ows_title", "Default Title"); |
---|
[379] | 778 | |
---|
[297] | 779 | if(msGrowLayerClasses(myLayer) == NULL) |
---|
[364] | 780 | return -1; |
---|
[370] | 781 | if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1) |
---|
[364] | 782 | return -1; |
---|
[370] | 783 | if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL) |
---|
[364] | 784 | return -1; |
---|
[370] | 785 | if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1) |
---|
[364] | 786 | return -1; |
---|
[297] | 787 | /** |
---|
| 788 | * Apply msStyle else fallback to the default style |
---|
| 789 | */ |
---|
| 790 | tmpMap=getMap(output->content,"msStyle"); |
---|
| 791 | if(tmpMap!=NULL) |
---|
[370] | 792 | msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0); |
---|
[297] | 793 | else{ |
---|
| 794 | /** |
---|
| 795 | * Set style |
---|
| 796 | */ |
---|
[370] | 797 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125; |
---|
| 798 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125; |
---|
| 799 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255; |
---|
| 800 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80; |
---|
| 801 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80; |
---|
| 802 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80; |
---|
[379] | 803 | |
---|
[297] | 804 | /** |
---|
| 805 | * Set specific style depending on type |
---|
| 806 | */ |
---|
| 807 | if(myLayer->type == MS_LAYER_POLYGON) |
---|
[370] | 808 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; |
---|
[297] | 809 | if(myLayer->type == MS_LAYER_LINE){ |
---|
[370] | 810 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3; |
---|
| 811 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5; |
---|
[297] | 812 | } |
---|
| 813 | if(myLayer->type == MS_LAYER_POINT){ |
---|
[370] | 814 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1; |
---|
| 815 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15; |
---|
[297] | 816 | } |
---|
[379] | 817 | |
---|
[297] | 818 | } |
---|
[370] | 819 | myLayer->CLASS[myLayer->numclasses]->numstyles++; |
---|
[297] | 820 | myLayer->numclasses++; |
---|
[379] | 821 | |
---|
[297] | 822 | m->layerorder[m->numlayers] = m->numlayers; |
---|
| 823 | m->numlayers++; |
---|
| 824 | |
---|
| 825 | } |
---|
| 826 | |
---|
[851] | 827 | OGR_DS_Destroy(poDS); |
---|
[839] | 828 | //OGRCleanupAll(); |
---|
[297] | 829 | |
---|
| 830 | return 1; |
---|
| 831 | } |
---|
| 832 | |
---|
[586] | 833 | /** |
---|
| 834 | * Try to open a raster output and define the corresponding layer in the MAPFILE |
---|
| 835 | * |
---|
| 836 | * @param conf the conf maps containing the main.cfg settings |
---|
| 837 | * @param output the specific output maps |
---|
| 838 | * @param m the mapObj |
---|
| 839 | */ |
---|
[297] | 840 | int tryGdal(maps* conf,maps* output,mapObj* m){ |
---|
| 841 | map* tmpMap=getMap(output->content,"storage"); |
---|
| 842 | char *pszFilename=tmpMap->value; |
---|
| 843 | GDALDatasetH hDataset; |
---|
| 844 | GDALRasterBandH hBand; |
---|
| 845 | double adfGeoTransform[6]; |
---|
| 846 | int i, iBand; |
---|
| 847 | |
---|
| 848 | /** |
---|
| 849 | * Try to open the DataSource using GDAL |
---|
| 850 | */ |
---|
| 851 | GDALAllRegister(); |
---|
[854] | 852 | hDataset = GDALOpen( pszFilename, GA_Update ); |
---|
[297] | 853 | if( hDataset == NULL ){ |
---|
| 854 | #ifdef DEBUGMS |
---|
[366] | 855 | fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename); |
---|
[297] | 856 | #endif |
---|
[851] | 857 | addToMap(output->content,"geodatatype","other"); |
---|
[297] | 858 | setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open"); |
---|
| 859 | GDALDestroyDriverManager(); |
---|
| 860 | return -1; |
---|
| 861 | } |
---|
| 862 | #ifdef DEBUGMS |
---|
[451] | 863 | fprintf(stderr,"Accessing the DataSource %s %d\n",pszFilename,__LINE__); |
---|
[297] | 864 | #endif |
---|
| 865 | |
---|
[851] | 866 | addToMap(output->content,"geodatatype","raster"); |
---|
[297] | 867 | /** |
---|
| 868 | * Add a new layer set name, data |
---|
| 869 | */ |
---|
| 870 | if(msGrowMapLayers(m)==NULL){ |
---|
| 871 | return -1; |
---|
| 872 | } |
---|
| 873 | if(initLayer((m->layers[m->numlayers]), m) == -1){ |
---|
| 874 | return -1; |
---|
| 875 | } |
---|
[451] | 876 | m->layers[m->numlayers]->index=m->numlayers; |
---|
[297] | 877 | |
---|
| 878 | layerObj* myLayer=m->layers[m->numlayers]; |
---|
[453] | 879 | myLayer->name = zStrdup(output->name); |
---|
[297] | 880 | myLayer->tileitem=NULL; |
---|
[453] | 881 | myLayer->data = zStrdup(pszFilename); |
---|
[297] | 882 | myLayer->index = m->numlayers; |
---|
| 883 | myLayer->dump = MS_TRUE; |
---|
| 884 | myLayer->status = MS_ON; |
---|
| 885 | myLayer->type = MS_LAYER_RASTER; |
---|
| 886 | |
---|
| 887 | char *title=output->name; |
---|
| 888 | tmpMap=getMap(output->content,"title"); |
---|
| 889 | if(tmpMap!=NULL) |
---|
| 890 | title=tmpMap->value; |
---|
| 891 | char *abstract=output->name; |
---|
| 892 | tmpMap=getMap(output->content,"abstract"); |
---|
| 893 | if(tmpMap!=NULL) |
---|
| 894 | abstract=tmpMap->value; |
---|
[451] | 895 | |
---|
[297] | 896 | msInsertHashTable(&(myLayer->metadata), "ows_label", title); |
---|
| 897 | msInsertHashTable(&(myLayer->metadata), "ows_title", title); |
---|
| 898 | msInsertHashTable(&(myLayer->metadata), "ows_abstract", abstract); |
---|
| 899 | msInsertHashTable(&(myLayer->metadata), "ows_rangeset_name", output->name); |
---|
| 900 | msInsertHashTable(&(myLayer->metadata), "ows_rangeset_label", title); |
---|
| 901 | |
---|
| 902 | /** |
---|
| 903 | * Set Map Size to the raster size |
---|
| 904 | */ |
---|
| 905 | m->width=GDALGetRasterXSize( hDataset ); |
---|
| 906 | m->height=GDALGetRasterYSize( hDataset ); |
---|
[854] | 907 | addIntToMap(output->content,"nb_pixels",GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset )); |
---|
[297] | 908 | |
---|
| 909 | /** |
---|
| 910 | * Set projection using Authority Code and Name if available or fallback to |
---|
| 911 | * proj4 definition if available or fallback to default EPSG:4326 |
---|
| 912 | */ |
---|
[366] | 913 | const char *tRef=GDALGetProjectionRef( hDataset ); |
---|
| 914 | if( tRef != NULL && strlen(tRef)>0 ){ |
---|
[297] | 915 | char *pszProjection; |
---|
| 916 | pszProjection = (char *) GDALGetProjectionRef( hDataset ); |
---|
[607] | 917 | #ifdef DEBUGMS |
---|
[297] | 918 | fprintf(stderr,"Accessing the DataSource %s\n",GDALGetProjectionRef( hDataset )); |
---|
[607] | 919 | #endif |
---|
[297] | 920 | setSrsInformations(output,m,myLayer,pszProjection); |
---|
[453] | 921 | }else{ |
---|
[854] | 922 | fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset )); |
---|
| 923 | CPLErr sp=GDALSetProjection( hDataset , "+init=epsg:4326" ); |
---|
| 924 | if(sp!=CE_None){ |
---|
| 925 | fprintf(stderr,"NO SRS FOUND ! %s\n",CPLGetLastErrorMsg()); |
---|
| 926 | } |
---|
[453] | 927 | } |
---|
[297] | 928 | |
---|
| 929 | /** |
---|
| 930 | * Set extent |
---|
| 931 | */ |
---|
| 932 | if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None ){ |
---|
| 933 | if( adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0 ){ |
---|
| 934 | |
---|
| 935 | double minX = adfGeoTransform[0] |
---|
| 936 | + adfGeoTransform[2] * GDALGetRasterYSize(hDataset); |
---|
| 937 | double minY = adfGeoTransform[3] |
---|
| 938 | + adfGeoTransform[5] * GDALGetRasterYSize(hDataset); |
---|
| 939 | |
---|
| 940 | double maxX = adfGeoTransform[0] |
---|
| 941 | + adfGeoTransform[1] * GDALGetRasterXSize(hDataset); |
---|
| 942 | double maxY = adfGeoTransform[3] |
---|
| 943 | + adfGeoTransform[4] * GDALGetRasterXSize(hDataset); |
---|
| 944 | |
---|
[839] | 945 | setMsExtent(output,m,myLayer,minX,minY,maxX,maxY); |
---|
| 946 | char extent[1024]; |
---|
| 947 | memset(&extent,0,1024); |
---|
| 948 | sprintf(extent,"%d,%d,%d,%d",minX,minY,maxX,maxY); |
---|
| 949 | addToMap(output->content,"boundingbox",extent); |
---|
[297] | 950 | } |
---|
[854] | 951 | }else{ |
---|
| 952 | int scale=1; |
---|
| 953 | if(m->width>2048){ |
---|
| 954 | addIntToMap(output->content,"width",2048); |
---|
| 955 | scale=2048/m->width; |
---|
| 956 | }else |
---|
| 957 | addIntToMap(output->content,"width",m->width); |
---|
| 958 | addIntToMap(output->content,"height",m->height*scale); |
---|
[297] | 959 | } |
---|
| 960 | |
---|
| 961 | /** |
---|
| 962 | * Extract information about available bands to set the bandcount and the |
---|
| 963 | * processing directive |
---|
| 964 | */ |
---|
[781] | 965 | char nBands[3]; |
---|
[839] | 966 | memset(&nBands,0,3); |
---|
[297] | 967 | int nBandsI=GDALGetRasterCount( hDataset ); |
---|
[839] | 968 | if(nBandsI<100){ |
---|
| 969 | sprintf(nBands,"%d",GDALGetRasterCount( hDataset )); |
---|
| 970 | msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands); |
---|
| 971 | } |
---|
[297] | 972 | if(nBandsI>=3) |
---|
[854] | 973 | if(nBandsI==4) |
---|
| 974 | msLayerAddProcessing(myLayer,"BANDS=1,2,3,4"); |
---|
| 975 | else |
---|
| 976 | msLayerAddProcessing(myLayer,"BANDS=1,2,3"); |
---|
[297] | 977 | else if(nBandsI>=2) |
---|
| 978 | msLayerAddProcessing(myLayer,"BANDS=1,2"); |
---|
| 979 | else |
---|
| 980 | msLayerAddProcessing(myLayer,"BANDS=1"); |
---|
[854] | 981 | |
---|
[297] | 982 | |
---|
| 983 | /** |
---|
| 984 | * Name available Bands |
---|
| 985 | */ |
---|
[781] | 986 | char lBands[7]; |
---|
[297] | 987 | char *nameBands=NULL; |
---|
| 988 | for( iBand = 0; iBand < nBandsI; iBand++ ){ |
---|
[854] | 989 | memset(&lBands,0,7); |
---|
[839] | 990 | sprintf(lBands,"Band%d",iBand+1); |
---|
[297] | 991 | if(nameBands==NULL){ |
---|
| 992 | nameBands=(char*)malloc((strlen(lBands)+1)*sizeof(char)); |
---|
| 993 | sprintf(nameBands,"%s",lBands); |
---|
| 994 | }else{ |
---|
[854] | 995 | /*if(iBand<4)*/{ |
---|
[453] | 996 | char *tmpS=zStrdup(nameBands); |
---|
[839] | 997 | nameBands=(char*)realloc(nameBands,(strlen(tmpS)+strlen(lBands)+2)*sizeof(char)); |
---|
[297] | 998 | sprintf(nameBands,"%s %s",tmpS,lBands); |
---|
| 999 | free(tmpS); |
---|
| 1000 | } |
---|
| 1001 | } |
---|
| 1002 | } |
---|
[839] | 1003 | if(nameBands!=NULL){ |
---|
| 1004 | msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands); |
---|
| 1005 | free(nameBands); |
---|
| 1006 | } |
---|
| 1007 | |
---|
[297] | 1008 | /** |
---|
[781] | 1009 | * Loops over metadata information to setup specific information |
---|
[297] | 1010 | */ |
---|
| 1011 | for( iBand = 0; iBand < nBandsI; iBand++ ){ |
---|
[854] | 1012 | double pdfMin, pdfMax, pdfMean, pdfStdDev; |
---|
[297] | 1013 | hBand = GDALGetRasterBand( hDataset, iBand+1 ); |
---|
| 1014 | |
---|
| 1015 | CPLErrorReset(); |
---|
[854] | 1016 | GDALComputeRasterStatistics( hBand, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev, NULL,NULL); |
---|
[297] | 1017 | char tmpN[21]; |
---|
| 1018 | sprintf(tmpN,"Band%d",iBand+1); |
---|
| 1019 | if (CPLGetLastErrorType() == CE_None){ |
---|
[854] | 1020 | char tmpMm[100],tmpMp[100]; |
---|
| 1021 | sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); |
---|
| 1022 | sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev)); |
---|
[839] | 1023 | char tmpI[31]; |
---|
[297] | 1024 | sprintf(tmpI,"%s_interval",tmpN); |
---|
| 1025 | msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm); |
---|
[854] | 1026 | if(pdfMax>255) |
---|
| 1027 | msLayerAddProcessing(myLayer,tmpMp); |
---|
[300] | 1028 | map* test=getMap(output->content,"msClassify"); |
---|
| 1029 | if(test!=NULL && strncasecmp(test->value,"true",4)==0){ |
---|
| 1030 | /** |
---|
| 1031 | * Classify one band raster pixel value using regular interval |
---|
| 1032 | */ |
---|
| 1033 | int _tmpColors[10][3]={ |
---|
| 1034 | {102,153,204}, |
---|
| 1035 | {51,102,153}, |
---|
| 1036 | {102,102,204}, |
---|
| 1037 | {51,204,0}, |
---|
| 1038 | {153,255,102}, |
---|
| 1039 | {204,255,102}, |
---|
| 1040 | {102,204,153}, |
---|
| 1041 | {255,69,64}, |
---|
| 1042 | {255,192,115}, |
---|
| 1043 | {255,201,115} |
---|
| 1044 | }; |
---|
| 1045 | |
---|
| 1046 | if(nBandsI==1){ |
---|
[854] | 1047 | double delta=pdfMax-pdfMin; |
---|
[300] | 1048 | double interval=delta/10; |
---|
[854] | 1049 | double cstep=pdfMin; |
---|
[300] | 1050 | for(i=0;i<10;i++){ |
---|
| 1051 | /** |
---|
| 1052 | * Create a new class |
---|
| 1053 | */ |
---|
| 1054 | if(msGrowLayerClasses(myLayer) == NULL) |
---|
[364] | 1055 | return -1; |
---|
[370] | 1056 | if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1) |
---|
[364] | 1057 | return -1; |
---|
[370] | 1058 | if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL) |
---|
[364] | 1059 | return -1; |
---|
[370] | 1060 | if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1) |
---|
[364] | 1061 | return -1; |
---|
[300] | 1062 | |
---|
| 1063 | /** |
---|
| 1064 | * Set class name |
---|
| 1065 | */ |
---|
| 1066 | char className[7]; |
---|
| 1067 | sprintf(className,"class%d",i); |
---|
[453] | 1068 | myLayer->CLASS[myLayer->numclasses]->name=zStrdup(className); |
---|
[300] | 1069 | |
---|
| 1070 | /** |
---|
| 1071 | * Set expression |
---|
| 1072 | */ |
---|
| 1073 | char expression[1024]; |
---|
| 1074 | if(i+1<10) |
---|
| 1075 | sprintf(expression,"([pixel]>=%.3f AND [pixel]<%.3f)",cstep,cstep+interval); |
---|
| 1076 | else |
---|
| 1077 | sprintf(expression,"([pixel]>=%.3f AND [pixel]<=%.3f)",cstep,cstep+interval); |
---|
[370] | 1078 | msLoadExpressionString(&myLayer->CLASS[myLayer->numclasses]->expression,expression); |
---|
[300] | 1079 | |
---|
| 1080 | /** |
---|
| 1081 | * Set color |
---|
| 1082 | */ |
---|
[370] | 1083 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=_tmpColors[i][0]; |
---|
| 1084 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=_tmpColors[i][1]; |
---|
| 1085 | myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=_tmpColors[i][2]; |
---|
[300] | 1086 | cstep+=interval; |
---|
[370] | 1087 | myLayer->CLASS[myLayer->numclasses]->numstyles++; |
---|
[300] | 1088 | myLayer->numclasses++; |
---|
| 1089 | |
---|
| 1090 | } |
---|
| 1091 | |
---|
| 1092 | char tmpMm[100]; |
---|
[854] | 1093 | sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); |
---|
[300] | 1094 | |
---|
[297] | 1095 | } |
---|
| 1096 | } |
---|
[752] | 1097 | else{ |
---|
| 1098 | if(nBandsI==1){ |
---|
| 1099 | myLayer->offsite.red=0; |
---|
| 1100 | myLayer->offsite.green=0; |
---|
| 1101 | myLayer->offsite.blue=0; |
---|
| 1102 | } |
---|
| 1103 | } |
---|
[297] | 1104 | } |
---|
| 1105 | if( strlen(GDALGetRasterUnitType(hBand)) > 0 ){ |
---|
[839] | 1106 | char tmpU[31]; |
---|
[297] | 1107 | sprintf(tmpU,"%s_band_uom",tmpN); |
---|
| 1108 | msInsertHashTable(&(myLayer->metadata), tmpU, GDALGetRasterUnitType(hBand)); |
---|
| 1109 | } |
---|
| 1110 | |
---|
| 1111 | } |
---|
[854] | 1112 | msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR"); |
---|
[297] | 1113 | |
---|
| 1114 | m->layerorder[m->numlayers] = m->numlayers; |
---|
| 1115 | m->numlayers++; |
---|
| 1116 | GDALClose( hDataset ); |
---|
| 1117 | GDALDestroyDriverManager(); |
---|
| 1118 | CPLCleanupTLS(); |
---|
| 1119 | return 1; |
---|
| 1120 | } |
---|
| 1121 | |
---|
| 1122 | /** |
---|
| 1123 | * Create a MapFile for WMS, WFS or WCS Service output |
---|
[586] | 1124 | * |
---|
| 1125 | * @param conf the conf maps containing the main.cfg settings |
---|
| 1126 | * @param outputs a specific output maps |
---|
[297] | 1127 | */ |
---|
| 1128 | void outputMapfile(maps* conf,maps* outputs){ |
---|
| 1129 | /** |
---|
[586] | 1130 | * First store the value on disk |
---|
[297] | 1131 | */ |
---|
[360] | 1132 | map* mime=getMap(outputs->content,"mimeType"); |
---|
| 1133 | char *ext="data"; |
---|
| 1134 | if(mime!=NULL) |
---|
| 1135 | if(strncasecmp(mime->value,"application/json",16)==0) |
---|
| 1136 | ext="json"; |
---|
[458] | 1137 | |
---|
[854] | 1138 | map* storage=getMap(outputs->content,"storage"); |
---|
| 1139 | if(storage==NULL){ |
---|
| 1140 | map* tmpMap=getMapFromMaps(conf,"main","dataPath"); |
---|
| 1141 | map* sidMap=getMapFromMaps(conf,"lenv","usid"); |
---|
| 1142 | char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); |
---|
| 1143 | sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); |
---|
| 1144 | int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); |
---|
| 1145 | map *gfile=getMap(outputs->content,"generated_file"); |
---|
| 1146 | if(gfile!=NULL){ |
---|
| 1147 | readGeneratedFile(conf,outputs->content,gfile->value); |
---|
| 1148 | } |
---|
| 1149 | map* sizeMap=getMap(outputs->content,"size"); |
---|
| 1150 | map* vData=getMap(outputs->content,"value"); |
---|
| 1151 | if(sizeMap!=NULL){ |
---|
| 1152 | zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); |
---|
| 1153 | } |
---|
| 1154 | else{ |
---|
| 1155 | zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); |
---|
| 1156 | } |
---|
| 1157 | close(f); |
---|
| 1158 | addToMap(outputs->content,"storage",pszDataSource); |
---|
| 1159 | free(pszDataSource); |
---|
[550] | 1160 | } |
---|
[297] | 1161 | |
---|
| 1162 | /* |
---|
| 1163 | * Create an empty map, set name, default size and extent |
---|
| 1164 | */ |
---|
| 1165 | mapObj *myMap=msNewMapObj(); |
---|
| 1166 | free(myMap->name); |
---|
[453] | 1167 | myMap->name=zStrdup("ZOO-Project_WXS_Server"); |
---|
[297] | 1168 | msMapSetSize(myMap,2048,2048); |
---|
| 1169 | msMapSetExtent(myMap,-1,-1,1,1); |
---|
| 1170 | |
---|
| 1171 | /* |
---|
| 1172 | * Set imagepath and imageurl using tmpPath and tmpUrl from main.cfg |
---|
| 1173 | */ |
---|
| 1174 | map *tmp1=getMapFromMaps(conf,"main","tmpPath"); |
---|
[453] | 1175 | myMap->web.imagepath=zStrdup(tmp1->value); |
---|
[297] | 1176 | tmp1=getMapFromMaps(conf,"main","tmpUrl"); |
---|
[453] | 1177 | myMap->web.imageurl=zStrdup(tmp1->value); |
---|
[297] | 1178 | |
---|
| 1179 | /* |
---|
| 1180 | * Define supported output formats |
---|
| 1181 | */ |
---|
| 1182 | outputFormatObj *o1=msCreateDefaultOutputFormat(NULL,"AGG/PNG","png"); |
---|
| 1183 | o1->imagemode=MS_IMAGEMODE_RGBA; |
---|
| 1184 | o1->transparent=MS_TRUE; |
---|
| 1185 | o1->inmapfile=MS_TRUE; |
---|
| 1186 | msAppendOutputFormat(myMap,msCloneOutputFormat(o1)); |
---|
| 1187 | msFreeOutputFormat(o1); |
---|
| 1188 | |
---|
| 1189 | #ifdef USE_KML |
---|
| 1190 | outputFormatObj *o2=msCreateDefaultOutputFormat(NULL,"KML","kml"); |
---|
[822] | 1191 | if(!o2){ |
---|
| 1192 | perror("Unable to initialize KML driver"); |
---|
| 1193 | fprintf(stderr,"Unable to initialize KML driver !\n"); |
---|
| 1194 | }else{ |
---|
| 1195 | o2->inmapfile=MS_TRUE; |
---|
| 1196 | msAppendOutputFormat(myMap,msCloneOutputFormat(o2)); |
---|
| 1197 | msFreeOutputFormat(o2); |
---|
| 1198 | } |
---|
[297] | 1199 | #endif |
---|
| 1200 | |
---|
| 1201 | outputFormatObj *o3=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","tiff"); |
---|
| 1202 | if(!o3) |
---|
| 1203 | fprintf(stderr,"Unable to initialize GDAL driver !\n"); |
---|
| 1204 | else{ |
---|
| 1205 | o3->imagemode=MS_IMAGEMODE_BYTE; |
---|
| 1206 | o3->inmapfile=MS_TRUE; |
---|
| 1207 | msAppendOutputFormat(myMap,msCloneOutputFormat(o3)); |
---|
| 1208 | msFreeOutputFormat(o3); |
---|
| 1209 | } |
---|
| 1210 | |
---|
| 1211 | outputFormatObj *o4=msCreateDefaultOutputFormat(NULL,"GDAL/AAIGRID","grd"); |
---|
| 1212 | if(!o4) |
---|
| 1213 | fprintf(stderr,"Unable to initialize GDAL driver !\n"); |
---|
| 1214 | else{ |
---|
| 1215 | o4->imagemode=MS_IMAGEMODE_INT16; |
---|
| 1216 | o4->inmapfile=MS_TRUE; |
---|
| 1217 | msAppendOutputFormat(myMap,msCloneOutputFormat(o4)); |
---|
| 1218 | msFreeOutputFormat(o4); |
---|
| 1219 | } |
---|
| 1220 | |
---|
| 1221 | #ifdef USE_CAIRO |
---|
| 1222 | outputFormatObj *o5=msCreateDefaultOutputFormat(NULL,"CAIRO/PNG","cairopng"); |
---|
| 1223 | if(!o5) |
---|
| 1224 | fprintf(stderr,"Unable to initialize CAIRO driver !\n"); |
---|
| 1225 | else{ |
---|
| 1226 | o5->imagemode=MS_IMAGEMODE_RGBA; |
---|
| 1227 | o5->transparent=MS_TRUE; |
---|
| 1228 | o5->inmapfile=MS_TRUE; |
---|
| 1229 | msAppendOutputFormat(myMap,msCloneOutputFormat(o5)); |
---|
| 1230 | msFreeOutputFormat(o5); |
---|
| 1231 | } |
---|
| 1232 | #endif |
---|
| 1233 | |
---|
[854] | 1234 | outputFormatObj *o6=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","geotiff"); |
---|
| 1235 | if(!o6) |
---|
| 1236 | fprintf(stderr,"Unable to initialize GDAL driver !\n"); |
---|
| 1237 | else{ |
---|
| 1238 | o6->imagemode=MS_IMAGEMODE_BYTE; |
---|
| 1239 | o6->mimetype=strdup("image/geotiff"); |
---|
| 1240 | o6->inmapfile=MS_TRUE; |
---|
| 1241 | msAppendOutputFormat(myMap,msCloneOutputFormat(o6)); |
---|
| 1242 | msFreeOutputFormat(o6); |
---|
| 1243 | } |
---|
| 1244 | |
---|
[297] | 1245 | /* |
---|
| 1246 | * Set default projection to EPSG:4326 |
---|
| 1247 | */ |
---|
| 1248 | msLoadProjectionStringEPSG(&myMap->projection,"EPSG:4326"); |
---|
| 1249 | myMap->transparent=1; |
---|
| 1250 | |
---|
| 1251 | /** |
---|
| 1252 | * Set metadata extracted from main.cfg file maps |
---|
| 1253 | */ |
---|
| 1254 | maps* cursor=conf; |
---|
| 1255 | map* correspondance=getCorrespondance(); |
---|
| 1256 | while(cursor!=NULL){ |
---|
| 1257 | map* _cursor=cursor->content; |
---|
| 1258 | map* vMap; |
---|
| 1259 | while(_cursor!=NULL){ |
---|
| 1260 | if((vMap=getMap(correspondance,_cursor->name))!=NULL){ |
---|
| 1261 | if (msInsertHashTable(&(myMap->web.metadata), vMap->value, _cursor->value) == NULL){ |
---|
| 1262 | #ifdef DEBUGMS |
---|
| 1263 | fprintf(stderr,"Unable to add metadata"); |
---|
| 1264 | #endif |
---|
| 1265 | return; |
---|
| 1266 | } |
---|
| 1267 | } |
---|
| 1268 | _cursor=_cursor->next; |
---|
| 1269 | } |
---|
| 1270 | cursor=cursor->next; |
---|
| 1271 | } |
---|
[492] | 1272 | freeMap(&correspondance); |
---|
| 1273 | free(correspondance); |
---|
[297] | 1274 | |
---|
[364] | 1275 | /* |
---|
| 1276 | * Set mapserver PROJ_LIB/GDAL_DATA or any other config parameter from |
---|
| 1277 | * the main.cfg [mapserver] section if any |
---|
| 1278 | */ |
---|
| 1279 | maps *tmp3=getMaps(conf,"mapserver"); |
---|
| 1280 | if(tmp3!=NULL){ |
---|
| 1281 | map* tmp4=tmp3->content; |
---|
| 1282 | while(tmp4!=NULL){ |
---|
| 1283 | msSetConfigOption(myMap,tmp4->name,tmp4->value); |
---|
| 1284 | tmp4=tmp4->next; |
---|
| 1285 | } |
---|
| 1286 | } |
---|
| 1287 | |
---|
[297] | 1288 | /** |
---|
| 1289 | * Set a ows_rootlayer_title, |
---|
| 1290 | */ |
---|
| 1291 | if (msInsertHashTable(&(myMap->web.metadata), "ows_rootlayer_name", "ZOO_Project_Layer") == NULL){ |
---|
| 1292 | #ifdef DEBUGMS |
---|
| 1293 | fprintf(stderr,"Unable to add metadata"); |
---|
| 1294 | #endif |
---|
| 1295 | return; |
---|
| 1296 | } |
---|
| 1297 | if (msInsertHashTable(&(myMap->web.metadata), "ows_rootlayer_title", "ZOO_Project_Layer") == NULL){ |
---|
| 1298 | #ifdef DEBUGMS |
---|
| 1299 | fprintf(stderr,"Unable to add metadata"); |
---|
| 1300 | #endif |
---|
| 1301 | return; |
---|
| 1302 | } |
---|
| 1303 | |
---|
| 1304 | /** |
---|
| 1305 | * Enable all the WXS requests using ows_enable_request |
---|
| 1306 | * see http://mapserver.org/trunk/development/rfc/ms-rfc-67.html |
---|
| 1307 | */ |
---|
| 1308 | if (msInsertHashTable(&(myMap->web.metadata), "ows_enable_request", "*") == NULL){ |
---|
| 1309 | #ifdef DEBUGMS |
---|
| 1310 | fprintf(stderr,"Unable to add metadata"); |
---|
| 1311 | #endif |
---|
| 1312 | return; |
---|
| 1313 | } |
---|
| 1314 | msInsertHashTable(&(myMap->web.metadata), "ows_srs", "EPSG:4326"); |
---|
| 1315 | |
---|
| 1316 | if(tryOgr(conf,outputs,myMap)<0) |
---|
| 1317 | if(tryGdal(conf,outputs,myMap)<0) |
---|
[364] | 1318 | return ; |
---|
[297] | 1319 | |
---|
| 1320 | tmp1=getMapFromMaps(conf,"main","dataPath"); |
---|
| 1321 | char *tmpPath=(char*)malloc((13+strlen(tmp1->value))*sizeof(char)); |
---|
| 1322 | sprintf(tmpPath,"%s/symbols.sym",tmp1->value); |
---|
| 1323 | msInitSymbolSet(&myMap->symbolset); |
---|
[453] | 1324 | myMap->symbolset.filename=zStrdup(tmpPath); |
---|
[297] | 1325 | free(tmpPath); |
---|
| 1326 | |
---|
[453] | 1327 | map* sid=getMapFromMaps(conf,"lenv","usid"); |
---|
[297] | 1328 | char *mapPath= |
---|
[458] | 1329 | (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char)); |
---|
[297] | 1330 | sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value); |
---|
| 1331 | msSaveMap(myMap,mapPath); |
---|
[492] | 1332 | free(mapPath); |
---|
[854] | 1333 | //msFreeSymbolSet(&myMap->symbolset); |
---|
| 1334 | msFreeMap(myMap); |
---|
| 1335 | //msFree(myMap); |
---|
[492] | 1336 | msGDALCleanup(); |
---|
[297] | 1337 | } |
---|
| 1338 | |
---|