Ignore:
Timestamp:
Feb 1, 2018, 11:27:28 AM (6 years ago)
Author:
djay
Message:

Add the capability to publish heatmap or any templated mapfile using the epecific msInclude and msLayer keys for an output. For MapServer? published output, define 4096 as the default maxsize and use pixel width or height for raster files. use the correct MapServer? imagemode depending on GDALGetRasterDataType (MS_IMAGEMODE_BYTE for GDT_Byte, MS_IMAGEMODE_INT16 for GDT_Int16 and MS_IMAGEMODE_FLOAT32 for GDT_Float32). Create a text file (.maps) listing every mapfiles created for a MapServer? published output (or inputs) using saveMapNames function. Fixes in ulinet, use uuid for naming temporary files. Add dialect input to the ogr2ogr service. Use the .maps file for removing a file from the DeleteData? service

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c

    r860 r862  
    144144 */
    145145void setReferenceUrl(maps* m,maps* tmpI){
     146  int imyIndex=getPublishedId(tmpI);
     147  if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL)
     148    return;
     149  outputMapfile(m,tmpI);
    146150  map *msUrl=getMapFromMaps(m,"main","mapserverAddress");
    147151  if(msUrl==NULL){
     
    150154    exit(-1);
    151155  }
    152   int imyIndex=getPublishedId(tmpI);
    153156  if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL)
    154157    return;
    155   outputMapfile(m,tmpI);
    156158  int finalProto=-1;
    157159  map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion");
     
    165167  map* versionMap=getMapArray(tmpI->content,"msOgcVersion",imyIndex);
    166168  map* datatype=getMapArray(tmpI->content,"geodatatype",imyIndex);
     169  map* layerName=getMapArray(tmpI->content,"msLayer",imyIndex);
    167170  char options[4][5][25]={
    168171    {"WMS","1.3.0","GetMap","layers=%s","wms_extent"},
    169     {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"},
     172    {"WFS","1.0.0","GetFeature","typename=%s","wcs_extent"},
    170173    {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"},
    171     {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}
     174    {"WCS","1.0.0","GetCoverage","coverage=%s","wcs_extent"}
    172175  };
    173   if(datatype==NULL || strncmp(datatype->value,"other",5)==0){
     176  map *nbElements=getMapArray(tmpI->content,"nb_features",imyIndex);
     177  if(nbElements==NULL)
     178    nbElements=getMapArray(tmpI->content,"nb_pixels",imyIndex);
     179  if(datatype==NULL || strncmp(datatype->value,"other",5)==0 || (nbElements!=NULL && atoi(nbElements->value)==0)){
    174180    map* minNb=getMap(tmpI->content,"minoccurs");
    175     if(minNb==NULL || atoi(minNb->value)>=1){
     181    map* useMs=getMap(tmpI->content,"useMapserver");
     182    if((minNb==NULL || atoi(minNb->value)>=1) && useMs!=NULL && strncasecmp(useMs->value,"true",4)==0){
    176183      setMapInMaps(m,"lenv","mapError","true");
    177184      setMapInMaps(m,"lenv","locator",tmpI->name);
    178       setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
     185      if(nbElements==NULL)
     186        setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
     187      else
     188        setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not access any feature or pixel in te resulting file."));
    179189      if(getMapFromMaps(m,"lenv","state")==NULL)
    180190        errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name);
     
    229239  }
    230240  char layers[128];
    231   sprintf(layers,options[proto][3],tmpI->name);
    232 
     241  if(layerName==NULL)
     242    sprintf(layers,options[proto][3],tmpI->name);
     243  else
     244    sprintf(layers,options[proto][3],layerName->value);
     245 
    233246  if(format==NULL || width==NULL || height==NULL || extent==NULL){
    234247    char tmpStr[1024];
     
    525538  int imyIndex=getPublishedId(output);
    526539  msMapSetExtent(m,minX,minY,maxX,maxY);
     540  m->maxsize=4096;
    527541#ifdef DEBUGMS
    528542  fprintf(stderr,"Extent %.15f %.15f %.15f %.15f\n",minX,minY,maxX,maxY);
     
    743757     * Add a new layer set name, data
    744758     */
    745     if(msGrowMapLayers(m)==NULL){
    746       return -1;
    747     }
    748     if(initLayer((m->layers[m->numlayers]), m) == -1){
    749       return -1;
    750     }
    751 
    752     layerObj* myLayer=m->layers[m->numlayers];
     759    layerObj* myLayer=NULL;
     760    if(getMapArray(output->content,"msInclude",imyIndex)==NULL){
     761      if(msGrowMapLayers(m)==NULL){
     762        return -1;
     763      }
     764      if(initLayer((m->layers[m->numlayers]), m) == -1){
     765        return -1;
     766      }
     767      myLayer=m->layers[m->numlayers];
     768    }else{
     769      myLayer=m->layers[m->numlayers-1];
     770    }
     771   
    753772#ifdef DEBUGMS
    754773    dumpMaps(output);
     
    852871    else
    853872      msInsertHashTable(&(myLayer->metadata), "ows_title", "Default Title");
     873
     874    if(getMapArray(output->content,"msInclude",imyIndex)==NULL){
     875      if(msGrowLayerClasses(myLayer) == NULL)
     876        return -1;
     877      if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
     878        return -1;
     879      if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
     880        return -1;
     881      if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
     882        return -1;
     883      /**
     884       * Apply msStyle else fallback to the default style
     885       */
     886      tmpMap=getMap(output->content,"msStyle");
     887      if(tmpMap!=NULL)
     888        msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
     889      else{
     890        /**
     891         * Set style
     892         */
     893        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125;
     894        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125;
     895        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255;
     896        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80;
     897        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
     898        myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
     899       
     900        /**
     901         * Set specific style depending on type
     902         */
     903        if(myLayer->type == MS_LAYER_POLYGON)
     904          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
     905        if(myLayer->type == MS_LAYER_LINE){
     906          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
     907          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5;
     908        }
     909        if(myLayer->type == MS_LAYER_POINT){
     910          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1;
     911          myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
     912        }
     913       
     914      }
     915      myLayer->CLASS[myLayer->numclasses]->numstyles++;
     916      myLayer->numclasses++;
    854917   
    855     if(msGrowLayerClasses(myLayer) == NULL)
    856       return -1;
    857     if(initClass((myLayer->CLASS[myLayer->numclasses])) == -1)
    858       return -1;
    859     if(msGrowClassStyles(myLayer->CLASS[myLayer->numclasses]) == NULL)
    860       return -1;
    861     if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
    862       return -1;
    863     /**
    864      * Apply msStyle else fallback to the default style
    865      */
    866     tmpMap=getMap(output->content,"msStyle");
    867     if(tmpMap!=NULL)
    868       msUpdateStyleFromString(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles],tmpMap->value,0);
    869     else{
    870       /**
    871        * Set style
    872        */
    873       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.red=125;
    874       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.green=125;
    875       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->color.blue=255;
    876       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.red=80;
    877       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
    878       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
    879      
    880       /**
    881        * Set specific style depending on type
    882        */
    883       if(myLayer->type == MS_LAYER_POLYGON)
    884         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
    885       if(myLayer->type == MS_LAYER_LINE){
    886         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->width=3;
    887         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinewidth=1.5;
    888       }
    889       if(myLayer->type == MS_LAYER_POINT){
    890         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->symbol=1;
    891         myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
    892       }
    893      
    894     }
    895     myLayer->CLASS[myLayer->numclasses]->numstyles++;
    896     myLayer->numclasses++;
    897    
    898     m->layerorder[m->numlayers] = m->numlayers;
    899     m->numlayers++;
    900 
    901   }
    902 
     918      m->layerorder[m->numlayers] = m->numlayers;
     919      m->numlayers++;
     920
     921    }
     922  }
    903923  OGR_DS_Destroy(poDS);
    904924  //OGRCleanupAll();
     
    9821002  m->width=GDALGetRasterXSize( hDataset );
    9831003  m->height=GDALGetRasterYSize( hDataset );
     1004  if(m->width>4096 || m->height>4096){
     1005    if(m->width>m->height)
     1006      m->maxsize=m->width;
     1007    else 
     1008      m->maxsize=m->height;
     1009  }else
     1010    m->maxsize=4096;
    9841011  addIntToMapArray(output->content,"nb_pixels",imyIndex,GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset ));
    985  
     1012  int pixel_type=GDALGetRasterDataType( hDataset );
     1013  addIntToMapArray(output->content,"pixel_data_type",imyIndex,pixel_type);
     1014
     1015  int outputIndex=msGetOutputFormatIndex(m,"tiff");
     1016  if(outputIndex>=0){
     1017    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)));
     1018    outputIndex=msGetOutputFormatIndex(m,"geotiff");
     1019    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)));   
     1020  }
     1021  //
     1022   
    9861023  /**
    9871024   * Set projection using Authority Code and Name if available or fallback to
     
    12411278   * Create an empty map, set name, default size and extent
    12421279   */
    1243   mapObj *myMap=msNewMapObj();
     1280  map* mapfileTemplate=getMapArray(outputs->content,"msInclude",imyIndex);
     1281  mapObj *myMap=NULL;
     1282  if(mapfileTemplate==NULL){
     1283    myMap=msNewMapObj();
     1284  }
     1285  else{
     1286    map* dataPath=getMapFromMaps(conf,"main","dataPath");
     1287    map* sid=getMapFromMaps(conf,"lenv","sid");
     1288    char *mapfileTemplatePath=(char*)malloc(((strlen(dataPath->value)+strlen(sid->value)+strlen(outputs->name)+10)*sizeof(char)));
     1289    sprintf(mapfileTemplatePath,"%s/%s_%s.map",dataPath->value,outputs->name,sid->value);
     1290    myMap=msLoadMap(mapfileTemplate->value,mapfileTemplatePath);
     1291    if(myMap==NULL){
     1292      setMapInMaps(conf,"lenv","message",_("Unable to open your template mapfile!"));
     1293      return ;
     1294    }
     1295  }
    12441296  free(myMap->name);
    12451297  myMap->name=zStrdup("ZOO-Project_WXS_Server");
     
    12811333    fprintf(stderr,"Unable to initialize GDAL driver !\n");
    12821334  else{
    1283     o3->imagemode=MS_IMAGEMODE_BYTE;
     1335    o3->imagemode=MS_IMAGEMODE_INT16;
    12841336    o3->inmapfile=MS_TRUE; 
    12851337    msAppendOutputFormat(myMap,msCloneOutputFormat(o3));
     
    12911343    fprintf(stderr,"Unable to initialize GDAL driver !\n");
    12921344  else{
    1293     o4->imagemode=MS_IMAGEMODE_INT16;
     1345    o4->imagemode=MS_IMAGEMODE_BYTE;
    12941346    o4->inmapfile=MS_TRUE; 
    12951347    msAppendOutputFormat(myMap,msCloneOutputFormat(o4));
     
    13101362#endif
    13111363
     1364 
    13121365  outputFormatObj *o6=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","geotiff");
    13131366  if(!o6)
     
    13211374  }
    13221375
     1376 
    13231377  /*
    13241378   * Set default projection to EPSG:4326
     
    14081462  sprintf(mapPath,"%s/%s_%d_%s.map",tmp1->value,outputs->name,imyIndex,sid->value);
    14091463  msSaveMap(myMap,mapPath);
     1464  saveMapNames(conf,outputs,mapPath);
    14101465  free(mapPath);
     1466  //free(myMap->symbolset.filename);
    14111467  //msFreeSymbolSet(&myMap->symbolset);
    14121468  msFreeMap(myMap);
     
    14151471}
    14161472
     1473/**
     1474 * Save the map fullpath in a text file (.maps)
     1475 * @param conf the main configuration map pointer
     1476 * @param output the current output for which a mapfile has been generated
     1477 * @param mapfile the mapfile saved to store in the text file
     1478 */
     1479void saveMapNames(maps* conf,maps* output,char* mapfile){
     1480  map* storage=getMap(output->content,"storage");
     1481  char *tmp=zStrdup(storage->value);
     1482  tmp[strlen(tmp)-strlen(strrchr(tmp,'.'))]=0;
     1483  char* mapName=(char*)malloc((strlen(tmp)+6)*sizeof(char*));
     1484  sprintf(mapName,"%s.maps",tmp);
     1485  FILE* myMaps=fopen(mapName,"a");
     1486  if(myMaps!=NULL){
     1487    fprintf(myMaps,"%s\n",mapfile);
     1488    fclose(myMaps);
     1489  }
     1490}
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