Printer Friendly
One of the very great things about the UMN Mapserver Web system is that it can support numerous kinds of datasources. In this brief excerpt we will provide examples of how to specify the more common data sources used for layers. The examples below are for Mapserver 4.6, but for the most part are applicable to lower versions.
File locations for file based datasources such as ESRI Shape and MapInfo tab files are defined relative to the SHAPEPATH attribute or as absolute paths. For example the beginning declaration of your .map file might look something like the below
MAP
#
# Start of map file
#
NAME MYMAP
EXTENT 732193.725550 2904132.702662 799614.090681 2971466.288170
SIZE 500 500
SHAPEPATH "c:\mydata\"
:
:
ESRI Shapefile
The most common kind of data used in UMN Mapserver is the ESRI shapefile which has a .shp extension. For this kind of datasource you simply specify the location of the file without even specifying the extension. Below is a sample declaration of a polygon layer that uses a shape file
LAYER
NAME buildings
TYPE POLYGON
STATUS DEFAULT
DATA buildings
PROJECTION
"init=epsg:2249"
END
CLASS
OUTLINECOLOR 10 10 10
END
END
MapInfo Tab Files
Many datasources are available to mapserver via the GDAL OGR driver. Map Info is one of those datasources. Below example is what a mapinfo layer definition looks like. Note the tab file specified should be placed in the folder denoted by SHAPEPATH at top of map file
LAYER
NAME buildings
STATUS DEFAULT
MINSCALE 7000
CONNECTIONTYPE OGR
CONNECTION "buildings.tab"
TYPE POLYGON
PROJECTION
"init=epsg:2249"
END
# -- MapInfo has projection information built in the tab file
# -- so you can often auto read this information with the below
#PROJECTION
# AUTO
#END
CLASS
OUTLINECOLOR 10 10 10
END
END
PostGIS Layer
Mapserver has a custom driver for the PostGIS spatial database. In order to use this, your mapserver cgi or mapscript must be compiled with the PostGIS driver. Below is what a postgis mapserver layer looks like.
LAYER
CONNECTIONTYPE postgis
NAME "buildings"
CONNECTION "user=dbuser dbname=mydb host=myserver"
# the_geom column is the name of a spatial geometry field in the table buildings
DATA "the_geom from buildings"
STATUS DEFAULT
TYPE POLYGON
# Note if you use a filter statement - this is basically like a where clause of the sql statement
FILTER "storyhg > 2"
CLASS
OUTLINECOLOR 10 10 10
END
END
More complex PostGIS layer
LAYER
NAME "projects"
CONNECTIONTYPE postgis
CONNECTION "user=myloginuser dbname=mydbname host=mydbhost password=mypass"
DATA "the_geom FROM (SELECT a.projid, a.projname, a.projtype, a.projyear, a.pid, parc.the_geom
FROM projects a INNER JOIN parcels parc ON a.parcel_id = parc.pid
WHERE a.projyear = 2007) as foo USING UNIQUE projid USING SRID=2249"
STATUS OFF
TYPE POLYGON
CLASS
NAME "Business Projects"
EXPRESSION ('[projtype]' = 'Business')
STYLE
OUTLINECOLOR 204 153 51
WIDTH 3
END
END
CLASS
NAME "Community Projects"
EXPRESSION ('[projtype]' = 'Community')
STYLE
OUTLINECOLOR 204 0 0
WIDTH 3
END
END
PROJECTION
"init=epsg:2249"
END
METADATA
"wms_title" "Projects"
"wfs_title" "Projects"
gml_include_items "all"
wms_include_items "all"
END
DUMP TRUE
TOLERANCE 10
END
WMS Layer
Mapserver has the ability to act as a WMS Server as well as a WMS Client. The WMS Client capabilities are accessed by defining WMS layers that connect to WMS servers.
Below is an example of a WMS layer using the Microsoft Terraservices WMS Server.
LAYER
NAME "msterraservicedoq"
TYPE RASTER
STATUS DEFAULT
CONNECTION "http://terraservice.net/ogcmap.ashx?"
CONNECTIONTYPE WMS
MINSCALE 3000
MAXSCALE 20000
#DEBUG ON
METADATA
"wms_srs" "EPSG:26919"
"wms_name" "doq"
"wms_server_version" "1.1.1"
"wms_format" "image/jpeg"
"wms_style" "UTMGrid_Cyan"
"wms_latlonboundingbox" "-71.19 42.23 -71 42.40"
END
END
Post Comments About How to Use different kinds of datasources in UMN Mapserver layers