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

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

First version including zoo_service shared library

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