Ignore:
Timestamp:
May 7, 2019, 2:17:08 PM (5 years ago)
Author:
djay
Message:

Merge prototype-v0 branch in trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/zoo-project/zoo-kernel/service_internal_ms.c

    r781 r917  
    3434#include "server_internal.h"
    3535#include "response_print.h"
     36#include "caching.h"
    3637
    3738/**
     
    7677
    7778/**
     79 * Return the current publish_id value
     80 * @param elem and maps pointer on which the search occur
     81 * @return the integer value of the publish_id field, if any, 0 otherwise
     82 */
     83int getPublishedId(maps* elem){
     84  if(elem!=NULL && elem->content!=NULL){
     85    map* myIndex=getMap(elem->content,"published_id");
     86    if(myIndex!=NULL){
     87      return atoi(myIndex->value);
     88    }
     89  }
     90  return 0;
     91}
     92
     93/**
    7894 * Add width and height keys to an output maps containing the maximum width
    7995 * and height for displaying the full data extent.
     
    87103 */
    88104void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){
     105  int imyIndex=getPublishedId(output);
    89106  double maxWidth=640;
    90107  double maxHeight=480;
     
    118135#endif
    119136  if(output!=NULL){
    120     addToMap(output->content,"width",sWidth);
    121     addToMap(output->content,"height",sHeight);
     137    setMapArray(output->content,"width",imyIndex,sWidth);
     138    setMapArray(output->content,"height",imyIndex,sHeight);
    122139  }
    123140}
     
    131148 */
    132149void setReferenceUrl(maps* m,maps* tmpI){
     150  int imyIndex=getPublishedId(tmpI);
     151  if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL)
     152    return;
    133153  outputMapfile(m,tmpI);
    134154  map *msUrl=getMapFromMaps(m,"main","mapserverAddress");
     
    138158    exit(-1);
    139159  }
     160  if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL)
     161    return;
     162  int finalProto=-1;
    140163  map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion");
    141164  map *dataPath=getMapFromMaps(m,"main","dataPath");
    142165  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]={
     166  map* format=getMapArray(tmpI->content,"mimeType",imyIndex);
     167  map* rformat=getMapArray(tmpI->content,"requestedMimeType",imyIndex);
     168  map* width=getMapArray(tmpI->content,"width",imyIndex);
     169  map* height=getMapArray(tmpI->content,"height",imyIndex);
     170  map* protoMap=getMapArray(tmpI->content,"msOgc",imyIndex);
     171  map* versionMap=getMapArray(tmpI->content,"msOgcVersion",imyIndex);
     172  map* datatype=getMapArray(tmpI->content,"geodatatype",imyIndex);
     173  map* layerName=getMapArray(tmpI->content,"msLayer",imyIndex);
     174  char options[4][5][25]={
    150175    {"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"}
     176    {"WFS","1.0.0","GetFeature","typename=%s","wcs_extent"},
     177    {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"},
     178    {"WCS","1.0.0","GetCoverage","coverage=%s","wcs_extent"}
    153179  };
     180  map *nbElements=getMapArray(tmpI->content,"nb_features",imyIndex);
     181  if(nbElements==NULL)
     182    nbElements=getMapArray(tmpI->content,"nb_pixels",imyIndex);
     183  if(datatype==NULL || strncmp(datatype->value,"other",5)==0 || (nbElements!=NULL && atoi(nbElements->value)==0)){
     184    map* minNb=getMap(tmpI->content,"minoccurs");
     185    map* useMs=getMap(tmpI->content,"useMapserver");
     186    if((minNb==NULL || atoi(minNb->value)>=1) && useMs!=NULL && strncasecmp(useMs->value,"true",4)==0){
     187      int lIndex=0;
     188      maps* lenv=getMaps(m,"lenv");
     189      if(getMapFromMaps(m,"lenv","mapErrorNb")==NULL)
     190        setMapInMaps(m,"lenv","mapErrorNb","0");
     191      else{
     192        map* tmpV=getMapFromMaps(m,"lenv","mapErrorNb");
     193        lIndex=atoi(tmpV->value)+1;
     194        addIntToMap(lenv->content,"mapErrorNb",lIndex);
     195      }
     196      setMapInMaps(m,"lenv","mapError","true");
     197      setMapArray(lenv->content,"locator",lIndex,tmpI->name);
     198      if(nbElements==NULL)
     199        setMapArray(lenv->content,"message",lIndex,_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
     200      else
     201        setMapArray(lenv->content,"message",lIndex,_("The ZOO-Kernel was able to retrieve the data but could not access any feature or pixel in te resulting file."));
     202      if(getMapFromMaps(m,"lenv","state")==NULL)
     203        errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name);
     204    }
     205    return;
     206  }
    154207  int proto=0;
    155208  if(rformat==NULL){
    156     rformat=getMap(tmpI->content,"mimeType");
     209    rformat=getMapArray(tmpI->content,"mimeType",imyIndex);
    157210  }
    158211  if(strncasecmp(rformat->value,"text/xml",8)==0)
    159212    proto=1;
    160   if(strncasecmp(rformat->value,"image/tiff",10)==0)
     213  if(strncasecmp(rformat->value,"image/tiff",10)==0 ||
     214     strncasecmp(rformat->value,"image/geotiff",10)==0)
    161215    proto=2;
     216  int hasFormat=-1;
    162217  if(protoMap!=NULL){
    163     if(strncasecmp(protoMap->value,"WMS",3)==0)
     218    hasFormat=1;
     219    if(strncasecmp(protoMap->value,"WMS",3)==0){
    164220      proto=0;
     221      rformat=createMap("value","image/png");
     222    }
    165223    else{
    166       if(strncasecmp(protoMap->value,"WFS",3)==0)
     224      if(strncasecmp(protoMap->value,"WFS",3)==0){
    167225        proto=1;
    168       else
     226        rformat=createMap("value","text/xml");
     227      }
     228      else {
    169229        proto=2;
     230        rformat=createMap("value","image/tiff");
     231      }
    170232    }
    171233  }
     
    178240  }
    179241
    180   map* extent=getMap(tmpI->content,options[proto][4]);
    181   map* crs=getMap(tmpI->content,"crs");
     242
     243  map* extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
     244  map* crs=getMapArray(tmpI->content,"crs",imyIndex);
    182245  int hasCRS=1;
    183246  if(crs==NULL){
     
    189252  }
    190253  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));
     254  if(layerName==NULL)
     255    sprintf(layers,options[proto][3],tmpI->name);
     256  else
     257    sprintf(layers,options[proto][3],layerName->value);
     258
     259  if(format==NULL || width==NULL || height==NULL || extent==NULL){
     260    char tmpStr[1024];
     261    sprintf(tmpStr,_("Unable to create the mapfile for %s because of missing values."),tmpI->name);
     262    errorException (m, tmpStr,
     263                    "InternalError", NULL);
     264    exit(-1);
     265    return;
     266  }
     267
     268  if(proto==0){
     269    hasFormat=1;
     270    rformat=createMap("mimeType","image/png");
     271  }else{
     272    if(proto==1){
     273      rformat=createMap("mimeType","text/xml");
     274      hasFormat=1;
     275    }
     276    else
     277      if(proto==2){
     278        rformat=createMap("mimeType","image/tiff");
     279        hasFormat=1;
     280        finalProto=1;
     281      }
     282  }
     283 
     284  char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(rformat->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char));
     285
    194286
    195287  if(proto>0){
     288    if(proto==2)
     289      finalProto=1;
    196290    sprintf(webService_url,
    197             "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
     291            "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
    198292            msUrl->value,
    199293            dataPath->value,
    200294            tmpI->name,
     295            imyIndex,
    201296            sid->value,
    202297            options[proto][2],
     
    208303            crs->value
    209304            );
     305    if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
     306      setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url);
     307    }
     308    else{
     309      setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url);
     310    }
     311    proto=0;
     312    freeMap(&rformat);
     313    free(rformat);
     314    rformat=createMap("mimeType","image/png");
    210315  }
    211316  else{
    212317    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",
     318            "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
    214319            msUrl->value,
    215320            dataPath->value,
    216321            tmpI->name,
     322            imyIndex,
    217323            sid->value,
    218324            options[proto][2],
     
    226332            crs->value
    227333            );
     334    setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url);
     335    if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
     336      proto=2;
     337      freeMap(&rformat);
     338      free(rformat);
     339      rformat=createMap("mimeType","image/tiff");
     340    }
     341    else{
     342      proto=1;
     343      freeMap(&rformat);
     344      free(rformat);
     345      rformat=createMap("mimeType","text/xml");
     346    }
     347  }
     348  setMapArray(tmpI->content,"Reference",imyIndex,webService_url);
     349  memset(layers,0,128);
     350  sprintf(layers,options[proto][3],tmpI->name);
     351  protoVersion=options[proto][1];
     352  extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
     353  memset(webService_url,0,strlen(webService_url));
     354  if(proto>0){
     355    if(proto==2)
     356      finalProto=1;
     357    sprintf(webService_url,
     358            "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
     359            msUrl->value,
     360            dataPath->value,
     361            tmpI->name,
     362            imyIndex,
     363            sid->value,
     364            options[proto][2],
     365            options[proto][0],
     366            protoVersion,
     367            layers,
     368            rformat->value,
     369            extent->value,
     370            crs->value
     371            );
     372    if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
     373      setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url);
     374    }
     375    else{
     376      setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url);
     377    }
     378  }else{
     379    sprintf(webService_url,
     380            "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
     381            msUrl->value,
     382            dataPath->value,
     383            tmpI->name,
     384            imyIndex,
     385            sid->value,
     386            options[proto][2],
     387            options[proto][0],
     388            protoVersion,
     389            layers,
     390            width->value,
     391            height->value,
     392            rformat->value,
     393            extent->value,
     394            crs->value
     395            );
     396    setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url);
     397  }
     398  if(finalProto>0){
     399    proto=3;
     400    memset(layers,0,128);
     401    sprintf(layers,options[proto][3],tmpI->name);
     402    protoVersion=options[proto][1];
     403    extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
     404    memset(webService_url,0,strlen(webService_url));
     405     freeMap(&rformat);
     406    free(rformat);
     407    rformat=createMap("value","image/tiff");
     408    sprintf(webService_url,
     409            "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
     410            msUrl->value,
     411            dataPath->value,
     412            tmpI->name,
     413            imyIndex,
     414            sid->value,
     415            options[proto][2],
     416            options[proto][0],
     417            protoVersion,
     418            layers,
     419            rformat->value,
     420            extent->value,
     421            crs->value
     422            );
     423    setMapArray(tmpI->content,"ref_wcs_preview_link",imyIndex,webService_url);
    228424  }
    229425  if(hasCRS==0){
     
    231427    free(crs);
    232428  }
    233   addToMap(tmpI->content,"Reference",webService_url);
     429  freeMap(&rformat);
     430  free(rformat);
    234431  free(webService_url);
    235432}
     
    249446  OGRSpatialReferenceH  hSRS;
    250447  map* msSrs=NULL;
     448  int imyIndex=getPublishedId(output);
    251449  hSRS = OSRNewSpatialReference(NULL);
    252450  if( pszProjection!=NULL && strlen(pszProjection)>1){
     
    272470        if(output!=NULL){
    273471          if(OSRIsGeographic(hSRS)==TRUE)
    274             addToMap(output->content,"crs_isGeographic","true");
     472            setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
    275473          else
    276             addToMap(output->content,"crs_isGeographic","false");
    277           addToMap(output->content,"crs",tmpSrs);
     474            setMapArray(output->content,"crs_isGeographic",imyIndex,"false");
     475          setMapArray(output->content,"crs",imyIndex,tmpSrs);
    278476        }
    279477      }
     
    288486          if(output!=NULL){
    289487            if(OSRIsGeographic(hSRS)==TRUE)
    290               addToMap(output->content,"crs_isGeographic","true");
     488              setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
    291489            else
    292               addToMap(output->content,"crs_isGeographic","false");
     490              setMapArray(output->content,"crs_isGeographic",imyIndex,"false");
    293491          }
    294492          free(proj4Str);
     
    298496          msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326");
    299497          if(output!=NULL){
    300             addToMap(output->content,"crs_isGeographic","true");
     498            setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
    301499          }
    302500        }
    303501        if(output!=NULL){
    304           addToMap(output->content,"crs","EPSG:4326");
    305           addToMap(output->content,"real_extent","true");
     502          setMapArray(output->content,"crs",imyIndex,"EPSG:4326");
     503          setMapArray(output->content,"real_extent",imyIndex,"true");
    306504        }
    307505        msInsertHashTable(&(m->web.metadata),"ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
     
    312510  else{
    313511    if(output!=NULL){
    314       msSrs=getMap(output->content,"msSrs");
     512      msSrs=getMapArray(output->content,"msSrs",imyIndex);
    315513    }
    316514    if(msSrs!=NULL){
     
    328526    }
    329527    if(output!=NULL){
    330       addToMap(output->content,"crs",msSrs->value);
    331       addToMap(output->content,"crs_isGeographic","true");
     528      setMapArray(output->content,"crs",imyIndex,msSrs->value);
     529      setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
    332530    }
    333531  }
     
    351549void setMsExtent(maps* output,mapObj* m,layerObj* myLayer,
    352550                 double minX,double minY,double maxX,double maxY){
     551  int imyIndex=getPublishedId(output);
    353552  msMapSetExtent(m,minX,minY,maxX,maxY);
     553  //m->maxsize=4096;
    354554#ifdef DEBUGMS
    355555  fprintf(stderr,"Extent %.15f %.15f %.15f %.15f\n",minX,minY,maxX,maxY);
     
    363563 
    364564  if(output!=NULL){
    365     map* test=getMap(output->content,"real_extent");
     565    map* test=getMapArray(output->content,"real_extent",imyIndex);
     566    pointObj min, max;
     567    projectionObj tempSrs;
     568    min.x = m->extent.minx;
     569    min.y = m->extent.miny;
     570    max.x = m->extent.maxx;
     571    max.y = m->extent.maxy;
     572    char tmpSrsStr[1024];
     573    msInitProjection(&tempSrs);
     574    msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326");
     575
     576    msProjectPoint(&(myLayer->projection),&tempSrs,&min);
     577    msProjectPoint(&myLayer->projection,&tempSrs,&max);
     578 
    366579    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");
     580      sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.y,min.x,max.y,max.x);
     581      map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex);
    382582#ifdef DEBUGMS
    383583      fprintf(stderr,"isGeo = %s\n",isGeo->value);
    384584#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);
     585      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0){
     586        sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.y,min.x,max.y,max.x);
     587        setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
     588        sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f", minY,minX, maxY, maxX);
     589      }else{
     590        sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y);
     591        setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
     592      }
     593      setMapArray(output->content,"wms_extent",imyIndex,tmpExtent);
     594      sprintf(tmpSrsStr,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y);
     595      setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent);
    390596    }else{
    391       sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY);
    392       map* isGeo=getMap(output->content,"crs_isGeographic");
     597      sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",min.x,min.y,max.x,max.y);
     598      setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
     599      sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",minX, minY, maxX, maxY);
     600      map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex);
    393601      if(isGeo!=NULL){
    394602#ifdef DEBUGMS
     
    396604#endif
    397605        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);
     606          sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f", minY,minX, maxY, maxX);
     607      }
     608      setMapArray(output->content,"wms_extent",imyIndex,tmpExtent);
     609      sprintf(tmpExtent,"%.15f,%.15f,%.15f,%.15f",minX,minY,maxX,maxY);
     610      setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent);
    403611    }
    404612  }
     
    415623 */
    416624int tryOgr(maps* conf,maps* output,mapObj* m){
    417 
    418   map* tmpMap=getMap(output->content,"storage");
     625  int imyIndex=getPublishedId(output);
     626  map* tmpMap=getMapArray(output->content,"storage",imyIndex);
    419627  char *pszDataSource=tmpMap->value;
    420628
     
    425633  /**
    426634   * Try to load the file as ZIP
    427    */
    428 
     635   *
    429636  OGRDataSourceH poDS1 = NULL;
    430637  OGRSFDriverH *poDriver1 = NULL;
     
    467674    fprintf(stderr,"Unable to access the DataSource as ZIP File\n");
    468675    setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
    469     OGR_DS_Destroy(poDS1);
     676    fprintf(stderr,"Remove ZIP File!\n");
     677    unlink(odsName);
     678    //OGR_DS_Destroy(poDS1);
    470679  }else{
    471680#ifdef DEBUGMS
     
    526735      i++;
    527736    }
    528   }
     737    OGR_DS_Destroy(poDS1);
     738    }
    529739  free(sdsName);
    530   free(dsName);
    531 
     740  free(dsName);*/
     741 
    532742  OGRDataSourceH poDS = NULL;
    533743  OGRSFDriverH *poDriver = NULL;
     
    538748#endif
    539749    setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
    540     OGR_DS_Destroy(poDS);
    541     OGRCleanupAll();
    542750#ifdef DEBUGMS
    543751    fprintf(stderr,"Unable to access the DataSource, exit! \n");
     
    546754  }
    547755
     756  setMapArray(output->content,"gdalType",imyIndex,OGR_Dr_GetName(OGR_DS_GetDriver(poDS))); 
     757  setMapArray(output->content,"geodatatype",imyIndex,"vector");
    548758  int iLayer = 0;
    549759  for( iLayer=0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++ ){
     
    561771     * Add a new layer set name, data
    562772     */
    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];
     773    layerObj* myLayer=NULL;
     774    if(getMapArray(output->content,"msInclude",imyIndex)==NULL){
     775      if(msGrowMapLayers(m)==NULL){
     776        return -1;
     777      }
     778      if(initLayer((m->layers[m->numlayers]), m) == -1){
     779        return -1;
     780      }
     781      myLayer=m->layers[m->numlayers];
     782    }else{
     783      myLayer=m->layers[m->numlayers-1];
     784    }
     785   
    571786#ifdef DEBUGMS
    572787    dumpMaps(output);
     
    580795    myLayer->status = MS_ON;
    581796    msConnectLayer(myLayer,MS_OGR,pszDataSource);
     797
     798    addIntToMapArray(output->content,"nb_features",imyIndex,OGR_L_GetFeatureCount(poLayer,1));
    582799
    583800    /**
     
    631848    }
    632849    else{
    633       addToMap(output->content,"crs","EPSG:4326");
    634       addToMap(output->content,"crs_isGeographic","true");
     850      setMapArray(output->content,"crs",imyIndex,"EPSG:4326");
     851      setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
    635852      msLoadProjectionStringEPSG(&m->projection,"EPSG:4326");
    636853      msInsertHashTable(&(m->web.metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
     
    641858    if (OGR_L_GetExtent(poLayer,&oExt, TRUE) == OGRERR_NONE){
    642859      setMsExtent(output,m,myLayer,oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
     860      char extent[1024];
     861      memset(&extent,0,1024);
     862      sprintf(extent,"%d,%d,%d,%d",oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
     863      setMapArray(output->content,"boundingbox",imyIndex,extent);
    643864    }
    644865 
     
    659880    msInsertHashTable(&(myLayer->metadata), "gml_include_items", "all");
    660881    msInsertHashTable(&(myLayer->metadata), "ows_name", output->name);
    661     map* tmpMap=getMap(output->content,"title");
     882    map* tmpMap=getMapArray(output->content,"title",imyIndex);
    662883    if(tmpMap!=NULL)
    663884      msInsertHashTable(&(myLayer->metadata), "ows_title", tmpMap->value);
    664885    else
    665886      msInsertHashTable(&(myLayer->metadata), "ows_title", "Default Title");
     887
     888    if(getMapArray(output->content,"msInclude",imyIndex)==NULL){
     889      if(msGrowLayerClasses(myLayer) == NULL)
     890        return -1;
     891      if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
     892        return -1;
     893      if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
     894        return -1;
     895      if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
     896        return -1;
     897      /**
     898       * Apply msStyle else fallback to the default style
     899       */
     900      tmpMap=getMap(output->content,"msStyle");
     901      if(tmpMap==NULL){
     902        switch(myLayer->type){
     903        case MS_LAYER_POLYGON:
     904          tmpMap=getMapFromMaps(conf,"main","msStylePoly");
     905          break;
     906        case MS_LAYER_LINE:
     907          tmpMap=getMapFromMaps(conf,"main","msStyleLine");
     908          break;
     909        default:
     910          tmpMap=getMapFromMaps(conf,"main","msStylePoint");
     911          break;
     912        }
     913      }
     914      if(tmpMap!=NULL)
     915        msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
     916      else{
     917        /**
     918         * Set style
     919         */
     920        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125;
     921        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125;
     922        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255;
     923        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80;
     924        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
     925        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
     926       
     927        /**
     928         * Set specific style depending on type
     929         */
     930        if(myLayer->type == MS_LAYER_POLYGON)
     931          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
     932        if(myLayer->type == MS_LAYER_LINE){
     933          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
     934          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5;
     935        }
     936        if(myLayer->type == MS_LAYER_POINT){
     937          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1;
     938          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
     939        }
     940       
     941      }
     942      myLayer->CLASS[myLayer->numclasses]->numstyles++;
     943      myLayer->numclasses++;
    666944   
    667     if(msGrowLayerClasses(myLayer) == NULL)
    668       return -1;
    669     if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
    670       return -1;
    671     if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
    672       return -1;
    673     if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
    674       return -1;
    675     /**
    676      * Apply msStyle else fallback to the default style
    677      */
    678     tmpMap=getMap(output->content,"msStyle");
    679     if(tmpMap!=NULL)
    680       msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
    681     else{
    682       /**
    683        * Set style
    684        */
    685       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125;
    686       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125;
    687       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255;
    688       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80;
    689       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
    690       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
    691      
    692       /**
    693        * Set specific style depending on type
    694        */
    695       if(myLayer->type == MS_LAYER_POLYGON)
    696         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
    697       if(myLayer->type == MS_LAYER_LINE){
    698         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
    699         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5;
    700       }
    701       if(myLayer->type == MS_LAYER_POINT){
    702         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1;
    703         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
    704       }
    705      
    706     }
    707     myLayer->CLASS[myLayer->numclasses]->numstyles++;
    708     myLayer->numclasses++;
    709    
    710     m->layerorder[m->numlayers] = m->numlayers;
    711     m->numlayers++;
    712 
    713   }
    714 
     945      m->layerorder[m->numlayers] = m->numlayers;
     946      m->numlayers++;
     947
     948    }
     949  }
    715950  OGR_DS_Destroy(poDS);
    716   OGRCleanupAll();
     951  //OGRCleanupAll();
    717952
    718953  return 1;
     
    727962 */
    728963int tryGdal(maps* conf,maps* output,mapObj* m){
    729   map* tmpMap=getMap(output->content,"storage");
     964  int imyIndex=getPublishedId(output);
     965  map* tmpMap=getMapArray(output->content,"storage",imyIndex);
     966  map* styleMap=getMap(output->content,"msStyle");
    730967  char *pszFilename=tmpMap->value;
    731968  GDALDatasetH hDataset;
     
    738975   */
    739976  GDALAllRegister();
    740   hDataset = GDALOpen( pszFilename, GA_ReadOnly );
     977  hDataset = GDALOpen( pszFilename, GA_Update ); /*GA_ReadOnly*/
    741978  if( hDataset == NULL ){
    742979#ifdef DEBUGMS
    743980    fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename);
    744981#endif
     982    setMapArray(output->content,"geodatatype",imyIndex,"other");
    745983    setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open");
    746984    GDALDestroyDriverManager();
     
    751989#endif
    752990
     991  setMapArray(output->content,"geodatatype",imyIndex,"raster");
    753992  /**
    754993   * Add a new layer set name, data
     
    7721011
    7731012  char *title=output->name;
    774   tmpMap=getMap(output->content,"title");
     1013  tmpMap=getMapArray(output->content,"title",imyIndex);
    7751014  if(tmpMap!=NULL)
    7761015    title=tmpMap->value;
    7771016  char *abstract=output->name;
    778   tmpMap=getMap(output->content,"abstract");
     1017  tmpMap=getMapArray(output->content,"abstract",imyIndex);
    7791018  if(tmpMap!=NULL)
    7801019    abstract=tmpMap->value;
     
    7911030  m->width=GDALGetRasterXSize( hDataset );
    7921031  m->height=GDALGetRasterYSize( hDataset );
    793  
     1032  if(m->width>4096 || m->height>4096){
     1033    if(m->width>m->height)
     1034      m->maxsize=m->width;
     1035    else 
     1036      m->maxsize=m->height;
     1037  }else
     1038    m->maxsize=4096;
     1039  addIntToMapArray(output->content,"nb_pixels",imyIndex,GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset ));
     1040  int pixel_type=GDALGetRasterDataType( hDataset );
     1041  addIntToMapArray(output->content,"pixel_data_type",imyIndex,pixel_type);
     1042
     1043  int outputIndex=msGetOutputFormatIndex(m,"tiff");
     1044  if(outputIndex>=0){
     1045    m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE)));
     1046    outputIndex=msGetOutputFormatIndex(m,"geotiff");
     1047    if(outputIndex>=0)
     1048      m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE)));
     1049  }
     1050  //
     1051   
    7941052  /**
    7951053   * Set projection using Authority Code and Name if available or fallback to
     
    8051063    setSrsInformations(output,m,myLayer,pszProjection);
    8061064  }else{
    807     fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset ));   
    808   }
    809 
     1065    fprintf(stderr,"NO SRS FOUND %s %d ! %s\n",__FILE__,__LINE__,GDALGetProjectionRef( hDataset ));
     1066    fflush(stderr);
     1067    CPLErr sp=GDALSetProjection( hDataset , "+init=epsg:4326" );
     1068    if(sp!=CE_None){
     1069      fprintf(stderr,"NO SRS SET ! %s\n",CPLGetLastErrorMsg());
     1070    }
     1071  }
    8101072
    8111073  /**
     
    8251087        + adfGeoTransform[4] * GDALGetRasterXSize(hDataset);
    8261088
    827        setMsExtent(output,m,myLayer,minX,minY,maxX,maxY);
    828 
    829     }
     1089      setMsExtent(output,m,myLayer,minX,minY,maxX,maxY);
     1090      char extent[1024];
     1091      memset(&extent,0,1024);
     1092      sprintf(extent,"%d,%d,%d,%d",minX,minY,maxX,maxY);
     1093      setMapArray(output->content,"boundingbox",imyIndex,extent);
     1094    }
     1095  }else{
     1096    int scale=1;
     1097    if(m->width>2048){
     1098      addIntToMapArray(output->content,"width",imyIndex,2048);
     1099      scale=2048/m->width;
     1100    }else
     1101      addIntToMapArray(output->content,"width",imyIndex,m->width);
     1102    addIntToMapArray(output->content,"height",imyIndex,m->height*scale);
    8301103  }
    8311104
     
    8351108   */
    8361109  char nBands[3];
     1110  memset(&nBands,0,3);
    8371111  int nBandsI=GDALGetRasterCount( hDataset );
    838   sprintf(nBands,"%d",GDALGetRasterCount( hDataset ));
    839   msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands);
    840   if(nBandsI>=3)
    841     msLayerAddProcessing(myLayer,"BANDS=1,2,3");
    842   else if(nBandsI>=2)
    843     msLayerAddProcessing(myLayer,"BANDS=1,2");
    844   else
    845     msLayerAddProcessing(myLayer,"BANDS=1");
     1112  if(nBandsI<100){
     1113    sprintf(nBands,"%d",GDALGetRasterCount( hDataset ));
     1114    msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands);
     1115  }
     1116  if(styleMap==NULL || strstr(styleMap->value,"BANDS=")==NULL){
     1117    if(nBandsI>=3)
     1118      if(nBandsI==4)
     1119        msLayerAddProcessing(myLayer,"BANDS=1,2,3,4");
     1120      else
     1121        msLayerAddProcessing(myLayer,"BANDS=1,2,3");
     1122    else if(nBandsI>=2)
     1123      msLayerAddProcessing(myLayer,"BANDS=1,2");
     1124    else
     1125      msLayerAddProcessing(myLayer,"BANDS=1");
     1126  }
    8461127
    8471128  /**
     
    8511132  char *nameBands=NULL;
    8521133  for( iBand = 0; iBand < nBandsI; iBand++ ){
    853     sprintf(lBands,"Band%d",iBand+1);
     1134    memset(&lBands,0,7);
     1135    sprintf(lBands,"Band%d",iBand+1);   
    8541136    if(nameBands==NULL){
    8551137      nameBands=(char*)malloc((strlen(lBands)+1)*sizeof(char));
    8561138      sprintf(nameBands,"%s",lBands);
    8571139    }else{
    858       if(iBand<4){
     1140      /*if(iBand<4)*/{
    8591141        char *tmpS=zStrdup(nameBands);
    860         nameBands=(char*)realloc(nameBands,(strlen(nameBands)+strlen(lBands)+1)*sizeof(char));
     1142        nameBands=(char*)realloc(nameBands,(strlen(tmpS)+strlen(lBands)+2)*sizeof(char));
    8611143        sprintf(nameBands,"%s %s",tmpS,lBands);
    8621144        free(tmpS);
     
    8641146    }
    8651147  }
    866   msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands);
    867  
     1148  if(nameBands!=NULL){
     1149    msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands);
     1150    free(nameBands);
     1151  }
     1152
    8681153  /**
    8691154   * Loops over metadata information to setup specific information
    8701155   */
    8711156  for( iBand = 0; iBand < nBandsI; iBand++ ){
    872     //int         bGotNodata;//, bSuccess;
    873     double      adfCMinMax[2]/*, dfNoData*/;
    874     //int         nBlockXSize, nBlockYSize, nMaskFlags;
    875     //double      /*dfMean, dfStdDev*/;
     1157    double      pdfMin, pdfMax, pdfMean, pdfStdDev;
    8761158    hBand = GDALGetRasterBand( hDataset, iBand+1 );
    8771159
    8781160    CPLErrorReset();
    879     GDALComputeRasterMinMax( hBand, FALSE, adfCMinMax );
     1161    GDALGetRasterStatistics( hBand, TRUE, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev);
    8801162    char tmpN[21];
    8811163    sprintf(tmpN,"Band%d",iBand+1);
    8821164    if (CPLGetLastErrorType() == CE_None){
    883       char tmpMm[100];
    884       sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
    885       char tmpI[21];
     1165      char tmpMm[100],tmpMp[100],tmpNb[3];
     1166      sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax);
     1167      if(pdfMin!=pdfMax && (styleMap==NULL || strstr(styleMap->value,"SCALE_")==NULL)){
     1168        sprintf(tmpNb,"%d",iBand+1);
     1169        if(styleMap==NULL || strstr(styleMap->value,"BANDS=")==NULL || strstr(strstr(styleMap->value,"BANDS="),tmpNb)!=NULL){
     1170          if(pdfMean-(2*pdfStdDev)<0)
     1171            sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,0.0,pdfMean+(2*pdfStdDev));
     1172          else
     1173            sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev));
     1174          msLayerAddProcessing(myLayer,tmpMp);
     1175        }
     1176      }
     1177      char tmpI[31];     
    8861178      sprintf(tmpI,"%s_interval",tmpN);
    8871179      msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm);
    888 
    8891180      map* test=getMap(output->content,"msClassify");
    8901181      if(test!=NULL && strncasecmp(test->value,"true",4)==0){
     
    9061197         
    9071198        if(nBandsI==1){
    908           double delta=adfCMinMax[1]-adfCMinMax[0];
     1199          double delta=pdfMax-pdfMin;
    9091200          double interval=delta/10;
    910           double cstep=adfCMinMax[0];
     1201          double cstep=pdfMin;
    9111202          for(i=0;i<10;i++){
    9121203            /**
     
    9521243         
    9531244          char tmpMm[100];
    954           sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
     1245          sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax);
    9551246         
    9561247        }
     
    9621253          myLayer->offsite.blue=0;
    9631254        }
    964         msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");
    9651255      }
    9661256    }
    9671257    if( strlen(GDALGetRasterUnitType(hBand)) > 0 ){
    968       char tmpU[21];
     1258      char tmpU[31];
    9691259      sprintf(tmpU,"%s_band_uom",tmpN);
    9701260      msInsertHashTable(&(myLayer->metadata), tmpU, GDALGetRasterUnitType(hBand));
     
    9721262
    9731263  }
    974 
     1264  if(styleMap==NULL || strstr(styleMap->value,"RESAMPLE")==NULL)
     1265    msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");
     1266 
     1267  if(styleMap!=NULL && strlen(styleMap->value)>9){
     1268    msUpdateLayerFromString(myLayer,styleMap->value,MS_FALSE);
     1269  }
     1270 
    9751271  m->layerorder[m->numlayers] = m->numlayers;
    9761272  m->numlayers++;
     
    9781274  GDALDestroyDriverManager();
    9791275  CPLCleanupTLS();
     1276  storeMd5(pszFilename);
    9801277  return 1;
    9811278}
     
    9881285 */
    9891286void outputMapfile(maps* conf,maps* outputs){
    990 
    9911287  /**
    9921288   * First store the value on disk
    9931289   */
    994   map* mime=getMap(outputs->content,"mimeType");
     1290  int imyIndex=getPublishedId(outputs);
     1291  map* mime=getMapArray(outputs->content,"mimeType",imyIndex);
     1292  map* msUrl=getMapFromMaps(conf,"main","mapserverAddress");
     1293  map* dataPath=getMapFromMaps(conf,"main","dataPath");
    9951294  char *ext="data";
    9961295  if(mime!=NULL)
     
    9981297      ext="json";
    9991298
    1000   map* tmpMap=getMapFromMaps(conf,"main","dataPath");
    1001   map* sidMap=getMapFromMaps(conf,"lenv","usid");
    1002   char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
    1003   sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext);
    1004   int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
    1005   map *gfile=getMap(outputs->content,"generated_file");
    1006   if(gfile!=NULL){
    1007     readGeneratedFile(conf,outputs->content,gfile->value);         
    1008   }
    1009   map* sizeMap=getMap(outputs->content,"size");
    1010   map* vData=getMap(outputs->content,"value");
    1011   if(sizeMap!=NULL){
    1012     zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
    1013   }
    1014   else{
    1015     zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char));
    1016   }
    1017   close(f);
    1018   addToMap(outputs->content,"storage",pszDataSource);
    1019   free(pszDataSource);
     1299  map* storage=getMapArray(outputs->content,"storage",imyIndex);
     1300  if(storage==NULL){
     1301    map* tmpMap=getMapFromMaps(conf,"main","dataPath");
     1302    map* sidMap=getMapFromMaps(conf,"lenv","usid");
     1303    char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
     1304    sprintf(pszDataSource,"%s/ZOO_DATA_%d_%s_%s.%s",tmpMap->value,imyIndex,outputs->name,sidMap->value,ext);
     1305    int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
     1306    map *gfile=getMapArray(outputs->content,"generated_file",imyIndex);
     1307    if(gfile!=NULL){
     1308      readGeneratedFile(conf,outputs->content,gfile->value);       
     1309    }
     1310    map* sizeMap=getMapArray(outputs->content,"size",imyIndex);
     1311    map* vData=getMapArray(outputs->content,"value",imyIndex);
     1312    if(sizeMap!=NULL){
     1313      zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
     1314    }
     1315    else{
     1316      zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char));
     1317    }
     1318    close(f);
     1319    setMapArray(outputs->content,"storage",imyIndex,pszDataSource);
     1320    free(pszDataSource);
     1321  }
    10201322
    10211323  /*
    10221324   * Create an empty map, set name, default size and extent
    10231325   */
    1024   mapObj *myMap=msNewMapObj();
     1326  map* mapfileTemplate=getMapArray(outputs->content,"msInclude",imyIndex);
     1327  mapObj *myMap=NULL;
     1328  if(mapfileTemplate==NULL){
     1329    myMap=msNewMapObj();
     1330  }
     1331  else{
     1332    map* dataPath=getMapFromMaps(conf,"main","dataPath");
     1333    map* sid=getMapFromMaps(conf,"lenv","sid");
     1334    char *mapfileTemplatePath=(char*)malloc(((strlen(dataPath->value)+strlen(sid->value)+strlen(outputs->name)+10)*sizeof(char)));
     1335    sprintf(mapfileTemplatePath,"%s/%s_%s.map",dataPath->value,outputs->name,sid->value);
     1336    myMap=msLoadMap(mapfileTemplate->value,mapfileTemplatePath);
     1337    if(myMap==NULL){
     1338      setMapInMaps(conf,"lenv","message",_("Unable to open your template mapfile!"));
     1339      return ;
     1340    }
     1341  }
    10251342  free(myMap->name);
    10261343  myMap->name=zStrdup("ZOO-Project_WXS_Server");
     
    10481365#ifdef USE_KML
    10491366  outputFormatObj *o2=msCreateDefaultOutputFormat(NULL,"KML","kml");
    1050   o2->inmapfile=MS_TRUE; 
    1051   msAppendOutputFormat(myMap,msCloneOutputFormat(o2));
    1052   msFreeOutputFormat(o2);
     1367  if(!o2){
     1368    perror("Unable to initialize KML driver");
     1369    fprintf(stderr,"Unable to initialize KML driver !\n");
     1370  }else{
     1371    o2->inmapfile=MS_TRUE; 
     1372    msAppendOutputFormat(myMap,msCloneOutputFormat(o2));
     1373    msFreeOutputFormat(o2);
     1374  }
    10531375#endif
    10541376
     
    10571379    fprintf(stderr,"Unable to initialize GDAL driver !\n");
    10581380  else{
    1059     o3->imagemode=MS_IMAGEMODE_BYTE;
     1381    o3->imagemode=MS_IMAGEMODE_INT16;
    10601382    o3->inmapfile=MS_TRUE; 
    10611383    msAppendOutputFormat(myMap,msCloneOutputFormat(o3));
     
    10671389    fprintf(stderr,"Unable to initialize GDAL driver !\n");
    10681390  else{
    1069     o4->imagemode=MS_IMAGEMODE_INT16;
     1391    o4->imagemode=MS_IMAGEMODE_BYTE;
    10701392    o4->inmapfile=MS_TRUE; 
    10711393    msAppendOutputFormat(myMap,msCloneOutputFormat(o4));
     
    10861408#endif
    10871409
     1410 
     1411  outputFormatObj *o6=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","geotiff");
     1412  if(!o6)
     1413    fprintf(stderr,"Unable to initialize GDAL driver !\n");
     1414  else{
     1415    o6->imagemode=MS_IMAGEMODE_BYTE;
     1416    o6->mimetype=strdup("image/geotiff");
     1417    o6->inmapfile=MS_TRUE;
     1418    msAppendOutputFormat(myMap,msCloneOutputFormat(o6));
     1419    msFreeOutputFormat(o6);
     1420  }
     1421
     1422 
    10881423  /*
    10891424   * Set default projection to EPSG:4326
     
    10911426  msLoadProjectionStringEPSG(&myMap->projection,"EPSG:4326");
    10921427  myMap->transparent=1;
    1093 
    1094   /**
    1095    * Set metadata extracted from main.cfg file maps
    1096    */
    1097   maps* cursor=conf;
    1098   map* correspondance=getCorrespondance();
    1099   while(cursor!=NULL){
    1100     map* _cursor=cursor->content;
    1101     map* vMap;
    1102     while(_cursor!=NULL){
    1103       if((vMap=getMap(correspondance,_cursor->name))!=NULL){
    1104         if (msInsertHashTable(&(myMap->web.metadata), vMap->value, _cursor->value) == NULL){
    1105 #ifdef DEBUGMS
    1106           fprintf(stderr,"Unable to add metadata");
    1107 #endif
    1108           return;
    1109         }
    1110       }
    1111       _cursor=_cursor->next;
    1112     }
    1113     cursor=cursor->next;
    1114   }
    1115   freeMap(&correspondance);
    1116   free(correspondance);
    11171428
    11181429  /*
     
    11571468  msInsertHashTable(&(myMap->web.metadata), "ows_srs", "EPSG:4326");
    11581469
     1470  /**
     1471   * Set metadata extracted from main.cfg file maps
     1472   */
     1473  maps* cursor=conf;
     1474  map* correspondance=getCorrespondance();
     1475  while(cursor!=NULL){
     1476    if(strstr(cursor->name,"_help")==NULL){
     1477      map* _cursor=cursor->content;
     1478      map* vMap;
     1479      while(_cursor!=NULL){
     1480        if((vMap=getMap(correspondance,_cursor->name))!=NULL){
     1481          if (msInsertHashTable(&(myMap->web.metadata), vMap->value, _cursor->value) == NULL){
     1482#ifdef DEBUGMS
     1483            fprintf(stderr,"Unable to add metadata");
     1484#endif
     1485            freeMap(&correspondance);
     1486            free(correspondance);
     1487            return;
     1488          }
     1489        }
     1490        _cursor=_cursor->next;
     1491      }
     1492    }
     1493    cursor=cursor->next;
     1494  }
     1495  freeMap(&correspondance);
     1496  free(correspondance);
     1497
     1498  map* sid=getMapFromMaps(conf,"lenv","usid");
     1499  char *mapPath=
     1500    (char*)malloc((14+strlen(sid->value)+strlen(outputs->name)+strlen(dataPath->value))*sizeof(char));
     1501  sprintf(mapPath,"%s/%s_%d_%s.map",dataPath->value,outputs->name,imyIndex,sid->value);
     1502  char *mapUrl=
     1503    (char*)malloc((6+strlen(mapPath)+strlen(msUrl->value))*sizeof(char));
     1504  sprintf(mapUrl,"%s?map=%s",msUrl->value,mapPath);
     1505
     1506  if (msInsertHashTable(&(myMap->web.metadata), "ows_onlineresource", mapUrl) == NULL){
     1507#ifdef DEBUGMS
     1508    fprintf(stderr,"Unable to add metadata");
     1509#endif
     1510    return;
     1511  }
     1512
    11591513  if(tryOgr(conf,outputs,myMap)<0)
    11601514    if(tryGdal(conf,outputs,myMap)<0)
    11611515      return ;
    11621516
    1163   tmp1=getMapFromMaps(conf,"main","dataPath");
    1164   char *tmpPath=(char*)malloc((13+strlen(tmp1->value))*sizeof(char));
    1165   sprintf(tmpPath,"%s/symbols.sym",tmp1->value);
     1517  char *tmpPath=(char*)malloc((13+strlen(dataPath->value))*sizeof(char));
     1518  sprintf(tmpPath,"%s/symbols.sym",dataPath->value);
    11661519  msInitSymbolSet(&myMap->symbolset);
    11671520  myMap->symbolset.filename=zStrdup(tmpPath);
    11681521  free(tmpPath);
    11691522
    1170   map* sid=getMapFromMaps(conf,"lenv","usid");
    1171   char *mapPath=
    1172     (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
    1173   sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);
    11741523  msSaveMap(myMap,mapPath);
     1524  saveMapNames(conf,outputs,mapPath);
    11751525  free(mapPath);
     1526  //free(myMap->symbolset.filename);
     1527  //msFreeSymbolSet(&myMap->symbolset);
     1528  msFreeMap(myMap);
     1529  //msFree(myMap);
    11761530  msGDALCleanup();
    1177   msFreeMap(myMap);
    11781531}
    11791532
     1533/**
     1534 * Save the map fullpath in a text file (.maps)
     1535 * @param conf the main configuration map pointer
     1536 * @param output the current output for which a mapfile has been generated
     1537 * @param mapfile the mapfile saved to store in the text file
     1538 */
     1539void saveMapNames(maps* conf,maps* output,char* mapfile){
     1540  map* storage=getMap(output->content,"storage");
     1541  char *tmp=zStrdup(storage->value);
     1542  tmp[strlen(tmp)-strlen(strrchr(tmp,'.'))]=0;
     1543  char* mapName=(char*)malloc((strlen(tmp)+6)*sizeof(char*));
     1544  sprintf(mapName,"%s.maps",tmp);
     1545  FILE* myMaps=fopen(mapName,"a");
     1546  if(myMaps!=NULL){
     1547    fprintf(myMaps,"%s\n",mapfile);
     1548    fclose(myMaps);
     1549  }
     1550  free(mapName);
     1551  free(tmp);
     1552}
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

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