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

Last change on this file since 586 was 586, checked in by djay, 9 years ago

Add the PHP ZOO-API, fix issue if ZTS is not defined, correct loading of the PHP script depending of the ZOO-Kernel location, use a ZEND_HANDLE_FD rather than the ZEND_HANDLE_FP used before, correct location of the hello.php service.

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