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

Last change on this file since 615 was 607, checked in by djay, 10 years ago

Introduce the Process Profiles Registry with its documentation.

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