MapServer之MapFile学习

MapServer之MapFile学习

##参考教程

教程 http://mapserver.org/tutorial/index.html

教程资料,含数据 http://download.osgeo.org/mapserver/docs/mapserver-tutorial.zip

MapFile Editors

https://github.com/mapserver/mapserver/wiki/MapFile-Editors

##MapServer访问地址解析

http://localhost/cgi-bin/mapserv?map=/ms4w/apps/tutorial/htdocs/example1-1.map&layer=states&mode=map ,分为两个部分:

  • http://localhost/cgi-bin/mapserv?(windows下位 mapserv.exe)

    调用 MapServer CGI 程序。直接访问出现信息

    No query information to decode. QUERY_STRING is set, but empty.

  • 查询字符串,包含CGI参数,以&隔开

    • 参数 map,值/ms4w/apps/tutorial/htdocs/example1-1.map,指定 MapServer CGI程序需要处理的 mapfile 文件
    • layer=states,指定 mapserv 程序启用 states图层
    • mode=map ,指定 mapserv 对 mapfile 输出的处理方式。
      • map 方式:直接发送图片到浏览器,而不在服务器中创建临时的图片
      • browser方式:在服务器中创建一个图片的临时目录

http://live.osgeo.org/zh/quickstart/mapserver_quickstart.html

MapServer 之 mapfile 配置文件

https://doc.tiki.org/Maps+Mapfile+Tutorial

MapServer官方文档 http://mapserver.org/mapfile/index.html

[TOC]

MapFile简介

MapFile 是 MapServer 的核心。它定义了对象间的关系,指出MapServer中的数据位置,并定义了数据如何显示。即 Mapfile 用于控制对数据的栅格或矢量输出,其中包含了数据源和渲染样式(颜色、符号、标准等)信息。

QGIS中有一个 MapServer Export Plugin,可以在QGIS中配置好数据和样式之后,导出mapfile。

MapFile中的每个对象以其名称开始,以END结束(对象必须闭合)。MapFile中标签不区分大小写,但最好是大写。MapFile 中的注释使用 #(hash)。MapFile文件包含一个Map对象,其以“Map”开始,包含一系列的LAYER对象。在有多个 LAYER对象的时候,在前面的 LAYER会先绘制,后面的 LAYER会叠加在先绘制的图层上面。

——每个MapFile文件都必须以Map开始,以END结束。

MAP
...
LAYER
...
END # end of layer1
END # end of map

每个对象都有很多的配置参数,配置参数不必闭合。参数值为字符串时,最好加双引号

Mapfile 使用 UTF-8 编码保存,后缀为map .

mapfile应用过程示意图

mapfile应用过程示意图,出自【MapServer 之 mapfile 配置文件】

MapFile的头部

mapfile 的头部(header)定义了一些控制地图在屏幕上显示效果的对象。包括MAP本身(最后需要END),决定如何创建网络地图图片的WEB对象、参考图或鹰眼图对象REFERENCE、比例尺对象SCALEBAR、图例对象LEGEND及控制地图是否能够查询的对象QUERYMAP

# Start of map file
MAP
NAME "Efate"
STATUS ON
SIZE 400 400
EXTENT 196900 8027100 245000 8073000
UNITS METERS
SHAPEPATH "/var/www/html/map/"
IMAGETYPE png24
FONTSET "fonts/fontset.txt"
OUTPUTFORMAT
NAME png24
DRIVER "GD/PNG"
MIMETYPE "image/png"
IMAGEMODE RGB
EXTENSION "png"
END
# Start of web interface definition
WEB
TEMPLATE /var/www/html/map/map.html
IMAGEPATH /var/www/html/map/images/
IMAGEURL /map/images/
LOG /var/www/html/map/maplog
END
# Start of reference map 定义参考图(鹰眼图)
REFERENCE
IMAGE /var/www/html/map/data/efate.png
EXTENT 196900 8027100 245000 8073000
STATUS ON
COLOR -1 -1 -1
OUTLINECOLOR 255 0 0
SIZE 95 95
END
# Start of legend 图例
LEGEND
KEYSIZE 18 12
LABEL
TYPE BITMAP
SIZE MEDIUM
COLOR 0 0 89
END
STATUS ON
END
# Start of scalebar 比例尺
SCALEBAR
IMAGECOLOR 255 255 255
LABEL
COLOR 0 0 0
SIZE SMALL
END
SIZE 350 5
COLOR 255 255 255
BACKGROUNDCOLOR 0 0 0
OUTLINECOLOR 0 0 0
UNITS kilometers
INTERVALS 5
STATUS ON
END
# Start of query definitions 查询定义
QUERYMAP
STATUS ON
STYLE HILITE
END
4#...
4
END # end of MAP

Tip: 一个快速使用 mapfile 的方法是直接应用上述内容,将 REFERENCE 部分中的图片指向真实内容. 这样就得到一个没有图层的mapfile文件。然后你可以往里面添加内容 ,根据你的需要进行修改.
mapfile中下述内容的值必须准确设置才能工作:

SHAPEPATH、IMAGEPATH、IMAGEURL、IMAGE

对象属性

MAP对象

http://mapserver.org/mapfile/map.html

MAP对象的主要属性(MAP对象内部的LAYER对象等下文说明):

MAP
4NAME "Efate" # map 文件名称
4STATUS ON # is this map on by default
4SIZE 400 400 # 影像地图的像素大小 size in pixel of the image map
4EXTENT 196900 8027100 245000 8073000 # 地图的地理范围 geographic extents of the map
4UNITS METERS # 地理范围的单位 units for the geographic extents
4# shapefile文件在服务器上的存储地址,同时作为参考目录使用 also used for directory reference
SHAPEPATH "/var/www/html/map/"
4# 输出影像的类型 24bits color PNG。PNG8 渲染速度比较快
IMAGETYPE png24
# 包含字体位置的文件 file containing the locations of fonts
4FONTSET "fonts/fontset.txt"
...
END
  • NAME map相关的前缀,使用它来生成 scalebar 和 legend 的GIF 文件. 应该保持简短.
  • SIZE [x][y] 输出影像(即地图)的像素的大小.
  • EXTENT<Lower Left X> <Lower Left Y> <Upper Right X> <Upper Right Y>:默认的地理坐标范围。可以使用orginfo获得矢量数据的四至,如ogrinfo -al -so states_ugl.shp
  • SHAPEPATH:文件目录(针对 shp 、tiff 等文件,非数据库或网络服务)。绝对路径 (如 /ms4w/apps/tutorial/dataC:/ms4w/apps/tutorial/data) 或者相对 mapfile位置的路径 (如 ”../data”).
  • WEB 对象,配置 MapServer 临时放置生成的地图图片的地址;
  • UNITS: 地图坐标单位,用于比例尺 [dd|feet|inches|kilometers|meters|miles|nauticalmiles]
  • IMAGECOLOR[r][g][b] ,设置地图的背景色,RGB;
  • PROJECTION,地图使用的投影坐标系;
  • SYMBOLSET ,指向符号定义文件,用于CLASS对象中的SYMBOL参数 Cartographic Symbol Reference

WEB对象

此对象内容定义了信息在服务器上存储的位置及其如何向浏览器提供服务

WEB
# location of the template for results
4# the line needs to be here, but it is not used (no file at this location)
TEMPLATE /var/www/html/map/map.html
# 存放地图图片的位置,必须以“/”结尾
IMAGEPATH /var/www/html/map/images/
4# web path for the maps images
IMAGEURL /map/images/
# 日志文件地址
LOG /var/www/html/map/maplog
END
  • IAMGEPATH,存放生成的地图的图片和临时文件的路径;
  • IMAGEURL,IMAGEPATH的基路径
  • METADATA,配置元数据,主要用来支持 OGC 的服务;

Projection

http://mapserver.org/tutorial/example1-6.html

若定义了 PROJECTION 对象,则 MapServer 会将图层和投影信息传递给PROJ.4 库来进行重投影.

PROJECTION
# 采用的一种 PROJ.4 定义 of Lambert Azimuthal Equal-Area projection
"proj=laea"
"ellps=clrk66"
"lat_0=45"
"lon_0=-100"
END

MapServer有两种定义投影的方式。

第一种如上例中,为传统的方式。

第二种是采用EPSG码,如

PROJECTION
4"init=epsg:2163"
END

map文件中定义的extent 的单位,必须和输出的投影的单位一致。因此,若之前采用的经纬度,则定义投影之后,需要修改extent的值。

可以使用 PROJ.4的 cs2cs命令来计算投影后地图的范围。

cs2cs +proj=latlong +datum=WGS84 +to +proj=laea +ellps=clrk66 +lat_0=45 +lon_0=-100
# 输入southwestern (lower left 左下角)的坐标
-97.5 41.619778 # 空格分隔
208398.01 -372335.44 0.000 # 输出的目标坐标值。第三个为高程值,此处可以忽略
# northeastern coordinate pair (upper right 右上角坐标)
-82.122902 49.38562
1285308.08 632638.93 0.000 # 输出的目标坐标值
# 由于投影分带的问题,这里的坐标与实际中使用的坐标不一样

在 MAP 对象头部中定义 PROJECTION 作为输出投影之后,需要在 LAYER 对象 中定义PROJECTION作为输入投影

LAYER对象

所有文件的位置必须是相对于SHAPEPATH所设置的路径 。若有文件为/var/www/html/map/data/mylayer.shp ,而 SHAPEPATH 的值为/var/www/html/map/,则文件位置必须设置为data/mylayer.shp. 采用这种规则能便于在使用Maps->Layer Management上传文件时定位到文件地址。
文件名都是大小写敏感的(包括扩展名),并应该绝对禁止包含空格!A shapefile is usually made of a shp, idx, dbf files while a Mapinfo layer is made of TAB, ID, MAP, DAT (and sometimes IND) files.

LAYER 表示图层数据源及其显示属性。在 LAYER 中存在一系列的属性,例如:

  • STATUS:图层允许显示(ON)、不显示(OFF)或强制显示(DEFAULT)
  • TYPE:渲染对象的几何类型,如 POLYGON 、LINE 、 POINT 、RASTER、ANNOTATION
  • DATA:所使用的源文件名称,如 shp 文件,或者 SQL 查询语句。支持的格式同 OGR。
  • CLASS:渲染样式控制
  • PROJECTION,字符串,图层数据所在的坐标系;
  • METADATA,要配置的服务的配置对象;
  • CONNECTIONTYPE,连接的类型,默认是本地,也就是本地磁盘文件;
  • CONNECTION,连接数据库的字符串,或者WMS等的URL,在图层数据在数据库中时候才会使用;在map文件中,必须单独成行(the string has to be in a single line in mapfile )

Vector layer

Shapefile
LAYER
NAME "My Layer"
TYPE LINE
STATUS ON
DATA "data/myshapefile.shp"
CLASS
COLOR 255 0 0
NAME "My layer legend"
END # end of class
END # end of layer

“My layer legend” in the LEGEND.

Mapinfo TAB

The difference with a shapefile is the use of the OGR library to read the Mapinfo files. The keyword CONNECTIONTYPE OGR must be used and the location of the file is given by the keyword CONNECTION instead of DATA. All the rest stay the same.

LAYER
NAME "My Layer"
TYPE LINE
STATUS ON
CONNECTIONTYPE OGR
CONNECTION "data/mymapinfofile.TAB"
CLASS
COLOR 255 0 0
NAME "My layer legend"
END # end of class
END # end of layer

Query

To make the layer queryable add anywehere inside the LAYER object the following lines:

TEMPLATE "query.html"
TOLERANCE 3
TOLERANCEUNITS PIXELS

第一个参数是必须的,但是并不一定需要指向一个真实的文件( does not need to pint to a real file). It is only used outsied tikimaps. The second parameters specify the pointing TOLERANCE in TOLERANCEUNITS, here 3 pixels. If you click on the map all the objects from this layer which are at less than 3 pixels from the click on the image will be selected.
The map is then redraw and at the bottom of the page will be the information related from the object.
Note: if you create a GIS layer which fields contain HTML tags, like for IMG or A (anchor/link), they will be rendered accordingly. This allows you to create a layer pointing to images stored on Tiki.

###STYLE

COLOR

多边形的填充色、线的颜色. RGB 格式.

OUTLINECOLOR

多边形边线的颜色. RGB 格式. MapServer 默认不绘制多边形的边线,需要设置此属性的值才能看到.

###Label

http://mapserver.org/tutorial/example1-4.html

从图层的属性中选择一个字段用于在地图上显示。例如,若有一个GIS图层包含国家的名称,对应的字段为 “NAME”,则可以使用LABELITEM "NAME"来告诉 mapserver 将其值显示在地图上.
在 CLASS 对象里面, 应当设置这些标注如何渲染.

LAYER
NAME "Country Names"
TYPE POINT
STATUS ON
METADATA
DOWNLOAD "T"
END
LABELITEM "NAME"
LABELCACHE ON
CONNECTIONTYPE OGR
CONNECTION "data/Country.TAB"
CLASS
SYMBOL 0
COLOR 0 0 0
NAME "Country Names"
LABEL
COLOR 0 0 0
FONT arial
TYPE TRUETYPE # 字体的类型 TRUETYPE、BITMAP
POSITION CC # C for center, U for upper, and L for lower,或使用 auto
PARTIALS TRUE
ANTIALIAS TRUE # 是否启用Truetype字体的抗锯齿效果
MINDISTANCE 300 # 相同标注之间的最小距离。设置的比较大能够避免过于拥挤
SIZE 7
BUFFER 1 # padding
OUTLINECOLOR 255 255 255
END
END
END

上例中, LABEL 为黑色 (COLOR 0 0 0) 并使用 TRUETYPE 字体 arial . 标注的 POSITION 为相对于POINT 对象的 Center/Center . 若一个对象并不完全在地图上,其标注也会显示出来 (PARTIAL TRUE). 标注的 SIZE 为7 points. 标注之间的距离不会小于 1 个像素 (BUFFER 1). 为了让最后一个参数能够正常作用,应该启用 LABELCACHE. 最后,标注对象有一个白色的边界 (OUTLINECOLOR 255 255 255).

还可以设置

  • MINFEATURESIZE 显示标签所需的最小目标要素的面积像素值。
  • MINSIZE 标签大小的最小像素值

###Thematic Mapping

每个 layer 包括一个或多个 CLASS. CLASS 定义了如何在屏幕上绘制每个对象。 通过使用 CLASSITEM, 你可以使用一个字段来将同一类的不同对象区分开。例如,所有深度为 -100m 到 -500m的等深线属于一类,而-500m 到-1000m 的等深线属于另一类. 这种划分在CLASS里面是通过使用 EXPRESSION 实现的. EXPRESSION 使用基于CLASSITEM中字段的简单逻辑实现。
例如,使用表示 LINE 对象水深值的字段”value”,根据深度值的不同显示不同的颜色。若 EXPRESSION 为 true ,则 CLASS 中的参数会被应用. 一个没有EXPRESSION 的 CLASS 将被作为未被划分的对象的默认CLASS .

通过ogrinfo,或者其他程序查看shapefile文件中的 dbf 文件,可以确定 数据中包含的属性,用来定义 CLASSITEM。

LAYER
NAME "Bathymetry 20m"
TYPE LINE
STATUS OFF
METADATA
WIKI "FijiBathymetry"
END
TEMPLATE "query.html"
TOLERANCE 3
TOLERANCEUNITS PIXELS
LABELITEM "Value"
CLASSITEM "Value"
LABELCACHE ON
CONNECTIONTYPE OGR
CONNECTION "data/fiji/viti_bathy_contour.TAB"
CLASS
SYMBOL 0
COLOR 0 200 255
NAME "Bathymetry 2.5m >-50m"
expression ([Value]>-50)
LABEL
ANGLE AUTO
COLOR 0 0 0
FONT arial
TYPE TRUETYPE
POSITION cc
PARTIALS FALSE
BUFFER 5
SIZE 6
OUTLINECOLOR 200 200 200
END
END
CLASS
SYMBOL 0
COLOR 0 100 255
NAME "Bathymetry 20m >-500m"
expression ([Value]<-50 AND [Value]>=-500)
LABEL
ANGLE AUTO
FONT arial
COLOR 0 0 0
TYPE TRUETYPE
POSITION cc
PARTIALS FALSE
BUFFER 5
SIZE 6
OUTLINECOLOR 200 200 200
END
END
END
MAP
IMAGETYPE PNG
EXTENT -97.238976 41.619778 -82.122902 49.385620
SIZE 400 300
SHAPEPATH "../data"
IMAGECOLOR 255 255 255
LAYER
NAME states_poly
DATA states_ugl
STATUS OFF
TYPE POLYGON
CLASSITEM "CLASS"
CLASS
NAME 'States'
EXPRESSION 'land' # Only polygons where "CLASS" = 'land' will be drawn.
STYLE
COLOR 232 232 232
END
END
CLASS
NAME 'Water'
EXPRESSION 'water' # Only polygons where "CLASS" = 'water' will be drawn.
STYLE
COLOR 198 198 255
END
END
END
END

Metadata

在一个 LAYER 组内,可以定义一个(且仅有一个) METADATA 组. 部分 metadata 在tikiwiki中有特殊用途.

WIKI

实验WIKI 根据图层名生成一个链接到wiki页面的链接。 使用wiki页来说明图层信息:
custodian、所有者、创建日期、精度、历史、基准/投影、interesting layer features…

METADATA
WIKI "MyLayerPage"
END

###Raster layer

http://mapserver.org/tutorial/example1-5.html

最简单的处理栅格图层的方式是使用包含投影信息的 Geotiff 图像. 但是生成 geotiff 图像可能需要其他遥感软件. 另一种方式是使用一个额外的包含图像像素坐标信息的文件。
当使用多个图像,而不是每个图像作为一个图层时,这些图像会被平铺(tiled). 将为每个图像生成一个 包含矩形的shapefile 来帮助系统准确定位图像.

Geotiff

设置 TYPE 为 RASTER, 并设置 DATA 指向 tiff 文件即可. 关键词 OFFSITE 用于指定tiff图像中透明部分的颜色. 这在拼接(tiling )或叠加(overlapping )多个影像时很有用。

LAYER
NAME "DTM 50m"
TYPE RASTER
STATUS OFF
DATA "data/fiji/VLevudtm.tif"
OFFSITE 0 0 0
PROCESSING "BANDS=1,2,3" # 此处选择多光谱影像中需要显示的波段
END

PROCESSING 指定处理指令,参考 http://mapserver.org/mapfile/layer.html#layer

Image Tiles

Images tiles are created using utility tools from the mapserver software. The utility is called gdaltindex and parses mainly geotiff images to get their boundaries and create a shapefile containing an outline for each of the images. Under Maps->Layer Management, at the bottom of the page a utility is avalilable to generate the shapefile. Basically upload the images to the right directory. The images should have the same name prefix. Then reference all these images with a wildcaard and name the shapefile to be created. For instance you can upload coralcoastsigatoka.tif, coralcoastmomi.tif, coralcoastnavua.tif and reference them as coralcoast*.tif and create the shapefile img_index.shp

LAYER
NAME "Coral Coast 4m IKONOS"
TYPE RASTER
METADATA
WIKI "FijiImagery"
END
STATUS ON
TILEINDEX "data/fiji/img_index.shp"
TILEITEM "Location"
OFFSITE 0 0 0
END

Grid Layer

A grid layer allows you to draw a grid in the local cordinates on your map. It is useful to find location of objects on the map. For best effect the grid must be the last layer in the mapfile to be drawn the last.

LAYER
NAME "Grid"
TYPE LINE
STATUS OFF
CLASS
COLOR 0 0 0
LABEL
FONT arial # must be in your FONTSET
TYPE TRUETYPE
SIZE 8
COLOR 0 0 0
OUTLINECOLOR 255 255 255
END
END
GRID
MINARCS 2
MAXARCS 6
END
END

WMS图层

LAYER
NAME modis_jpl
TYPE RASTER
OFFSITE 0 0 0
STATUS OFF
CONNECTIONTYPE WMS
CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?"
METADATA
"wms_srs" "EPSG:4326"
"wms_name" "modis"
"wms_server_version" "1.1.1"
"wms_format" "image/jpeg"
END
PROJECTION
"init=epsg:4326"
END
END

DOWNLOAD

若 DOWNLOAD 被设置为 “T”,那么组成此图层的文件将可以被注册用户下载 .

METADATA
DOWNLOAD "T"
END

The system selects all the files with the same base name as defined in the LAYER DATA or CONNECTION clause but with different extension. However if one of these files has the extension NDL, the download is disabled. This allows to upload GIS data that can only be viewable.

Reference对象(鹰眼)

这部分内容定义了如何显示一个概略图(鹰眼图). 可以用一个图片来表示感兴趣的区域,并指定边界的坐标. 系统将会基于当前的视图,在图片上绘制一个矩形来标识视图的边界。

REFERENCE
IMAGE /var/www/html/map/data/efate.png # location of the image
EXTENT 196900 8027100 245000 8073000 # extent of the image
STATUS ON # the overview is on by default
COLOR -1 -1 -1 # 透明背景
OUTLINECOLOR 255 0 0 # 边线的颜色
SIZE 95 95 # 图像大小,像素
END

The tip to create an image for overview, is to not worry about the image at the begining. Any image will do. When the layers are implemented in the mapfile and the main view sounds pretty enough, then select a default view, click Redraw if neccessary to get the minx, maxx, miny, maxy parameters in the URL, (if necessary adjust them manualy). Save the current map as an image onto your local machine, use an image editing software to resize the image to the size you want to use in the overview (here 95x95 pixel). Upload the image using the maps->layer manager and update the IMAGE link in the REFERENCE group to point to this new image. Finish by entering the correct EXTENTS that corresponds to the minx,miny,maxx,maxy of the map you used to create the overview.

Legend

The legend is linked to each LAYER by the way each object type is represented (POINT, LINE, POLYGON,…) and its COLOR and OUTLINECOLOR and by the NAME used in the CLASS group. It is important to have a meaningful NAME for each CLASS group in every LAYER group. The NAME of the CLASS can be different from the NAME of the layer as a LAYER can have several CLASSes.

LEGEND
# the size of the object representing the geographical object
KEYSIZE 18 12
LABEL
# Font type for the legend name of each geographical object
TYPE BITMAP
4# font size
SIZE MEDIUM
4# font color
COLOR 0 0 89
END
# legend is on by default
STATUS ON
END

Scalebar

显示比例尺以获取距离信息.

SCALEBAR
IMAGECOLOR 255 255 255 # 比例尺占位图片的背景色 background color of the image placeholder
LABEL
COLOR 0 0 0 # 表示距离的标签的文字颜色 color of the labels indicating the distance
SIZE SMALL # 标签大小
END
SIZE 350 5 # 比例尺的像素大小
COLOR 255 255 255 # 比例尺颜色
BACKGROUNDCOLOR 0 0 0 # 比例尺的背景色
OUTLINECOLOR 0 0 0 # 比例尺外边界颜色
UNITS kilometers # 比例尺单位
INTERVALS 5 # 比例尺中总的间隔数 How many intervals in total in the scalebar
STATUS ON # 默认启用
END

QUERYMAP

此部分内容用于设置地图为 可查询的,以及查询的结果如何显示。即使现在没有可查询的LAYER,也建议包含此部分内容,因为迟早会有这样的需求。

QUERYMAP
STATUS ON # 地图默认可查询
STYLE HILITE # 高亮显示选中对象
END

OUTPUTFORMAT

一个map文件可有一个或多个OUTPUTFORMAT 对象,用于定义可用的输出格式,如 PNG, GIF, JPEG, GeoTIFF, SVG, PDF 和 KML 等. pdf 和 svg 依赖 cairo

OUTPUTFORMAT
NAME "png"
DRIVER AGG/PNG
MIMETYPE "image/png"
IMAGEMODE RGB # [PC256|RGB|RGBA|INT16|FLOAT32|FEATURE]
EXTENSION "png"
FORMATOPTION "GAMMA=0.75"
END

driver: AGG/PNG 、 AGG/PNG8、AGG/JPEG、 OGR/Mapinfo File、CAIRO/SVG、CAIRO/PDF、CAIRO/PNG、GDAL/GTiff 、KML, KMZ 和 UTFGRID

FORMATOPTION :Provides a driver or format specific option. 在一个 OUTPUTFORMAT 中可以有一个或多个 FORMATOPTION 声明 (optional)

带注释示例

Editing the mapfile for a MapServer-based webGIS

# ethex.map (with full comments)
# 此处为 Map 对象定义起始
# First piece of information is about general characteristics of the map we want
# to create.
# It starts with the MAP keyword and finishes with the END keyword.
MAP
4# 地图的名称
4NAME "ethex"
4# 地图的地理范围: it is the first extension the webGIS will display
4EXTENT 1486000 5056000 1525000 5088000
4# 分辨率 (pixels) of the window where the map will be drawn in
4SIZE 500 400
4# 数据源路径
4# (NOTE! here the path is from the mapfile 此处路径从 mapfile 位置开始算)
4SHAPEPATH "data/shpf"
4# 图形符号定义文件路径
4# (NOTE! 此处路径从 mapfile 位置开始算)
4SYMBOLSET "graphics/symbols/Symbols.sym"
4# 包含 TrueType 字体定义的文件路径
4# (NOTE! here the path is from the mapfile)
4FONTSET "graphics/fonts/fontset.txt"
4# 地图图片背景色
4# (R G B colour model)
4IMAGECOLOR 175 175 175
4# 单位 Geographic units
4UNITS meters
4#...........................................................................
4 # Web 对象定义.
4 # It defines how the interface (template file) has to operate.
4 # 以 WEB 关键字开始以 END 关键字结束.
4 # Web 对象包含在 Map 对象里面 ( Map 对象的子对象)
4
4 WEB
4 # Path of the folder where MapServer writes temporary files
4 # (NOTE! here the path is absolute)
4 IMAGEPATH "/usr/local/mapserver_tmp/"
4 # Web path of the folder where MapServer writes temporary files
4 # (NOTE! here the path is from the web root (E.g. from htdocs for
4 # Apache web servers))
4 IMAGEURL "/tmp/"
4 # 主模板文件名称 Name of the main template file
4 TEMPLATE "ethex.html"
4 END
4 # Projection (投影)对象定义.
4 # 此处定义了地图的全局投影系统( global CRS(Coordinate Reference System))
4 PROJECTION
4 # 地图 CRS 的 EPSG 代码
4 "init=epsg:3003"
4 END
4#...........................................................................
4 # Reference 对象.
4 # 定义参考地图 reference map (鹰眼地图 overview map).
4 REFERENCE
4 # 状态 (值: ON 或 OFF)
4 STATUS on
4 # 参考图图片文件路径
4 # (NOTE! path is from the mapfile)
4 IMAGE "graphics/refmap/refmap.png"
4
4 # 窗口屏幕分辨率 (pixels) reference map
4 SIZE 183 150
4
4 # 参考图地理范围
4 EXTENT 1486000 5056000 1525000 5088000
4
4 # 表示主图显示范围的鹰眼图上方框填充颜色
4 # (值 -1 -1 -1 表示透明色)
4 COLOR -1 -1 -1
4
4 # 方框线的颜色
4 OUTLINECOLOR 255 0 0
4 END
4#...........................................................................
4 # Querymap 对象.
4 # 定义了 query map (显示查询结果的地图 map drawn to display query results).
4 QUERYMAP
4 # (值: ON or OFF)
4 STATUS on
4
4 # 用于高亮显示查询结果颜色的颜色
# Colour used to highlight queried features (默认: yellow)
4 COLOR 255 0 0
4
4 # STYLE 如何高亮(下划线)显示结果要素的样式
4 # hilite: 以COLOR定义的颜色为下划线显示结果要素 underlined ; 其他正常显示
4 # normal: 正常显示,与未查询的要素一样
4 # selected: 查到的要素正常显示,其他要素不显示
4 STYLE hilite
4 END
4#...........................................................................
4 # Legend 图例对象.
4 # static legend.
4 LEGEND
4 # ON or OFF
4 STATUS on
4 # 图例背景色
4 IMAGECOLOR 255 255 255
4 # 图例符号Dimensions of the legend symbols (in pixels) 默认= 20 x 10
4 KEYSIZE 18 12
4 # Here starts the definition of the Label Object. The Label Object defines the
4 # characteristics of the legend symbols.
4 LABEL
4 # Here there is the definition of the font to be used; Generally bitmap fonts
4 # are faster to be drawn than TrueType fonts. But TrueType fonts are scalable
4 # and available in a variety of faces.
4 # When truetype is selected the FONT parameter must be also defined.
4 TYPE truetype
4 FONT "courier"
4 # 文本大小.
4 # It has to be defined has: [integer] for truetype type
4 # [tiny|small|medium|large|giant] for bitmap type.
4 SIZE 10
4 # As an alternative
4 # TYPE bitmap
4 # SIZE small (o giant o medium)
4 # Here we define the color used
4 COLOR 0 0 130
4 END
4 END
4#...........................................................................
4 # 比例尺对象 Scalebar Object.
4 SCALEBAR
44# Status of the scalebar (values: ON or OFF)
44STATUS on
44# Color to be used for odd intervals
44COLOR 0 0 0
44#Color to be used for outlining individual intervals
44OUTLINECOLOR 50 50 50
44# Color to be used for even intervals
44BACKGROUNDCOLOR 255 255 224
44# Background color for the scalebar
44IMAGECOLOR 215 215 200
44# Output scale bar units ([feet|inches|kilometers|meters|miles)
44UNITS kilometers
44# Number of intervals of the scalebar(integer)
44INTERVALS 4
44# Scalebar image size(in pixel)
44SIZE 200 2
44# Scalebar style: (available values: 0,1)
44STYLE 0
44# Here starts the definition of the Label Object. The Label Object defines the
44# characteristics of the scalebar symbols.
44LABEL
444TYPE bitmap
444SIZE small
444COLOR 50 50 50
44END
44# As an alternative:
44# LABEL
444# TYPE BITMAP
444# SIZE tiny
444# COLOR 255 0 0
44# END
4 END
4
4#...........................................................................
4 # Layer Object. The Layer Object determines the make-up of
4 # a specific cartographic layer in the map. Layers are drawn in their order of
4 # appearance in the MapFile (显示时,第一个图层在最下面,最后的图层在最上面).
4 # 每个 mapfile 最多 50 个图层.
4 # This can be changed by editing the map.h file to change the value of
4 # MS_MAXLAYERS to the desired number and recompiling Mapserver.
4 # 1st LAYER: our first layer corresponds to a shapefile layer.
4LAYER
4 # 图层名称: it is the link between the MapFile and web interfaces that refer
4 # to this name (max=20 characters)
4 NAME "municipalities"
4
4 # 图层状态 (values: DEFAULT = always displayed, ON = displayed on demand or
4 # OFF = not displayed)
4 STATUS default
4
4 # Path and filename of the shapefile to process (without extension).
4 # It has to be specified relatively to the SHAPEPATH option of the Map Object.
4 DATA "municipalities"
4 # 数据类型: point/line/polygon/raster
4 TYPE polygon
4 # Item name in the attribute table to be used for labeling.
4 LABELITEM "NAME"
4 # Item name in the attribute table to be used for defining different thematic
4 # classes.
4 CLASSITEM "DISTRICT"
44
4 # Maximum scale at which the layer is labeled (double).
4 LABELMAXSCALE 100000
4 # Templates to be used to publish a set of results (multiresult query modes)
4 HEADER "header.html"
4 FOOTER "footer.html"
4 TEMPLATE "query.html"
4 # Metadata definition needed for attribute queries (MapServer version 5+)
4 METADATA
4 qstring_validation_pattern '.'
4 END
4
4 # Here starts the first Class Object. It defines the thematic classes of the
4 # layer.
4 # Each layer must have at least one class.
4 # If more than one class has to be defined, membership is determined using
4 # attribute values and expressions.
4 # It starts with the keyword CLASS and terminates with the keyword END.
4 CLASS
4 # Name to be used in the legend for the specific class. If it has not been
4 # defined, in the legend this class doesn't appear.
4 NAME "Como district"
4 # Value of the attribute item defined in CLASSITEM
4 EXPRESSION "Como"
4 # Label to be used
4 LABEL
4 TYPE TRUETYPE
4 FONT "times"
4 SIZE 8
4 # Label positioning; available values: auto, ul|uc|ur|cl|cc|cr|ll|lc|lr; in
4 # this latter case first letter refers to
4 # Y coordinate (u= up, c= center, l= low), the second to X coordinate(l=
4 # left, c= center, r= right.
4 # By selecting the value "auto" MapServer is requested to calculate a
4 # label position that will not interfere with other labels.
4 POSITION auto
4 # Label color
4 COLOR 155 155 155
4 END
4 # Style to be used for the feautures of the layer.
4 STYLE
4 # Color to be used for drawing features.
4 COLOR 0 0 255
4 # Color to be used for outlining polygons.
4 OUTLINECOLOR 0 255 0
4 END
4 END
4 # See previous class for comments
44CLASS
444NAME "Varese district"
444EXPRESSION "Varese"
444LABEL
4444TYPE TRUETYPE
4444FONT "times"
4444SIZE 8
4444POSITION AUTO
4444COLOR 155 155 155
444END
444STYLE
4444COLOR 110 210 55
4444OUTLINECOLOR 225 0 0
444END
44END
4END
4#...........................................................................
4#...........................................................................
4 # 3rd LAYER: it is a raster layer (see 2nd layer)
4LAYER
44NAME "NEraster"
# Name of the group that the layer belongs to.
44# The group allows to do things like turning on and off a group of layers at
44# once.
44#GROUP "raster4"
44STATUS on
# Name of the data file: a path relative to SHAPEPATH is used.
44DATA "../raster/ne.tif"
44TYPE raster
# Scale at which the layer is drawn.
44MINSCALEDENOM 2000
44MAXSCALEDENOM 25000
4END
4#...........................................................................
4#...........................................................................
4 # 6th LAYER: it is a vector (shp file) layer
4 LAYER
4 NAME "lakes"
4 STATUS default
4 DATA "lakes"
4 TYPE polygon
4 LABELITEM "NAME"
4 CLASS
4 NAME "Lakes"
4 STYLE
4 # Name (or number) of the symbol to be used for the features
4 # Symbols are defined in the file given in the SYMBOLSET parameter
4 SYMBOL "lakes_ellipse"
4 COLOR 0 215 240
4 OUTLINECOLOR 0 215 240
4 END
4 LABEL
4 TYPE truetype
4 FONT "mtypcors"
4 SIZE 11
4 # Label positioning; available values: auto, ul|uc|ur|cl|cc|cr|ll|lc|lr; in
4 # this latter case first letter refers to Y coordinate (u= up, c= center,
4 # l= low), the second to X coordinate(l= left, c= center, r= right).
4 # By selecting the value "auto", MapServer is requested to calculate a
4 # label position that will not interfere with other labels.
4 POSITION AUTO
4 COLOR 0 0 255
4 BACKGROUNDCOLOR 255 255 0
4 END
4 END
4 END
4#...........................................................................
4 # 7th LAYER: it is a vector (shp file) layer
4 LAYER
4 NAME "railways"
4 STATUS on
4 DATA "railways"
4 TYPE line
4 MAXSCALEDENOM 100000
4 CLASS
4 NAME "Railways"
4 STYLE
4 SYMBOL "point"
4 COLOR 0 0 0
4 SIZE 7
4 END
4 STYLE
4 SYMBOL "point"
4 COLOR 255 255 0
4 SIZE 5
4 END
4 STYLE
4 SYMBOL "line10-10"
4 COLOR 0 0 0
4 SIZE 1
4 END
4 END
4 END
4
4#...........................................................................
4 # 8th LAYER:it is a vector (shp file) layer. A different projection (UTM32/WGS84
4 # characterises the data.
4 LAYER
4 NAME "stations"
4 STATUS on
4 DATA "stations"
4 TYPE point
4 CLASSITEM "COMP_CODE"
4 LABELITEM "NAME"
4 LABELMAXSCALEDENOM 100000
4 HEADER "header_f.html"
4 FOOTER "footer_f.html"
4 TEMPLATE "query_f.html"
4 # Projection: 32632 is the CRS UTM32/WGS84 code.
4 PROJECTION
4 "init=epsg:32632"
4 END
4 METADATA
4 qstring_validation_pattern '.'
4 END
4 CLASS
4 NAME "FNM stations (WGS84-UTM)"
4 # Four different kind of EXPRESSION are available to define the membership
4 # to one specific class:
4 # strings comparison (case sensitive and fastest to evaluate).
4 # regular expression (a regular expression ( regexp or regex is a string
4 # that describes or matches a set of strings,
4 # according to certain syntax rules. For example
4 # they are used by text editors and utilities
4 # to search and manipulate bodies of text based on
4 # certain patterns).
4 # Examples available at:
4 # http://umn.mapserver.ch/index_en.php
4 # logical expression, delimited by parentheses "(expression)". Attribute
444
4 # names are delimited by square brackets "[ATTRIBUTE]".
4 # The following logical operators are supported:
4 # =,>,<,<=,>=,=,or,and,lt,gt,ge,le,eq,ne.
4 # lenght function of the string;
4 # example: EXPRESSION (length('[NAME_E]') < 8)
4 #
4 # In the following, by using expression, "FNM" and "FS" stations are
4 # given different symbols and colors.
4 EXPRESSION "FNM"
4 LABEL
4 TYPE truetype
4 FONT "arial"
4 SIZE 9
4 POSITION auto
4 COLOR 0 200 0
4 BACKGROUNDCOLOR 200 255 0
4 #SHADOWSIZE 1 1
4 #SHADOWCOLOR 0 0 0
4 #BACKGROUNDSHADOWSIZE 5 5
4 #BACKGROUNDSHADOWCOLOR 0 100 0
4 END
4 STYLE
4 SYMBOL "7x7square"
4 COLOR 0 200 0
4 END
4 END
4 CLASS
4 NAME "FS stations (WGS84-UTM)"
4 EXPRESSION "FS"
4 LABEL
4 TYPE truetype
4 FONT "mtypcors"
4 SIZE 10
4 POSITION auto
4 COLOR 0 0 157
4 BACKGROUNDCOLOR 0 220 255
4 END
4 STYLE
4 SYMBOL "7x7square"
4 COLOR 0 0 157
4 END
4 END
4 END
4#...........................................................................
4 # 9th LAYER: it is a vector (MapInfo) layer. It is read through the OGR library.
4 LAYER
4 NAME "alluvional-cones"
4 STATUS on
4 TYPE line
4 # CONNECTIONTYPE specifies the connection:
4 # CONNECTIONTYPE [local|sde|ogr|postgis|oraclespatial|wms]
4 CONNECTIONTYPE OGR
44
4 # Relative path and data file (here the path is from the mapfile)
4 CONNECTION "data/ogr/alluvional-cones.tab"
4 MAXSCALEDENOM 100000
4 CLASS
4 NAME "Alluvional cones"
4 STYLE
4 COLOR 214 49 148
4 END
4 END
4 END
4#...........................................................................
4
4 # 10th LAYER: it is the same as the 8th layer but in the Gauss/Boaga projection.
4 LAYER
4 NAME "stationsgb"
4 STATUS on
4 DATA "GaussBoaga/stations"
4 TYPE point
4 CLASSITEM "COMP_CODE"
4 LABELITEM "NAME"
4 LABELMAXSCALEDENOM 100000
4 HEADER "header_f.html"
4 FOOTER "footer_f.html"
4 TEMPLATE "query_f.html"
4 CLASS
4 NAME "FNM stations (GB)"
4 EXPRESSION "FNM"
4 LABEL
4 TYPE truetype
4 FONT "arial"
4 SIZE 9
4 POSITION auto
4 COLOR 0 200 0
4 BACKGROUNDCOLOR 200 255 0
4 END
4 STYLE
4 SYMBOL "7x7square"
4 COLOR 250 215 0
4 END
4 END
4 CLASS
4 NAME "FS stations (GB)"
4 EXPRESSION "FS"
4 LABEL
444 TYPE truetype
444 FONT "mtypcors"
444 SIZE 10
444 POSITION auto
444 COLOR 0 0 157
444 BACKGROUNDCOLOR 0 220 255
4 END
444 STYLE
444 SYMBOL "7x7square"
444 COLOR 230 70 157
444 END
4 END
4 END
# end of the Map Object
END
文章目录
  1. 1. MapServer之MapFile学习
    1. 1.1. MapFile简介
    2. 1.2. MapFile的头部
    3. 1.3. 对象属性
      1. 1.3.1. MAP对象
        1. 1.3.1.1. MAP对象的主要属性(MAP对象内部的LAYER对象等下文说明):
      2. 1.3.2. WEB对象
    4. 1.4. Projection
      1. 1.4.1. LAYER对象
        1. 1.4.1.1. Vector layer
          1. 1.4.1.1.1. Shapefile
          2. 1.4.1.1.2. Mapinfo TAB
        2. 1.4.1.2. Query
      2. 1.4.2. Metadata
        1. 1.4.2.1. WIKI
          1. 1.4.2.1.1. Geotiff
          2. 1.4.2.1.2. Image Tiles
        2. 1.4.2.2. Grid Layer
      3. 1.4.3. WMS图层
      4. 1.4.4. DOWNLOAD
      5. 1.4.5. Reference对象(鹰眼)
      6. 1.4.6. Legend
      7. 1.4.7. Scalebar
      8. 1.4.8. QUERYMAP
    5. 1.5. OUTPUTFORMAT
    6. 1.6. 带注释示例
|