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

Last change on this file since 828 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
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  };
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;
162  if(protoMap!=NULL){
163    if(strncasecmp(protoMap->value,"WMS",3)==0)
164      proto=0;
165    else{
166      if(strncasecmp(protoMap->value,"WFS",3)==0)
167        proto=1;
168      else 
169        proto=2;
170    }
171  }
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");
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  }
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
195  if(proto>0){
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            );
210  }
211  else{
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            );
228  }
229  if(hasCRS==0){
230    freeMap(&crs);
231    free(crs);
232  }
233  addToMap(tmpI->content,"Reference",webService_url);
234  free(webService_url);
235}
236
237/**
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
246 */
247void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer,
248                        char* pszProjection){
249  OGRSpatialReferenceH  hSRS;
250  map* msSrs=NULL;
251  hSRS = OSRNewSpatialReference(NULL);
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 EPSG:3857 %s",tmpSrs);
265       
266        msInsertHashTable(&(m->web.metadata), "ows_srs", tmpSrss);
267        msInsertHashTable(&(myLayer->metadata), "ows_srs", tmpSrss);
268       
269#ifdef DEBUGMS
270        fprintf(stderr,"isGeo %b\n\n",OSRIsGeographic(hSRS)==TRUE);
271#endif
272        if(output!=NULL){
273          if(OSRIsGeographic(hSRS)==TRUE)
274            addToMap(output->content,"crs_isGeographic","true");
275          else
276            addToMap(output->content,"crs_isGeographic","false");
277          addToMap(output->content,"crs",tmpSrs);
278        }
279      }
280      else{
281        OSRExportToProj4(hSRS,&proj4Str);
282        if(proj4Str!=NULL && strlen(proj4Str)>0){
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          }
294          free(proj4Str);
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        }
303        if(output!=NULL){
304          addToMap(output->content,"crs","EPSG:4326");
305          addToMap(output->content,"real_extent","true");
306        }
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");
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);
318      msLoadProjectionStringEPSG(&myLayer->projection,msSrs->value);
319      char tmpSrs[128];
320      sprintf(tmpSrs,"%s EPSG:4326 EPSG:900913 EPSG:3857",msSrs->value);
321      msInsertHashTable(&(m->web.metadata),"ows_srs",tmpSrs);
322      msInsertHashTable(&(myLayer->metadata),"ows_srs",tmpSrs);
323    }else{
324      msLoadProjectionStringEPSG(&m->projection,"EPSG:4326");
325      msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326");
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");
328    }
329    if(output!=NULL){
330      addToMap(output->content,"crs",msSrs->value);
331      addToMap(output->content,"crs_isGeographic","true");
332    }
333  }
334
335  OSRDestroySpatialReference( hSRS );
336}
337
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 */
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){
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");
376
377      msProjectPoint(&(m->projection),&tempSrs,&min);
378      msProjectPoint(&m->projection,&tempSrs,&max);
379     
380      sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x);
381      map* isGeo=getMap(output->content,"crs_isGeographic");
382#ifdef DEBUGMS
383      fprintf(stderr,"isGeo = %s\n",isGeo->value);
384#endif
385      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0)
386        sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
387      addToMap(output->content,"wms_extent",tmpExtent);
388      sprintf(tmpSrsStr,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
389      addToMap(output->content,"wcs_extent",tmpExtent);
390    }else{
391      sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY);
392      map* isGeo=getMap(output->content,"crs_isGeographic");
393      if(isGeo!=NULL){
394#ifdef DEBUGMS
395        fprintf(stderr,"isGeo = %s\n",isGeo->value);
396#endif
397        if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0)
398          sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
399      }
400      addToMap(output->content,"wms_extent",tmpExtent); 
401      sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",minX,minY,maxX,maxY);
402      addToMap(output->content,"wcs_extent",tmpExtent);
403    }
404  }
405
406  setMapSize(output,minX,minY,maxX,maxY);
407}
408
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 */
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
429  OGRDataSourceH poDS1 = NULL;
430  OGRSFDriverH *poDriver1 = NULL;
431  char *dsName=(char*)malloc((8+strlen(pszDataSource)+1)*sizeof(char));
432  char *odsName=zStrdup(pszDataSource);
433  char *sdsName=zStrdup(pszDataSource);
434  char *demo=".data";
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");
452  free(odsName);
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);
462#ifdef DEBUGMS
463  fprintf(stderr,"Try loading %s",dsName);
464#endif
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{
471#ifdef DEBUGMS
472    fprintf(stderr,"The DataSource is a  ZIP File\n");
473#endif
474    char** demo=VSIReadDir(dsName);
475    int i=0;
476    zMkdir(sdsName
477#ifndef WIN32
478                ,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
479#endif
480                );
481    while(demo[i]!=NULL){
482#ifdef DEBUGMS
483      fprintf(stderr,"ZIP File content : %s\n",demo[i]);
484#endif
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");
490#ifdef DEBUGMS
491      fprintf(stderr,"open : %s\n",tmpDs);
492#endif
493      VSIFSeekL(vsif,0,SEEK_END);
494      vsi_l_offset size=VSIFTellL(vsif);
495#ifdef DEBUGMS
496      fprintf(stderr,"size : %d\n",size);
497#endif
498      VSIFSeekL(vsif,0,SEEK_SET);
499      char *vsifcontent=(char*) malloc(((int)size+1)*sizeof(char));
500      VSIFReadL(vsifcontent,1,(size_t)size,vsif);
501      char *fpath=(char*) malloc((strlen(sdsName)+strlen(demo[1])+2)*sizeof(char));
502      sprintf(fpath,"%s/%s",sdsName,demo[i]);
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);
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){
511#ifdef DEBUGMS
512        fprintf(stderr,"*** DEBUG %s\n",strstr(tmpP,"."));
513#endif
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;
520#ifdef DEBUGMS
521          fprintf(stderr,"*** DEBUG %s\n",pszDataSource);
522#endif
523        }
524      }
525      VSIFCloseL(vsif);
526      i++;
527    }
528  }
529  free(sdsName);
530  free(dsName);
531
532  OGRDataSourceH poDS = NULL;
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++ ){
550    OGRLayerH poLayer = OGR_DS_GetLayer(poDS,iLayer);
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];
571#ifdef DEBUGMS
572    dumpMaps(output);
573#endif
574    myLayer->name = zStrdup(output->name);
575    myLayer->tileitem=NULL;
576    myLayer->data = zStrdup(OGR_L_GetName(poLayer));
577    myLayer->connection = zStrdup(pszDataSource);
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);
630      free(wkt);
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 EPSG:3857");
637      msInsertHashTable(&(myLayer->metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
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     */
648    char *fid=(char*)OGR_L_GetFIDColumn(poLayer);
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);
654        fid=(char*)OGR_Fld_GetNameRef(fdef);
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");
666   
667    if(msGrowLayerClasses(myLayer) == NULL)
668      return -1;
669    if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
670      return -1;
671    if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
672      return -1;
673    if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
674      return -1;
675    /**
676     * Apply msStyle else fallback to the default style
677     */
678    tmpMap=getMap(output->content,"msStyle");
679    if(tmpMap!=NULL)
680      msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
681    else{
682      /**
683       * Set style
684       */
685      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125;
686      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125;
687      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255;
688      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80;
689      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
690      myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
691     
692      /**
693       * Set specific style depending on type
694       */
695      if(myLayer->type == MS_LAYER_POLYGON)
696        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
697      if(myLayer->type == MS_LAYER_LINE){
698        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
699        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5;
700      }
701      if(myLayer->type == MS_LAYER_POINT){
702        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1;
703        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
704      }
705     
706    }
707    myLayer->CLASS[myLayer->numclasses]->numstyles++;
708    myLayer->numclasses++;
709   
710    m->layerorder[m->numlayers] = m->numlayers;
711    m->numlayers++;
712
713  }
714
715  OGR_DS_Destroy(poDS);
716  OGRCleanupAll();
717
718  return 1;
719}
720
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 */
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
743    fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename);
744#endif
745    setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open");
746    GDALDestroyDriverManager();
747    return -1;
748  }
749#ifdef DEBUGMS
750  fprintf(stderr,"Accessing the DataSource %s %d\n",pszFilename,__LINE__);
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  }
762  m->layers[m->numlayers]->index=m->numlayers;
763
764  layerObj* myLayer=m->layers[m->numlayers];
765  myLayer->name = zStrdup(output->name);
766  myLayer->tileitem=NULL;
767  myLayer->data = zStrdup(pszFilename);
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;
781
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   */
798  const char *tRef=GDALGetProjectionRef( hDataset );
799  if( tRef != NULL && strlen(tRef)>0 ){
800    char *pszProjection;
801    pszProjection = (char *) GDALGetProjectionRef( hDataset );
802#ifdef DEBUGMS
803    fprintf(stderr,"Accessing the DataSource %s\n",GDALGetProjectionRef( hDataset ));
804#endif
805    setSrsInformations(output,m,myLayer,pszProjection);
806  }else{
807    fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset ));   
808  }
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   */
836  char nBands[3];
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   */
850  char lBands[7];
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){
859        char *tmpS=zStrdup(nameBands);
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  /**
869   * Loops over metadata information to setup specific information
870   */
871  for( iBand = 0; iBand < nBandsI; iBand++ ){
872    //int         bGotNodata;//, bSuccess;
873    double      adfCMinMax[2]/*, dfNoData*/;
874    //int         nBlockXSize, nBlockYSize, nMaskFlags;
875    //double      /*dfMean, dfStdDev*/;
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
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)
916              return -1;
917            if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
918              return -1;
919            if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
920              return -1;
921            if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
922              return -1;
923           
924            /**
925             * Set class name
926             */
927            char className[7];
928            sprintf(className,"class%d",i);
929            myLayer->CLASS[myLayer->numclasses]->name=zStrdup(className);
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);
939            msLoadExpressionString(&myLayer->CLASS[myLayer->numclasses]->expression,expression);
940           
941            /**
942             * Set color
943             */
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];
947            cstep+=interval;
948            myLayer->CLASS[myLayer->numclasses]->numstyles++;
949            myLayer->numclasses++;
950           
951          }
952         
953          char tmpMm[100];
954          sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
955         
956        }
957      }
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      }
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
985 *
986 * @param conf the conf maps containing the main.cfg settings
987 * @param outputs a specific output maps
988 */
989void outputMapfile(maps* conf,maps* outputs){
990
991  /**
992   * First store the value on disk
993   */
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";
999
1000  map* tmpMap=getMapFromMaps(conf,"main","dataPath");
1001  map* sidMap=getMapFromMaps(conf,"lenv","usid");
1002  char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
1003  sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 
1004  int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
1005  map *gfile=getMap(outputs->content,"generated_file");
1006  if(gfile!=NULL){
1007    readGeneratedFile(conf,outputs->content,gfile->value);         
1008  }
1009  map* sizeMap=getMap(outputs->content,"size");
1010  map* vData=getMap(outputs->content,"value");
1011  if(sizeMap!=NULL){
1012    zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
1013  }
1014  else{
1015    zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char));
1016  }
1017  close(f);
1018  addToMap(outputs->content,"storage",pszDataSource);
1019  free(pszDataSource);
1020
1021  /*
1022   * Create an empty map, set name, default size and extent
1023   */
1024  mapObj *myMap=msNewMapObj();
1025  free(myMap->name);
1026  myMap->name=zStrdup("ZOO-Project_WXS_Server");
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");
1034  myMap->web.imagepath=zStrdup(tmp1->value);
1035  tmp1=getMapFromMaps(conf,"main","tmpUrl");
1036  myMap->web.imageurl=zStrdup(tmp1->value);
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  }
1115  freeMap(&correspondance);
1116  free(correspondance);
1117
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
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)
1161      return ;
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);
1167  myMap->symbolset.filename=zStrdup(tmpPath);
1168  free(tmpPath);
1169
1170  map* sid=getMapFromMaps(conf,"lenv","usid");
1171  char *mapPath=
1172    (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
1173  sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);
1174  msSaveMap(myMap,mapPath);
1175  free(mapPath);
1176  msGDALCleanup();
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