ZOO-Project
Functions
service_internal_ms.h File Reference
#include <sys/stat.h>
#include "service.h"
#include "cpl_conv.h"
#include "cpl_multiproc.h"
#include "ogr_api.h"
#include "gdal.h"
#include "ogr_srs_api.h"
#include <mapserver.h>

Go to the source code of this file.

Functions

mapgetCorrespondance ()
 Get a list of configuration keys having a corresponding mandatory ows_*. More...
 
void setMapSize (maps *output, double minx, double miny, double maxy, double maxx)
 Add width and height keys to an output maps containing the maximum width and height for displaying the full data extent. More...
 
void setReferenceUrl (maps *m, maps *tmpI)
 Add a Reference key to an output containing the WMFS/WFS/WCS request for accessing service result. More...
 
void setSrsInformations (maps *output, mapObj *m, layerObj *myLayer, char *pszProjection)
 Set projection for a layer in a MAPFILE using Authority Code and Name if available or fallback to proj4 definition if available or fallback to default EPSG:4326. More...
 
void setMsExtent (maps *output, mapObj *m, layerObj *myLayer, double minX, double minY, double maxX, double maxY)
 Set the MAPFILE extent, the the ows_extent for the layer, add wms_extent and wfs_extent to the output maps and call setMapSize. More...
 
int tryOgr (maps *conf, maps *output, mapObj *m)
 Try to open a vector output and define the corresponding layer in the MAPFILE. More...
 
int tryGdal (maps *conf, maps *output, mapObj *m)
 Try to open a raster output and define the corresponding layer in the MAPFILE. More...
 
void outputMapfile (maps *conf, maps *outputs)
 Create a MapFile for WMS, WFS or WCS Service output. More...
 
void saveMapNames (maps *, maps *, char *)
 Save the map fullpath in a text file (.maps) More...
 

Function Documentation

map* getCorrespondance ( )

Get a list of configuration keys having a corresponding mandatory ows_*.

Map composed by a main.cfg maps name as key and the corresponding MapServer Mafile Metadata name to use see doc from here :

Returns
a new map containing a table linking a name of a configuration key to a corresponding mandatory ows_* keyword (ie. "fees" => "ows_fees").
void outputMapfile ( maps conf,
maps outputs 
)

Create a MapFile for WMS, WFS or WCS Service output.

Parameters
confthe conf maps containing the main.cfg settings
outputsa specific output maps

First store the value on disk

Set a ows_rootlayer_title,

Enable all the WXS requests using ows_enable_request see http://mapserver.org/trunk/development/rfc/ms-rfc-67.html

Set metadata extracted from main.cfg file maps

void saveMapNames ( maps conf,
maps output,
char *  mapfile 
)

Save the map fullpath in a text file (.maps)

Parameters
confthe main configuration map pointer
outputthe current output for which a mapfile has been generated
mapfilethe mapfile saved to store in the text file
void setMapSize ( maps output,
double  minx,
double  miny,
double  maxx,
double  maxy 
)

Add width and height keys to an output maps containing the maximum width and height for displaying the full data extent.

Restriction to an image having a size of 640x480 (width * height)

Parameters
output
minxthe lower left x coordinate
minythe lower left y coordinate
maxxthe upper right x coordinate
maxythe upper right y coordinate
void setMsExtent ( maps output,
mapObj *  m,
layerObj *  myLayer,
double  minX,
double  minY,
double  maxX,
double  maxY 
)

Set the MAPFILE extent, the the ows_extent for the layer, add wms_extent and wfs_extent to the output maps and call setMapSize.

Parameters
outputthe specific output
mthe mapObj
myLayerthe layerObj
minXthe lower left x coordinate
minYthe lower left y coordinate
maxXthe upper right x coordinate
maxYthe upper right y coordinate
See also
setMapSize
void setReferenceUrl ( maps m,
maps tmpI 
)

Add a Reference key to an output containing the WMFS/WFS/WCS request for accessing service result.

Parameters
mthe conf maps containing the main.cfg settings
tmpIthe specific output maps to add the Reference key
void setSrsInformations ( maps output,
mapObj *  m,
layerObj *  myLayer,
char *  pszProjection 
)

Set projection for a layer in a MAPFILE using Authority Code and Name if available or fallback to proj4 definition if available or fallback to default EPSG:4326.

Parameters
outputthe output maps
mthe opened mapObj
myLayerthe layerObj
pszProjectiona char* containing the SRS definition in WKT format
int tryGdal ( maps conf,
maps output,
mapObj *  m 
)

Try to open a raster output and define the corresponding layer in the MAPFILE.

Parameters
confthe conf maps containing the main.cfg settings
outputthe specific output maps
mthe mapObj

Try to open the DataSource using GDAL

Add a new layer set name, data

Set Map Size to the raster size

Set projection using Authority Code and Name if available or fallback to proj4 definition if available or fallback to default EPSG:4326

Set extent

Extract information about available bands to set the bandcount and the processing directive

Name available Bands

Loops over metadata information to setup specific information

Classify one band raster pixel value using regular interval

Create a new class

Set class name

Set expression

Set color

int tryOgr ( maps conf,
maps output,
mapObj *  m 
)

Try to open a vector output and define the corresponding layer in the MAPFILE.

Parameters
confthe conf maps containing the main.cfg settings
outputthe specific output maps
mthe mapObj

Try to open the DataSource using OGR

 Try to load the file as ZIP

OGRDataSourceH poDS1 = NULL; OGRSFDriverH poDriver1 = NULL; char *dsName=(char)malloc((8+strlen(pszDataSource)+1)*sizeof(char)); char *odsName=zStrdup(pszDataSource); char *sdsName=zStrdup(pszDataSource); char *demo=".data"; sdsName[strlen(sdsName)-(strlen(demo)-1)]='d'; sdsName[strlen(sdsName)-(strlen(demo)-2)]='i'; sdsName[strlen(sdsName)-(strlen(demo)-3)]='r'; sdsName[strlen(sdsName)-(strlen(demo)-4)]=0;

odsName[strlen(odsName)-(strlen(demo)-1)]='z'; odsName[strlen(odsName)-(strlen(demo)-2)]='i'; odsName[strlen(odsName)-(strlen(demo)-3)]='p'; odsName[strlen(odsName)-(strlen(demo)-4)]=0; sprintf(dsName,"/vsizip/%s",odsName);

#ifdef DEBUGMS fprintf(stderr,"Try loading %s, %s, %s\n",dsName,odsName,dsName); #endif

FILE* file = fopen(pszDataSource, "rb"); FILE* fileZ = fopen(odsName, "wb"); free(odsName); fseek(file, 0, SEEK_END); unsigned long fileLen=ftell(file); fseek(file, 0, SEEK_SET); char *buffer=(char *)malloc(fileLen+1); fread(buffer, fileLen, 1, file); fwrite(buffer,fileLen, 1, fileZ); fclose(file); fclose(fileZ); free(buffer); #ifdef DEBUGMS fprintf(stderr,"Try loading %s",dsName); #endif poDS1 = OGROpen( dsName, FALSE, poDriver1 ); if( poDS1 == NULL ){ fprintf(stderr,"Unable to access the DataSource as ZIP File\n"); setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); fprintf(stderr,"Remove ZIP File!\n"); unlink(odsName); OGR_DS_Destroy(poDS1); }else{ #ifdef DEBUGMS fprintf(stderr,"The DataSource is a ZIP File\n"); #endif char** demo=VSIReadDir(dsName); int i=0; zMkdir(sdsName #ifndef WIN32 ,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH #endif ); while(demo[i]!=NULL){ #ifdef DEBUGMS fprintf(stderr,"ZIP File content : %s\n",demo[i]); #endif char tmpDs=(char)malloc((strlen(dsName)+strlen(demo[i])+2)*sizeof(char)); sprintf(tmpDs,"%s/%s",dsName,demo[i]); fprintf(stderr,"read : %s\n",tmpDs);

VSILFILE* vsif=VSIFOpenL(tmpDs,"rb"); #ifdef DEBUGMS fprintf(stderr,"open : %s\n",tmpDs); #endif VSIFSeekL(vsif,0,SEEK_END); vsi_l_offset size=VSIFTellL(vsif); #ifdef DEBUGMS fprintf(stderr,"size : %d\n",size); #endif VSIFSeekL(vsif,0,SEEK_SET); char vsifcontent=(char) malloc(((int)size+1)*sizeof(char)); VSIFReadL(vsifcontent,1,(size_t)size,vsif); char fpath=(char) malloc((strlen(sdsName)+strlen(demo[1])+2)*sizeof(char)); sprintf(fpath,"%s/%s",sdsName,demo[i]); int f=zOpen(fpath,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); zWrite(f,vsifcontent,(int)size); close(f); chmod(fpath,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH); char* tmpP=strstr(fpath,".shp"); if(tmpP==NULL) tmpP=strstr(fpath,".SHP"); if(tmpP!=NULL){ #ifdef DEBUGMS fprintf(stderr,"*** DEBUG %s\n",strstr(tmpP,".")); #endif if( strcmp(tmpP,".shp")==0 || strcmp(tmpP,".SHP")==0 ){ tmpMap=getMap(output->content,"storage"); free(tmpMap->value); tmpMap->value=(char*) malloc((strlen(fpath)+1)*sizeof(char)); sprintf(tmpMap->value,"%s",fpath); pszDataSource=tmpMap->value; #ifdef DEBUGMS fprintf(stderr,"*** DEBUG %s\n",pszDataSource); #endif } } VSIFCloseL(vsif); i++; } OGR_DS_Destroy(poDS1); } free(sdsName); free(dsName);

Add a new layer set name, data

Detect the Geometry Type or use Polygon

Detect spatial reference or use WGS84

Detect the FID column or use the first attribute field as FID

Apply msStyle else fallback to the default style

Set style

Set specific style depending on type