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

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

Add the MapServer? 7.0.1 internal support. Add the ZOO-Client API reference in the official documentation. Add support for exotic openssl location.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 36.9 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];
264        sprintf(tmpSrss,"EPSG:4326 EPSG:900913 %s",tmpSrs);
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        }
[451]307        msInsertHashTable(&(m->web.metadata),"ows_srs", "EPSG:4326 EPSG:900913");
308        msInsertHashTable(&(myLayer->metadata),"ows_srs","EPSG:4326 EPSG:900913");
[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];
[490]320      sprintf(tmpSrs,"%s EPSG:4326 EPSG:900913",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");
[297]326      msInsertHashTable(&(m->web.metadata),"ows_srs","EPSG:4326 EPSG:900913");
327      msInsertHashTable(&(myLayer->metadata),"ows_srs","EPSG:4326 EPSG:900913");
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");
636      msInsertHashTable(&(m->web.metadata), "ows_srs", "EPSG:4326 EPSG:900913");
637      msInsertHashTable(&(myLayer->metadata), "ows_srs", "EPSG:4326 EPSG:900913");
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;
[753]671#if MS_VERSION_MAJOR<7
[370]672    myLayer->CLASS[myLayer->numclasses]->type = myLayer->type;
[753]673#endif
[370]674    if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
[364]675      return -1;
[370]676    if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
[364]677      return -1;
[297]678    /**
679     * Apply msStyle else fallback to the default style
680     */
681    tmpMap=getMap(output->content,"msStyle");
682    if(tmpMap!=NULL)
[370]683      msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
[297]684    else{
685      /**
686       * Set style
687       */
[370]688      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125;
689      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125;
690      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255;
691      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80;
692      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
693      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
[379]694     
[297]695      /**
696       * Set specific style depending on type
697       */
698      if(myLayer->type == MS_LAYER_POLYGON)
[370]699        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
[297]700      if(myLayer->type == MS_LAYER_LINE){
[370]701        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
702        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5;
[297]703      }
704      if(myLayer->type == MS_LAYER_POINT){
[370]705        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1;
706        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
[297]707      }
[379]708     
[297]709    }
[370]710    myLayer->CLASS[myLayer->numclasses]->numstyles++;
[297]711    myLayer->numclasses++;
[379]712   
[297]713    m->layerorder[m->numlayers] = m->numlayers;
714    m->numlayers++;
715
716  }
717
718  OGR_DS_Destroy(poDS);
719  OGRCleanupAll();
720
721  return 1;
722}
723
[586]724/**
725 * Try to open a raster output and define the corresponding layer in the MAPFILE
726 *
727 * @param conf the conf maps containing the main.cfg settings
728 * @param output the specific output maps
729 * @param m the mapObj
730 */
[297]731int tryGdal(maps* conf,maps* output,mapObj* m){
732  map* tmpMap=getMap(output->content,"storage");
733  char *pszFilename=tmpMap->value;
734  GDALDatasetH hDataset;
735  GDALRasterBandH hBand;
736  double adfGeoTransform[6];
737  int i, iBand;
738 
739  /**
740   * Try to open the DataSource using GDAL
741   */
742  GDALAllRegister();
743  hDataset = GDALOpen( pszFilename, GA_ReadOnly );
744  if( hDataset == NULL ){
745#ifdef DEBUGMS
[366]746    fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename);
[297]747#endif
748    setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open");
749    GDALDestroyDriverManager();
750    return -1;
751  }
752#ifdef DEBUGMS
[451]753  fprintf(stderr,"Accessing the DataSource %s %d\n",pszFilename,__LINE__);
[297]754#endif
755
756  /**
757   * Add a new layer set name, data
758   */
759  if(msGrowMapLayers(m)==NULL){
760    return -1;
761  }
762  if(initLayer((m->layers[m->numlayers]), m) == -1){
763    return -1;
764  }
[451]765  m->layers[m->numlayers]->index=m->numlayers;
[297]766
767  layerObj* myLayer=m->layers[m->numlayers];
[453]768  myLayer->name = zStrdup(output->name);
[297]769  myLayer->tileitem=NULL;
[453]770  myLayer->data = zStrdup(pszFilename);
[297]771  myLayer->index = m->numlayers;
772  myLayer->dump = MS_TRUE;
773  myLayer->status = MS_ON;
774  myLayer->type = MS_LAYER_RASTER;
775
776  char *title=output->name;
777  tmpMap=getMap(output->content,"title");
778  if(tmpMap!=NULL)
779    title=tmpMap->value;
780  char *abstract=output->name;
781  tmpMap=getMap(output->content,"abstract");
782  if(tmpMap!=NULL)
783    abstract=tmpMap->value;
[451]784
[297]785  msInsertHashTable(&(myLayer->metadata), "ows_label", title);
786  msInsertHashTable(&(myLayer->metadata), "ows_title", title);
787  msInsertHashTable(&(myLayer->metadata), "ows_abstract", abstract);
788  msInsertHashTable(&(myLayer->metadata), "ows_rangeset_name", output->name);
789  msInsertHashTable(&(myLayer->metadata), "ows_rangeset_label", title);
790
791  /**
792   * Set Map Size to the raster size
793   */
794  m->width=GDALGetRasterXSize( hDataset );
795  m->height=GDALGetRasterYSize( hDataset );
796 
797  /**
798   * Set projection using Authority Code and Name if available or fallback to
799   * proj4 definition if available or fallback to default EPSG:4326
800   */
[366]801  const char *tRef=GDALGetProjectionRef( hDataset );
802  if( tRef != NULL && strlen(tRef)>0 ){
[297]803    char *pszProjection;
804    pszProjection = (char *) GDALGetProjectionRef( hDataset );
[607]805#ifdef DEBUGMS
[297]806    fprintf(stderr,"Accessing the DataSource %s\n",GDALGetProjectionRef( hDataset ));
[607]807#endif
[297]808    setSrsInformations(output,m,myLayer,pszProjection);
[453]809  }else{
810    fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset ));   
811  }
[297]812
813
814  /**
815   * Set extent
816   */
817  if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None ){
818    if( adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0 ){
819
820      double minX = adfGeoTransform[0]
821        + adfGeoTransform[2] * GDALGetRasterYSize(hDataset);
822      double minY = adfGeoTransform[3]
823        + adfGeoTransform[5] * GDALGetRasterYSize(hDataset);
824
825      double maxX = adfGeoTransform[0]
826        + adfGeoTransform[1] * GDALGetRasterXSize(hDataset);
827      double maxY = adfGeoTransform[3]
828        + adfGeoTransform[4] * GDALGetRasterXSize(hDataset);
829
830       setMsExtent(output,m,myLayer,minX,minY,maxX,maxY);
831
832    }
833  }
834
835  /**
836   * Extract information about available bands to set the bandcount and the
837   * processing directive
838   */
839  char nBands[2];
840  int nBandsI=GDALGetRasterCount( hDataset );
841  sprintf(nBands,"%d",GDALGetRasterCount( hDataset ));
842  msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands);
843  if(nBandsI>=3)
844    msLayerAddProcessing(myLayer,"BANDS=1,2,3");
845  else if(nBandsI>=2)
846    msLayerAddProcessing(myLayer,"BANDS=1,2");
847  else
848    msLayerAddProcessing(myLayer,"BANDS=1");
849
850  /**
851   * Name available Bands
852   */
853  char lBands[6];
854  char *nameBands=NULL;
855  for( iBand = 0; iBand < nBandsI; iBand++ ){
856    sprintf(lBands,"Band%d",iBand+1);
857    if(nameBands==NULL){
858      nameBands=(char*)malloc((strlen(lBands)+1)*sizeof(char));
859      sprintf(nameBands,"%s",lBands);
860    }else{
861      if(iBand<4){
[453]862        char *tmpS=zStrdup(nameBands);
[297]863        nameBands=(char*)realloc(nameBands,(strlen(nameBands)+strlen(lBands)+1)*sizeof(char));
864        sprintf(nameBands,"%s %s",tmpS,lBands);
865        free(tmpS);
866      }
867    }
868  }
869  msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands);
870 
871  /**
872   * Loops over metadata informations to setup specific informations
873   */
874  for( iBand = 0; iBand < nBandsI; iBand++ ){
[453]875    //int         bGotNodata;//, bSuccess;
876    double      adfCMinMax[2]/*, dfNoData*/;
877    //int         nBlockXSize, nBlockYSize, nMaskFlags;
878    //double      /*dfMean, dfStdDev*/;
[297]879    hBand = GDALGetRasterBand( hDataset, iBand+1 );
880
881    CPLErrorReset();
882    GDALComputeRasterMinMax( hBand, FALSE, adfCMinMax );
883    char tmpN[21];
884    sprintf(tmpN,"Band%d",iBand+1);
885    if (CPLGetLastErrorType() == CE_None){
886      char tmpMm[100];
887      sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
888      char tmpI[21];
889      sprintf(tmpI,"%s_interval",tmpN);
890      msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm);
891
[300]892      map* test=getMap(output->content,"msClassify");
893      if(test!=NULL && strncasecmp(test->value,"true",4)==0){
894        /**
895         * Classify one band raster pixel value using regular interval
896         */
897        int _tmpColors[10][3]={
898          {102,153,204},
899          {51,102,153},
900          {102,102,204},
901          {51,204,0},
902          {153,255,102},
903          {204,255,102},
904          {102,204,153},
905          {255,69,64},
906          {255,192,115},
907          {255,201,115}
908        };
909         
910        if(nBandsI==1){
911          double delta=adfCMinMax[1]-adfCMinMax[0];
912          double interval=delta/10;
913          double cstep=adfCMinMax[0];
914          for(i=0;i<10;i++){
915            /**
916             * Create a new class
917             */
918            if(msGrowLayerClasses(myLayer) == NULL)
[364]919              return -1;
[370]920            if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
[364]921              return -1;
[753]922#if MS_VERSION_MAJOR<7
[370]923            myLayer->CLASS[myLayer->numclasses]->type = myLayer->type;
[753]924#endif
[370]925            if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
[364]926              return -1;
[370]927            if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
[364]928              return -1;
[300]929           
930            /**
931             * Set class name
932             */
933            char className[7];
934            sprintf(className,"class%d",i);
[453]935            myLayer->CLASS[myLayer->numclasses]->name=zStrdup(className);
[300]936           
937            /**
938             * Set expression
939             */
940            char expression[1024];
941            if(i+1<10)
942              sprintf(expression,"([pixel]>=%.3f AND [pixel]<%.3f)",cstep,cstep+interval);
943            else
944              sprintf(expression,"([pixel]>=%.3f AND [pixel]<=%.3f)",cstep,cstep+interval);
[370]945            msLoadExpressionString(&myLayer->CLASS[myLayer->numclasses]->expression,expression);
[300]946           
947            /**
948             * Set color
949             */
[370]950            myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=_tmpColors[i][0];
951            myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=_tmpColors[i][1];
952            myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=_tmpColors[i][2];
[300]953            cstep+=interval;
[370]954            myLayer->CLASS[myLayer->numclasses]->numstyles++;
[300]955            myLayer->numclasses++;
956           
957          }
958         
959          char tmpMm[100];
960          sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
961         
[297]962        }
963      }
[752]964      else{
965        if(nBandsI==1){
966          myLayer->offsite.red=0;
967          myLayer->offsite.green=0;
968          myLayer->offsite.blue=0;
969        }
970        msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");
971      }
[297]972    }
973    if( strlen(GDALGetRasterUnitType(hBand)) > 0 ){
974      char tmpU[21];
975      sprintf(tmpU,"%s_band_uom",tmpN);
976      msInsertHashTable(&(myLayer->metadata), tmpU, GDALGetRasterUnitType(hBand));
977    }
978
979  }
980
981  m->layerorder[m->numlayers] = m->numlayers;
982  m->numlayers++;
983  GDALClose( hDataset );
984  GDALDestroyDriverManager();
985  CPLCleanupTLS();
986  return 1;
987}
988
989/**
990 * Create a MapFile for WMS, WFS or WCS Service output
[586]991 *
992 * @param conf the conf maps containing the main.cfg settings
993 * @param outputs a specific output maps
[297]994 */
995void outputMapfile(maps* conf,maps* outputs){
996
997  /**
[586]998   * First store the value on disk
[297]999   */
[360]1000  map* mime=getMap(outputs->content,"mimeType");
1001  char *ext="data";
1002  if(mime!=NULL)
1003    if(strncasecmp(mime->value,"application/json",16)==0)
1004      ext="json";
[458]1005
[297]1006  map* tmpMap=getMapFromMaps(conf,"main","dataPath");
[453]1007  map* sidMap=getMapFromMaps(conf,"lenv","usid");
[297]1008  char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
[458]1009  sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 
1010  int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
[550]1011  map *gfile=getMap(outputs->content,"generated_file");
1012  if(gfile!=NULL){
1013    readGeneratedFile(conf,outputs->content,gfile->value);         
1014  }
[297]1015  map* sizeMap=getMap(outputs->content,"size");
1016  map* vData=getMap(outputs->content,"value");
1017  if(sizeMap!=NULL){
[458]1018    zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
[297]1019  }
1020  else{
[458]1021    zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char));
[297]1022  }
1023  close(f);
1024  addToMap(outputs->content,"storage",pszDataSource);
[492]1025  free(pszDataSource);
[297]1026
1027  /*
1028   * Create an empty map, set name, default size and extent
1029   */
1030  mapObj *myMap=msNewMapObj();
1031  free(myMap->name);
[453]1032  myMap->name=zStrdup("ZOO-Project_WXS_Server");
[297]1033  msMapSetSize(myMap,2048,2048);
1034  msMapSetExtent(myMap,-1,-1,1,1);
1035 
1036  /*
1037   * Set imagepath and imageurl using tmpPath and tmpUrl from main.cfg
1038   */
1039  map *tmp1=getMapFromMaps(conf,"main","tmpPath");
[453]1040  myMap->web.imagepath=zStrdup(tmp1->value);
[297]1041  tmp1=getMapFromMaps(conf,"main","tmpUrl");
[453]1042  myMap->web.imageurl=zStrdup(tmp1->value);
[297]1043 
1044  /*
1045   * Define supported output formats
1046   */
1047  outputFormatObj *o1=msCreateDefaultOutputFormat(NULL,"AGG/PNG","png");
1048  o1->imagemode=MS_IMAGEMODE_RGBA;
1049  o1->transparent=MS_TRUE;
1050  o1->inmapfile=MS_TRUE;
1051  msAppendOutputFormat(myMap,msCloneOutputFormat(o1));
1052  msFreeOutputFormat(o1);
1053
1054#ifdef USE_KML
1055  outputFormatObj *o2=msCreateDefaultOutputFormat(NULL,"KML","kml");
1056  o2->inmapfile=MS_TRUE; 
1057  msAppendOutputFormat(myMap,msCloneOutputFormat(o2));
1058  msFreeOutputFormat(o2);
1059#endif
1060
1061  outputFormatObj *o3=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","tiff");
1062  if(!o3)
1063    fprintf(stderr,"Unable to initialize GDAL driver !\n");
1064  else{
1065    o3->imagemode=MS_IMAGEMODE_BYTE;
1066    o3->inmapfile=MS_TRUE; 
1067    msAppendOutputFormat(myMap,msCloneOutputFormat(o3));
1068    msFreeOutputFormat(o3);
1069  }
1070
1071  outputFormatObj *o4=msCreateDefaultOutputFormat(NULL,"GDAL/AAIGRID","grd");
1072  if(!o4)
1073    fprintf(stderr,"Unable to initialize GDAL driver !\n");
1074  else{
1075    o4->imagemode=MS_IMAGEMODE_INT16;
1076    o4->inmapfile=MS_TRUE; 
1077    msAppendOutputFormat(myMap,msCloneOutputFormat(o4));
1078    msFreeOutputFormat(o4);
1079  }
1080
1081#ifdef USE_CAIRO
1082  outputFormatObj *o5=msCreateDefaultOutputFormat(NULL,"CAIRO/PNG","cairopng");
1083  if(!o5)
1084    fprintf(stderr,"Unable to initialize CAIRO driver !\n");
1085  else{
1086    o5->imagemode=MS_IMAGEMODE_RGBA;
1087    o5->transparent=MS_TRUE;
1088    o5->inmapfile=MS_TRUE;
1089    msAppendOutputFormat(myMap,msCloneOutputFormat(o5));
1090    msFreeOutputFormat(o5);
1091  }
1092#endif
1093
1094  /*
1095   * Set default projection to EPSG:4326
1096   */
1097  msLoadProjectionStringEPSG(&myMap->projection,"EPSG:4326");
1098  myMap->transparent=1;
1099
1100  /**
1101   * Set metadata extracted from main.cfg file maps
1102   */
1103  maps* cursor=conf;
1104  map* correspondance=getCorrespondance();
1105  while(cursor!=NULL){
1106    map* _cursor=cursor->content;
1107    map* vMap;
1108    while(_cursor!=NULL){
1109      if((vMap=getMap(correspondance,_cursor->name))!=NULL){
1110        if (msInsertHashTable(&(myMap->web.metadata), vMap->value, _cursor->value) == NULL){
1111#ifdef DEBUGMS
1112          fprintf(stderr,"Unable to add metadata");
1113#endif
1114          return;
1115        }
1116      }
1117      _cursor=_cursor->next;
1118    }
1119    cursor=cursor->next;
1120  }
[492]1121  freeMap(&correspondance);
1122  free(correspondance);
[297]1123
[364]1124  /*
1125   * Set mapserver PROJ_LIB/GDAL_DATA or any other config parameter from
1126   * the main.cfg [mapserver] section if any
1127   */
1128  maps *tmp3=getMaps(conf,"mapserver");
1129  if(tmp3!=NULL){
1130    map* tmp4=tmp3->content;
1131    while(tmp4!=NULL){
1132      msSetConfigOption(myMap,tmp4->name,tmp4->value);
1133      tmp4=tmp4->next;
1134    }
1135  }
1136
[297]1137  /**
1138   * Set a ows_rootlayer_title, 
1139   */
1140  if (msInsertHashTable(&(myMap->web.metadata), "ows_rootlayer_name", "ZOO_Project_Layer") == NULL){
1141#ifdef DEBUGMS
1142    fprintf(stderr,"Unable to add metadata");
1143#endif
1144    return;
1145  }
1146  if (msInsertHashTable(&(myMap->web.metadata), "ows_rootlayer_title", "ZOO_Project_Layer") == NULL){
1147#ifdef DEBUGMS
1148    fprintf(stderr,"Unable to add metadata");
1149#endif
1150    return;
1151  }
1152
1153  /**
1154   * Enable all the WXS requests using ows_enable_request
1155   * see http://mapserver.org/trunk/development/rfc/ms-rfc-67.html
1156   */
1157  if (msInsertHashTable(&(myMap->web.metadata), "ows_enable_request", "*") == NULL){
1158#ifdef DEBUGMS
1159    fprintf(stderr,"Unable to add metadata");
1160#endif
1161    return;
1162  }
1163  msInsertHashTable(&(myMap->web.metadata), "ows_srs", "EPSG:4326");
1164
1165  if(tryOgr(conf,outputs,myMap)<0)
1166    if(tryGdal(conf,outputs,myMap)<0)
[364]1167      return ;
[297]1168
1169  tmp1=getMapFromMaps(conf,"main","dataPath");
1170  char *tmpPath=(char*)malloc((13+strlen(tmp1->value))*sizeof(char));
1171  sprintf(tmpPath,"%s/symbols.sym",tmp1->value);
1172  msInitSymbolSet(&myMap->symbolset);
[453]1173  myMap->symbolset.filename=zStrdup(tmpPath);
[297]1174  free(tmpPath);
1175
[453]1176  map* sid=getMapFromMaps(conf,"lenv","usid");
[297]1177  char *mapPath=
[458]1178    (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
[297]1179  sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);
1180  msSaveMap(myMap,mapPath);
[492]1181  free(mapPath);
1182  msGDALCleanup();
[297]1183  msFreeMap(myMap);
1184}
1185
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