source: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c @ 839

Last change on this file since 839 was 839, checked in by djay, 7 years ago

Update the source code for HPC support. Automatically adding nested outputs for the HPC support (should this be available for every support?). Add capability to store the metadata in the Collection DataBase?. Addition of the zcfg2sql to import any existing ZCFG file into the Collection DB. Add the support to invoke a callback (for history purpose) in case a [callback] section contains at least one parameter defined (url). Add support to convert maps and map to JSON (for callback use only by now). Fix some memory leaks (some are still there).

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