source: trunk/zoo-project/zoo-kernel/service_internal_ms.c @ 873

Last change on this file since 873 was 781, checked in by djay, 8 years ago

Fix issue #140

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 36.8 KB
RevLine 
[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 */
49map* 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]88void 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]132void 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  }
[297]140  map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion");
141  map *dataPath=getMapFromMaps(m,"main","dataPath");
[453]142  map *sid=getMapFromMaps(m,"lenv","usid");
[297]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]={
150    {"WMS","1.3.0","GetMap","layers=%s","wms_extent"},
[434]151    {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"},
[297]152    {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}
153  };
154  int proto=0;
155  if(rformat==NULL){
156    rformat=getMap(tmpI->content,"mimeType");
157  }
158  if(strncasecmp(rformat->value,"text/xml",8)==0)
159    proto=1;
160  if(strncasecmp(rformat->value,"image/tiff",10)==0)
161    proto=2;
[490]162  if(protoMap!=NULL){
[297]163    if(strncasecmp(protoMap->value,"WMS",3)==0)
164      proto=0;
[490]165    else{
166      if(strncasecmp(protoMap->value,"WFS",3)==0)
167        proto=1;
168      else 
169        proto=2;
170    }
171  }
[297]172  char *protoVersion=options[proto][1];
173  if(proto==1){
174    if(msOgcVersion!=NULL)
175      protoVersion=msOgcVersion->value;
176    if(versionMap!=NULL)
177      protoVersion=versionMap->value;
178  }
179
180  map* extent=getMap(tmpI->content,options[proto][4]);
181  map* crs=getMap(tmpI->content,"crs");
[402]182  int hasCRS=1;
183  if(crs==NULL){
184    crs=getMapFromMaps(m,"main","crs");
185    if(crs==NULL){
186      crs=createMap("crs","epsg:4326");
187      hasCRS=0;
188    }
189  }
[297]190  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));
194
[357]195  if(proto>0){
[297]196    sprintf(webService_url,
197            "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
198            msUrl->value,
199            dataPath->value,
200            tmpI->name,
201            sid->value,
202            options[proto][2],
203            options[proto][0],
204            protoVersion,
205            layers,
206            rformat->value,
207            extent->value,
208            crs->value
209            );
[357]210  }
211  else{
[297]212    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",
214            msUrl->value,
215            dataPath->value,
216            tmpI->name,
217            sid->value,
218            options[proto][2],
219            options[proto][0],
220            protoVersion,
221            layers,
222            width->value,
223            height->value,
224            rformat->value,
225            extent->value,
226            crs->value
227            );
[357]228  }
[402]229  if(hasCRS==0){
230    freeMap(&crs);
231    free(crs);
232  }
[297]233  addToMap(tmpI->content,"Reference",webService_url);
[492]234  free(webService_url);
[297]235}
236
237/**
[586]238 * Set projection for a layer in a MAPFILE using Authority Code and Name if
239 * available or fallback to proj4 definition if available or fallback to
240 * default EPSG:4326
241 *
242 * @param output the output maps
243 * @param m the opened mapObj
244 * @param myLayer the layerObj
245 * @param pszProjection a char* containing the SRS definition in WKT format
[297]246 */
247void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer,
248                        char* pszProjection){
249  OGRSpatialReferenceH  hSRS;
250  map* msSrs=NULL;
251  hSRS = OSRNewSpatialReference(NULL);
[451]252  if( pszProjection!=NULL && strlen(pszProjection)>1){
253    if(OSRImportFromWkt( hSRS, &pszProjection ) == CE_None ){
254      char *proj4Str=NULL;
255      if(OSRGetAuthorityName(hSRS,NULL)!=NULL && 
256         OSRGetAuthorityCode(hSRS,NULL)!=NULL){
257        char tmpSrs[20];
258        sprintf(tmpSrs,"%s:%s",
259                OSRGetAuthorityName(hSRS,NULL),OSRGetAuthorityCode(hSRS,NULL));
260        msLoadProjectionStringEPSG(&m->projection,tmpSrs);
261        msLoadProjectionStringEPSG(&myLayer->projection,tmpSrs);
262       
263        char tmpSrss[256];
[776]264        sprintf(tmpSrss,"EPSG:4326 EPSG:900913 EPSG:3857 %s",tmpSrs);
[451]265       
266        msInsertHashTable(&(m->web.metadata), "ows_srs", tmpSrss);
267        msInsertHashTable(&(myLayer->metadata), "ows_srs", tmpSrss);
268       
[297]269#ifdef DEBUGMS
[451]270        fprintf(stderr,"isGeo %b\n\n",OSRIsGeographic(hSRS)==TRUE);
[297]271#endif
[451]272        if(output!=NULL){
[297]273          if(OSRIsGeographic(hSRS)==TRUE)
274            addToMap(output->content,"crs_isGeographic","true");
275          else
276            addToMap(output->content,"crs_isGeographic","false");
[451]277          addToMap(output->content,"crs",tmpSrs);
[297]278        }
279      }
280      else{
[451]281        OSRExportToProj4(hSRS,&proj4Str);
[475]282        if(proj4Str!=NULL && strlen(proj4Str)>0){
[451]283#ifdef DEBUGMS
284          fprintf(stderr,"PROJ (%s)\n",proj4Str);
285#endif
286          msLoadProjectionString(&(m->projection),proj4Str);
287          msLoadProjectionString(&(myLayer->projection),proj4Str);
288          if(output!=NULL){ 
289            if(OSRIsGeographic(hSRS)==TRUE)
290              addToMap(output->content,"crs_isGeographic","true");
291            else
292              addToMap(output->content,"crs_isGeographic","false");
293          }
[492]294          free(proj4Str);
[451]295        }
296        else{
297          msLoadProjectionStringEPSG(&m->projection,"EPSG:4326");
298          msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326");
299          if(output!=NULL){
300            addToMap(output->content,"crs_isGeographic","true");
301          }
302        }
[297]303        if(output!=NULL){
[451]304          addToMap(output->content,"crs","EPSG:4326");
305          addToMap(output->content,"real_extent","true");
[297]306        }
[776]307        msInsertHashTable(&(m->web.metadata),"ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
308        msInsertHashTable(&(myLayer->metadata),"ows_srs","EPSG:4326 EPSG:900913 EPSG:3857");
[297]309      }
310    }
311  }
312  else{
313    if(output!=NULL){
314      msSrs=getMap(output->content,"msSrs");
315    }
316    if(msSrs!=NULL){
317      msLoadProjectionStringEPSG(&m->projection,msSrs->value);
[330]318      msLoadProjectionStringEPSG(&myLayer->projection,msSrs->value);
[297]319      char tmpSrs[128];
[776]320      sprintf(tmpSrs,"%s EPSG:4326 EPSG:900913 EPSG:3857",msSrs->value);
[297]321      msInsertHashTable(&(m->web.metadata),"ows_srs",tmpSrs);
322      msInsertHashTable(&(myLayer->metadata),"ows_srs",tmpSrs);
323    }else{
324      msLoadProjectionStringEPSG(&m->projection,"EPSG:4326");
[330]325      msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326");
[776]326      msInsertHashTable(&(m->web.metadata),"ows_srs","EPSG:4326 EPSG:900913 EPSG:3857");
327      msInsertHashTable(&(myLayer->metadata),"ows_srs","EPSG:4326 EPSG:900913 EPSG:3857");
[297]328    }
[362]329    if(output!=NULL){
330      addToMap(output->content,"crs",msSrs->value);
331      addToMap(output->content,"crs_isGeographic","true");
332    }
[297]333  }
334
335  OSRDestroySpatialReference( hSRS );
336}
337
[586]338/**
339 * Set the MAPFILE extent, the the ows_extent for the layer, add wms_extent and
340 * wfs_extent to the output maps and call setMapSize.
341 *
342 * @param output the specific output
343 * @param m the mapObj
344 * @param myLayer the layerObj
345 * @param minX the lower left x coordinate
346 * @param minY the lower left y coordinate
347 * @param maxX the upper right x coordinate
348 * @param maxY the upper right y coordinate
349 * @see setMapSize
350 */
[297]351void setMsExtent(maps* output,mapObj* m,layerObj* myLayer,
352                 double minX,double minY,double maxX,double maxY){
353  msMapSetExtent(m,minX,minY,maxX,maxY);
354#ifdef DEBUGMS
355  fprintf(stderr,"Extent %.15f %.15f %.15f %.15f\n",minX,minY,maxX,maxY);
356#endif
357  char tmpExtent[1024];
358  sprintf(tmpExtent,"%.15f %.15f %.15f %.15f",minX,minY,maxX,maxY);
359#ifdef DEBUGMS
360  fprintf(stderr,"Extent %s\n",tmpExtent);
361#endif
362  msInsertHashTable(&(myLayer->metadata), "ows_extent", tmpExtent);
363 
364  if(output!=NULL){
[357]365    map* test=getMap(output->content,"real_extent");
366    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");
[360]376
[357]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);
[360]381      map* isGeo=getMap(output->content,"crs_isGeographic");
[434]382#ifdef DEBUGMS
[360]383      fprintf(stderr,"isGeo = %s\n",isGeo->value);
[434]384#endif
[360]385      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0)
386        sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
[357]387      addToMap(output->content,"wms_extent",tmpExtent);
[360]388      sprintf(tmpSrsStr,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
[357]389      addToMap(output->content,"wcs_extent",tmpExtent);
390    }else{
391      sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY);
392      map* isGeo=getMap(output->content,"crs_isGeographic");
[402]393      if(isGeo!=NULL){
[434]394#ifdef DEBUGMS
[402]395        fprintf(stderr,"isGeo = %s\n",isGeo->value);
[434]396#endif
[402]397        if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0)
398          sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
399      }
[357]400      addToMap(output->content,"wms_extent",tmpExtent); 
401      sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",minX,minY,maxX,maxY);
[360]402      addToMap(output->content,"wcs_extent",tmpExtent);
[357]403    }
[297]404  }
405
406  setMapSize(output,minX,minY,maxX,maxY);
407}
408
[586]409/**
410 * Try to open a vector output and define the corresponding layer in the MAPFILE
411 *
412 * @param conf the conf maps containing the main.cfg settings
413 * @param output the specific output maps
414 * @param m the mapObj
415 */
[297]416int tryOgr(maps* conf,maps* output,mapObj* m){
417
418  map* tmpMap=getMap(output->content,"storage");
419  char *pszDataSource=tmpMap->value;
420
421  /**
422   * Try to open the DataSource using OGR
423   */
424  OGRRegisterAll();
425  /**
426   * Try to load the file as ZIP
427   */
428
[364]429  OGRDataSourceH poDS1 = NULL;
[297]430  OGRSFDriverH *poDriver1 = NULL;
431  char *dsName=(char*)malloc((8+strlen(pszDataSource)+1)*sizeof(char));
[453]432  char *odsName=zStrdup(pszDataSource);
433  char *sdsName=zStrdup(pszDataSource);
[623]434  char *demo=".data";
[297]435  sdsName[strlen(sdsName)-(strlen(demo)-1)]='d';
436  sdsName[strlen(sdsName)-(strlen(demo)-2)]='i';
437  sdsName[strlen(sdsName)-(strlen(demo)-3)]='r';
438  sdsName[strlen(sdsName)-(strlen(demo)-4)]=0;
439
440  odsName[strlen(odsName)-(strlen(demo)-1)]='z';
441  odsName[strlen(odsName)-(strlen(demo)-2)]='i';
442  odsName[strlen(odsName)-(strlen(demo)-3)]='p';
443  odsName[strlen(odsName)-(strlen(demo)-4)]=0;
444  sprintf(dsName,"/vsizip/%s",odsName);
445
446#ifdef DEBUGMS
447  fprintf(stderr,"Try loading %s, %s, %s\n",dsName,odsName,dsName);
448#endif
449
450  FILE* file = fopen(pszDataSource, "rb");
451  FILE* fileZ = fopen(odsName, "wb");
[492]452  free(odsName);
[297]453  fseek(file, 0, SEEK_END);
454  unsigned long fileLen=ftell(file);
455  fseek(file, 0, SEEK_SET);
456  char *buffer=(char *)malloc(fileLen+1);
457  fread(buffer, fileLen, 1, file);
458  fwrite(buffer,fileLen, 1, fileZ);
459  fclose(file);
460  fclose(fileZ);
461  free(buffer);
[434]462#ifdef DEBUGMS
[297]463  fprintf(stderr,"Try loading %s",dsName);
[434]464#endif
[297]465  poDS1 = OGROpen( dsName, FALSE, poDriver1 );
466  if( poDS1 == NULL ){
467    fprintf(stderr,"Unable to access the DataSource as ZIP File\n");
468    setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
469    OGR_DS_Destroy(poDS1);
470  }else{
[434]471#ifdef DEBUGMS
[297]472    fprintf(stderr,"The DataSource is a  ZIP File\n");
[434]473#endif
[297]474    char** demo=VSIReadDir(dsName);
475    int i=0;
[453]476    zMkdir(sdsName
[364]477#ifndef WIN32
478                ,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
479#endif
480                );
[297]481    while(demo[i]!=NULL){
[434]482#ifdef DEBUGMS
[297]483      fprintf(stderr,"ZIP File content : %s\n",demo[i]);
[434]484#endif
[297]485      char *tmpDs=(char*)malloc((strlen(dsName)+strlen(demo[i])+2)*sizeof(char));
486      sprintf(tmpDs,"%s/%s",dsName,demo[i]);
487      fprintf(stderr,"read : %s\n",tmpDs);
488     
489      VSILFILE* vsif=VSIFOpenL(tmpDs,"rb");
[434]490#ifdef DEBUGMS
[297]491      fprintf(stderr,"open : %s\n",tmpDs);
[434]492#endif
[297]493      VSIFSeekL(vsif,0,SEEK_END);
[453]494      vsi_l_offset size=VSIFTellL(vsif);
[434]495#ifdef DEBUGMS
[297]496      fprintf(stderr,"size : %d\n",size);
[434]497#endif
[297]498      VSIFSeekL(vsif,0,SEEK_SET);
[453]499      char *vsifcontent=(char*) malloc(((int)size+1)*sizeof(char));
500      VSIFReadL(vsifcontent,1,(size_t)size,vsif);
[297]501      char *fpath=(char*) malloc((strlen(sdsName)+strlen(demo[1])+2)*sizeof(char));
502      sprintf(fpath,"%s/%s",sdsName,demo[i]);
[453]503      int f=zOpen(fpath,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
504      zWrite(f,vsifcontent,(int)size);
[297]505      close(f);
506      chmod(fpath,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH);
507      char* tmpP=strstr(fpath,".shp");
508      if(tmpP==NULL)
509        tmpP=strstr(fpath,".SHP");
510      if(tmpP!=NULL){
[434]511#ifdef DEBUGMS
[297]512        fprintf(stderr,"*** DEBUG %s\n",strstr(tmpP,"."));
[434]513#endif
[297]514        if( strcmp(tmpP,".shp")==0 || strcmp(tmpP,".SHP")==0 ){
515          tmpMap=getMap(output->content,"storage");
516          free(tmpMap->value);
517          tmpMap->value=(char*) malloc((strlen(fpath)+1)*sizeof(char));
518          sprintf(tmpMap->value,"%s",fpath);
519          pszDataSource=tmpMap->value;
[434]520#ifdef DEBUGMS
[297]521          fprintf(stderr,"*** DEBUG %s\n",pszDataSource);
[434]522#endif
[297]523        }
524      }
525      VSIFCloseL(vsif);
526      i++;
527    }
528  }
[492]529  free(sdsName);
530  free(dsName);
[297]531
[364]532  OGRDataSourceH poDS = NULL;
[297]533  OGRSFDriverH *poDriver = NULL;
534  poDS = OGROpen( pszDataSource, FALSE, poDriver );
535  if( poDS == NULL ){
536#ifdef DEBUGMS
537    fprintf(stderr,"Unable to access the DataSource %s\n",pszDataSource);
538#endif
539    setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
540    OGR_DS_Destroy(poDS);
541    OGRCleanupAll();
542#ifdef DEBUGMS
543    fprintf(stderr,"Unable to access the DataSource, exit! \n"); 
544#endif
545    return -1;
546  }
547
548  int iLayer = 0;
549  for( iLayer=0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++ ){
[364]550    OGRLayerH poLayer = OGR_DS_GetLayer(poDS,iLayer);
[297]551
552    if( poLayer == NULL ){
553#ifdef DEBUGMS
554      fprintf(stderr,"Unable to access the DataSource Layer \n");
555#endif
556      setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
557      return -1;
558    }
559
560    /**
561     * Add a new layer set name, data
562     */
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];
[434]571#ifdef DEBUGMS
[297]572    dumpMaps(output);
[434]573#endif
[453]574    myLayer->name = zStrdup(output->name);
[297]575    myLayer->tileitem=NULL;
[453]576    myLayer->data = zStrdup(OGR_L_GetName(poLayer));
577    myLayer->connection = zStrdup(pszDataSource);
[297]578    myLayer->index = m->numlayers;
579    myLayer->dump = MS_TRUE;
580    myLayer->status = MS_ON;
581    msConnectLayer(myLayer,MS_OGR,pszDataSource);
582
583    /**
584     * Detect the Geometry Type or use Polygon
585     */
586    if(OGR_L_GetGeomType(poLayer) != wkbUnknown){
587      switch(OGR_L_GetGeomType(poLayer)){
588      case wkbPoint:
589      case wkbMultiPoint:
590      case wkbPoint25D:
591      case wkbMultiPoint25D:
592#ifdef DEBUGMS
593        fprintf(stderr,"POINT DataSource Layer \n");
594#endif
595        myLayer->type = MS_LAYER_POINT;
596        break;
597      case wkbLineString :
598      case wkbMultiLineString :
599      case wkbLineString25D:
600      case wkbMultiLineString25D:
601#ifdef DEBUGMS
602        fprintf(stderr,"LINE DataSource Layer \n");
603#endif
604        myLayer->type = MS_LAYER_LINE;
605        break;
606      case wkbPolygon:
607      case wkbMultiPolygon:
608      case wkbPolygon25D:
609      case wkbMultiPolygon25D:
610#ifdef DEBUGMS
611        fprintf(stderr,"POLYGON DataSource Layer \n");
612#endif
613        myLayer->type = MS_LAYER_POLYGON;
614        break;
615      default:
616        myLayer->type = MS_LAYER_POLYGON;
617        break;
618      }
619    }else
620      myLayer->type = MS_LAYER_POLYGON;
621
622    /**
623     * Detect spatial reference or use WGS84
624     */
625    OGRSpatialReferenceH srs=OGR_L_GetSpatialRef(poLayer);
626    if(srs!=NULL){
627      char *wkt=NULL;
628      OSRExportToWkt(srs,&wkt);
629      setSrsInformations(output,m,myLayer,wkt);
[492]630      free(wkt);
[297]631    }
632    else{
633      addToMap(output->content,"crs","EPSG:4326");
634      addToMap(output->content,"crs_isGeographic","true");
635      msLoadProjectionStringEPSG(&m->projection,"EPSG:4326");
[776]636      msInsertHashTable(&(m->web.metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
637      msInsertHashTable(&(myLayer->metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
[297]638    }
639
640    OGREnvelope oExt;
641    if (OGR_L_GetExtent(poLayer,&oExt, TRUE) == OGRERR_NONE){
642      setMsExtent(output,m,myLayer,oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
643    }
644 
645    /**
646     * Detect the FID column or use the first attribute field as FID
647     */
[364]648    char *fid=(char*)OGR_L_GetFIDColumn(poLayer);
[297]649    if(strlen(fid)==0){
650      OGRFeatureDefnH def=OGR_L_GetLayerDefn(poLayer);
651      int fIndex=0;
652      for(fIndex=0;fIndex<OGR_FD_GetFieldCount(def);fIndex++){
653        OGRFieldDefnH fdef=OGR_FD_GetFieldDefn(def,fIndex);
[364]654        fid=(char*)OGR_Fld_GetNameRef(fdef);
[297]655        break;
656      }
657    }
658    msInsertHashTable(&(myLayer->metadata), "gml_featureid", fid);
659    msInsertHashTable(&(myLayer->metadata), "gml_include_items", "all");
660    msInsertHashTable(&(myLayer->metadata), "ows_name", output->name);
661    map* tmpMap=getMap(output->content,"title");
662    if(tmpMap!=NULL)
663      msInsertHashTable(&(myLayer->metadata), "ows_title", tmpMap->value);
664    else
665      msInsertHashTable(&(myLayer->metadata), "ows_title", "Default Title");
[379]666   
[297]667    if(msGrowLayerClasses(myLayer) == NULL)
[364]668      return -1;
[370]669    if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
[364]670      return -1;
[370]671    if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
[364]672      return -1;
[370]673    if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
[364]674      return -1;
[297]675    /**
676     * Apply msStyle else fallback to the default style
677     */
678    tmpMap=getMap(output->content,"msStyle");
679    if(tmpMap!=NULL)
[370]680      msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
[297]681    else{
682      /**
683       * Set style
684       */
[370]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;
[379]691     
[297]692      /**
693       * Set specific style depending on type
694       */
695      if(myLayer->type == MS_LAYER_POLYGON)
[370]696        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
[297]697      if(myLayer->type == MS_LAYER_LINE){
[370]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;
[297]700      }
701      if(myLayer->type == MS_LAYER_POINT){
[370]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;
[297]704      }
[379]705     
[297]706    }
[370]707    myLayer->CLASS[myLayer->numclasses]->numstyles++;
[297]708    myLayer->numclasses++;
[379]709   
[297]710    m->layerorder[m->numlayers] = m->numlayers;
711    m->numlayers++;
712
713  }
714
715  OGR_DS_Destroy(poDS);
716  OGRCleanupAll();
717
718  return 1;
719}
720
[586]721/**
722 * Try to open a raster output and define the corresponding layer in the MAPFILE
723 *
724 * @param conf the conf maps containing the main.cfg settings
725 * @param output the specific output maps
726 * @param m the mapObj
727 */
[297]728int tryGdal(maps* conf,maps* output,mapObj* m){
729  map* tmpMap=getMap(output->content,"storage");
730  char *pszFilename=tmpMap->value;
731  GDALDatasetH hDataset;
732  GDALRasterBandH hBand;
733  double adfGeoTransform[6];
734  int i, iBand;
735 
736  /**
737   * Try to open the DataSource using GDAL
738   */
739  GDALAllRegister();
740  hDataset = GDALOpen( pszFilename, GA_ReadOnly );
741  if( hDataset == NULL ){
742#ifdef DEBUGMS
[366]743    fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename);
[297]744#endif
745    setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open");
746    GDALDestroyDriverManager();
747    return -1;
748  }
749#ifdef DEBUGMS
[451]750  fprintf(stderr,"Accessing the DataSource %s %d\n",pszFilename,__LINE__);
[297]751#endif
752
753  /**
754   * Add a new layer set name, data
755   */
756  if(msGrowMapLayers(m)==NULL){
757    return -1;
758  }
759  if(initLayer((m->layers[m->numlayers]), m) == -1){
760    return -1;
761  }
[451]762  m->layers[m->numlayers]->index=m->numlayers;
[297]763
764  layerObj* myLayer=m->layers[m->numlayers];
[453]765  myLayer->name = zStrdup(output->name);
[297]766  myLayer->tileitem=NULL;
[453]767  myLayer->data = zStrdup(pszFilename);
[297]768  myLayer->index = m->numlayers;
769  myLayer->dump = MS_TRUE;
770  myLayer->status = MS_ON;
771  myLayer->type = MS_LAYER_RASTER;
772
773  char *title=output->name;
774  tmpMap=getMap(output->content,"title");
775  if(tmpMap!=NULL)
776    title=tmpMap->value;
777  char *abstract=output->name;
778  tmpMap=getMap(output->content,"abstract");
779  if(tmpMap!=NULL)
780    abstract=tmpMap->value;
[451]781
[297]782  msInsertHashTable(&(myLayer->metadata), "ows_label", title);
783  msInsertHashTable(&(myLayer->metadata), "ows_title", title);
784  msInsertHashTable(&(myLayer->metadata), "ows_abstract", abstract);
785  msInsertHashTable(&(myLayer->metadata), "ows_rangeset_name", output->name);
786  msInsertHashTable(&(myLayer->metadata), "ows_rangeset_label", title);
787
788  /**
789   * Set Map Size to the raster size
790   */
791  m->width=GDALGetRasterXSize( hDataset );
792  m->height=GDALGetRasterYSize( hDataset );
793 
794  /**
795   * Set projection using Authority Code and Name if available or fallback to
796   * proj4 definition if available or fallback to default EPSG:4326
797   */
[366]798  const char *tRef=GDALGetProjectionRef( hDataset );
799  if( tRef != NULL && strlen(tRef)>0 ){
[297]800    char *pszProjection;
801    pszProjection = (char *) GDALGetProjectionRef( hDataset );
[607]802#ifdef DEBUGMS
[297]803    fprintf(stderr,"Accessing the DataSource %s\n",GDALGetProjectionRef( hDataset ));
[607]804#endif
[297]805    setSrsInformations(output,m,myLayer,pszProjection);
[453]806  }else{
807    fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset ));   
808  }
[297]809
810
811  /**
812   * Set extent
813   */
814  if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None ){
815    if( adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0 ){
816
817      double minX = adfGeoTransform[0]
818        + adfGeoTransform[2] * GDALGetRasterYSize(hDataset);
819      double minY = adfGeoTransform[3]
820        + adfGeoTransform[5] * GDALGetRasterYSize(hDataset);
821
822      double maxX = adfGeoTransform[0]
823        + adfGeoTransform[1] * GDALGetRasterXSize(hDataset);
824      double maxY = adfGeoTransform[3]
825        + adfGeoTransform[4] * GDALGetRasterXSize(hDataset);
826
827       setMsExtent(output,m,myLayer,minX,minY,maxX,maxY);
828
829    }
830  }
831
832  /**
833   * Extract information about available bands to set the bandcount and the
834   * processing directive
835   */
[781]836  char nBands[3];
[297]837  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");
846
847  /**
848   * Name available Bands
849   */
[781]850  char lBands[7];
[297]851  char *nameBands=NULL;
852  for( iBand = 0; iBand < nBandsI; iBand++ ){
853    sprintf(lBands,"Band%d",iBand+1);
854    if(nameBands==NULL){
855      nameBands=(char*)malloc((strlen(lBands)+1)*sizeof(char));
856      sprintf(nameBands,"%s",lBands);
857    }else{
858      if(iBand<4){
[453]859        char *tmpS=zStrdup(nameBands);
[297]860        nameBands=(char*)realloc(nameBands,(strlen(nameBands)+strlen(lBands)+1)*sizeof(char));
861        sprintf(nameBands,"%s %s",tmpS,lBands);
862        free(tmpS);
863      }
864    }
865  }
866  msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands);
867 
868  /**
[781]869   * Loops over metadata information to setup specific information
[297]870   */
871  for( iBand = 0; iBand < nBandsI; iBand++ ){
[453]872    //int         bGotNodata;//, bSuccess;
873    double      adfCMinMax[2]/*, dfNoData*/;
874    //int         nBlockXSize, nBlockYSize, nMaskFlags;
875    //double      /*dfMean, dfStdDev*/;
[297]876    hBand = GDALGetRasterBand( hDataset, iBand+1 );
877
878    CPLErrorReset();
879    GDALComputeRasterMinMax( hBand, FALSE, adfCMinMax );
880    char tmpN[21];
881    sprintf(tmpN,"Band%d",iBand+1);
882    if (CPLGetLastErrorType() == CE_None){
883      char tmpMm[100];
884      sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
885      char tmpI[21];
886      sprintf(tmpI,"%s_interval",tmpN);
887      msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm);
888
[300]889      map* test=getMap(output->content,"msClassify");
890      if(test!=NULL && strncasecmp(test->value,"true",4)==0){
891        /**
892         * Classify one band raster pixel value using regular interval
893         */
894        int _tmpColors[10][3]={
895          {102,153,204},
896          {51,102,153},
897          {102,102,204},
898          {51,204,0},
899          {153,255,102},
900          {204,255,102},
901          {102,204,153},
902          {255,69,64},
903          {255,192,115},
904          {255,201,115}
905        };
906         
907        if(nBandsI==1){
908          double delta=adfCMinMax[1]-adfCMinMax[0];
909          double interval=delta/10;
910          double cstep=adfCMinMax[0];
911          for(i=0;i<10;i++){
912            /**
913             * Create a new class
914             */
915            if(msGrowLayerClasses(myLayer) == NULL)
[364]916              return -1;
[370]917            if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
[364]918              return -1;
[370]919            if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
[364]920              return -1;
[370]921            if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
[364]922              return -1;
[300]923           
924            /**
925             * Set class name
926             */
927            char className[7];
928            sprintf(className,"class%d",i);
[453]929            myLayer->CLASS[myLayer->numclasses]->name=zStrdup(className);
[300]930           
931            /**
932             * Set expression
933             */
934            char expression[1024];
935            if(i+1<10)
936              sprintf(expression,"([pixel]>=%.3f AND [pixel]<%.3f)",cstep,cstep+interval);
937            else
938              sprintf(expression,"([pixel]>=%.3f AND [pixel]<=%.3f)",cstep,cstep+interval);
[370]939            msLoadExpressionString(&myLayer->CLASS[myLayer->numclasses]->expression,expression);
[300]940           
941            /**
942             * Set color
943             */
[370]944            myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=_tmpColors[i][0];
945            myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=_tmpColors[i][1];
946            myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=_tmpColors[i][2];
[300]947            cstep+=interval;
[370]948            myLayer->CLASS[myLayer->numclasses]->numstyles++;
[300]949            myLayer->numclasses++;
950           
951          }
952         
953          char tmpMm[100];
954          sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
955         
[297]956        }
957      }
[752]958      else{
959        if(nBandsI==1){
960          myLayer->offsite.red=0;
961          myLayer->offsite.green=0;
962          myLayer->offsite.blue=0;
963        }
964        msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");
965      }
[297]966    }
967    if( strlen(GDALGetRasterUnitType(hBand)) > 0 ){
968      char tmpU[21];
969      sprintf(tmpU,"%s_band_uom",tmpN);
970      msInsertHashTable(&(myLayer->metadata), tmpU, GDALGetRasterUnitType(hBand));
971    }
972
973  }
974
975  m->layerorder[m->numlayers] = m->numlayers;
976  m->numlayers++;
977  GDALClose( hDataset );
978  GDALDestroyDriverManager();
979  CPLCleanupTLS();
980  return 1;
981}
982
983/**
984 * Create a MapFile for WMS, WFS or WCS Service output
[586]985 *
986 * @param conf the conf maps containing the main.cfg settings
987 * @param outputs a specific output maps
[297]988 */
989void outputMapfile(maps* conf,maps* outputs){
990
991  /**
[586]992   * First store the value on disk
[297]993   */
[360]994  map* mime=getMap(outputs->content,"mimeType");
995  char *ext="data";
996  if(mime!=NULL)
997    if(strncasecmp(mime->value,"application/json",16)==0)
998      ext="json";
[458]999
[297]1000  map* tmpMap=getMapFromMaps(conf,"main","dataPath");
[453]1001  map* sidMap=getMapFromMaps(conf,"lenv","usid");
[297]1002  char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
[458]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);
[550]1005  map *gfile=getMap(outputs->content,"generated_file");
1006  if(gfile!=NULL){
1007    readGeneratedFile(conf,outputs->content,gfile->value);         
1008  }
[297]1009  map* sizeMap=getMap(outputs->content,"size");
1010  map* vData=getMap(outputs->content,"value");
1011  if(sizeMap!=NULL){
[458]1012    zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
[297]1013  }
1014  else{
[458]1015    zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char));
[297]1016  }
1017  close(f);
1018  addToMap(outputs->content,"storage",pszDataSource);
[492]1019  free(pszDataSource);
[297]1020
1021  /*
1022   * Create an empty map, set name, default size and extent
1023   */
1024  mapObj *myMap=msNewMapObj();
1025  free(myMap->name);
[453]1026  myMap->name=zStrdup("ZOO-Project_WXS_Server");
[297]1027  msMapSetSize(myMap,2048,2048);
1028  msMapSetExtent(myMap,-1,-1,1,1);
1029 
1030  /*
1031   * Set imagepath and imageurl using tmpPath and tmpUrl from main.cfg
1032   */
1033  map *tmp1=getMapFromMaps(conf,"main","tmpPath");
[453]1034  myMap->web.imagepath=zStrdup(tmp1->value);
[297]1035  tmp1=getMapFromMaps(conf,"main","tmpUrl");
[453]1036  myMap->web.imageurl=zStrdup(tmp1->value);
[297]1037 
1038  /*
1039   * Define supported output formats
1040   */
1041  outputFormatObj *o1=msCreateDefaultOutputFormat(NULL,"AGG/PNG","png");
1042  o1->imagemode=MS_IMAGEMODE_RGBA;
1043  o1->transparent=MS_TRUE;
1044  o1->inmapfile=MS_TRUE;
1045  msAppendOutputFormat(myMap,msCloneOutputFormat(o1));
1046  msFreeOutputFormat(o1);
1047
1048#ifdef USE_KML
1049  outputFormatObj *o2=msCreateDefaultOutputFormat(NULL,"KML","kml");
1050  o2->inmapfile=MS_TRUE; 
1051  msAppendOutputFormat(myMap,msCloneOutputFormat(o2));
1052  msFreeOutputFormat(o2);
1053#endif
1054
1055  outputFormatObj *o3=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","tiff");
1056  if(!o3)
1057    fprintf(stderr,"Unable to initialize GDAL driver !\n");
1058  else{
1059    o3->imagemode=MS_IMAGEMODE_BYTE;
1060    o3->inmapfile=MS_TRUE; 
1061    msAppendOutputFormat(myMap,msCloneOutputFormat(o3));
1062    msFreeOutputFormat(o3);
1063  }
1064
1065  outputFormatObj *o4=msCreateDefaultOutputFormat(NULL,"GDAL/AAIGRID","grd");
1066  if(!o4)
1067    fprintf(stderr,"Unable to initialize GDAL driver !\n");
1068  else{
1069    o4->imagemode=MS_IMAGEMODE_INT16;
1070    o4->inmapfile=MS_TRUE; 
1071    msAppendOutputFormat(myMap,msCloneOutputFormat(o4));
1072    msFreeOutputFormat(o4);
1073  }
1074
1075#ifdef USE_CAIRO
1076  outputFormatObj *o5=msCreateDefaultOutputFormat(NULL,"CAIRO/PNG","cairopng");
1077  if(!o5)
1078    fprintf(stderr,"Unable to initialize CAIRO driver !\n");
1079  else{
1080    o5->imagemode=MS_IMAGEMODE_RGBA;
1081    o5->transparent=MS_TRUE;
1082    o5->inmapfile=MS_TRUE;
1083    msAppendOutputFormat(myMap,msCloneOutputFormat(o5));
1084    msFreeOutputFormat(o5);
1085  }
1086#endif
1087
1088  /*
1089   * Set default projection to EPSG:4326
1090   */
1091  msLoadProjectionStringEPSG(&myMap->projection,"EPSG:4326");
1092  myMap->transparent=1;
1093
1094  /**
1095   * Set metadata extracted from main.cfg file maps
1096   */
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 DEBUGMS
1106          fprintf(stderr,"Unable to add metadata");
1107#endif
1108          return;
1109        }
1110      }
1111      _cursor=_cursor->next;
1112    }
1113    cursor=cursor->next;
1114  }
[492]1115  freeMap(&correspondance);
1116  free(correspondance);
[297]1117
[364]1118  /*
1119   * Set mapserver PROJ_LIB/GDAL_DATA or any other config parameter from
1120   * the main.cfg [mapserver] section if any
1121   */
1122  maps *tmp3=getMaps(conf,"mapserver");
1123  if(tmp3!=NULL){
1124    map* tmp4=tmp3->content;
1125    while(tmp4!=NULL){
1126      msSetConfigOption(myMap,tmp4->name,tmp4->value);
1127      tmp4=tmp4->next;
1128    }
1129  }
1130
[297]1131  /**
1132   * Set a ows_rootlayer_title, 
1133   */
1134  if (msInsertHashTable(&(myMap->web.metadata), "ows_rootlayer_name", "ZOO_Project_Layer") == NULL){
1135#ifdef DEBUGMS
1136    fprintf(stderr,"Unable to add metadata");
1137#endif
1138    return;
1139  }
1140  if (msInsertHashTable(&(myMap->web.metadata), "ows_rootlayer_title", "ZOO_Project_Layer") == NULL){
1141#ifdef DEBUGMS
1142    fprintf(stderr,"Unable to add metadata");
1143#endif
1144    return;
1145  }
1146
1147  /**
1148   * Enable all the WXS requests using ows_enable_request
1149   * see http://mapserver.org/trunk/development/rfc/ms-rfc-67.html
1150   */
1151  if (msInsertHashTable(&(myMap->web.metadata), "ows_enable_request", "*") == NULL){
1152#ifdef DEBUGMS
1153    fprintf(stderr,"Unable to add metadata");
1154#endif
1155    return;
1156  }
1157  msInsertHashTable(&(myMap->web.metadata), "ows_srs", "EPSG:4326");
1158
1159  if(tryOgr(conf,outputs,myMap)<0)
1160    if(tryGdal(conf,outputs,myMap)<0)
[364]1161      return ;
[297]1162
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);
1166  msInitSymbolSet(&myMap->symbolset);
[453]1167  myMap->symbolset.filename=zStrdup(tmpPath);
[297]1168  free(tmpPath);
1169
[453]1170  map* sid=getMapFromMaps(conf,"lenv","usid");
[297]1171  char *mapPath=
[458]1172    (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
[297]1173  sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);
1174  msSaveMap(myMap,mapPath);
[492]1175  free(mapPath);
1176  msGDALCleanup();
[297]1177  msFreeMap(myMap);
1178}
1179
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png