MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.7 Adding a wms layer

MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.7 Adding a wms layerhtml

前言web

  Add OGC WMS Layers(添加一个Open Geospatial Consortium  web-based interoperability service 图层)。数据库

  MapServer能够使用来之其余地图服务器的的图层。这种状况下,MapServer将做为一个WMS(或WFS)客户端。固然,MapServer也能够将数据共享层提供给其余地图服务器。这个时候MapServer做为WMS(或WFS)服务器。  apache

WMS、WFS、WCS等概念浏览器

  WMS(Web Map Service)服务器

  描述:app

  WMS表示地图服务。它可以根据浏览器请求返回相应的web光栅格式的地图数据(如:PNG、GIF、JPEG等,或者是SVG、WEB CGM等矢量形式数据)。同时他还能指定返回的数据是否为PNG透明格式,以便用户叠加多个图层使用。WMS支持HTTP协议,全部的操做均由URL决定。less

  应用操做:分布式

  WMS规范定义了许多请求类型,每一个请求类型都有一组查询参数和相关行为。符合WMS的服务器必须可以处理至少如下两种类型的WMS请求:ide

    • 1. GetCapabilities:返回一个XML文档,其中包含Web Map服务器信息的元数据
    • 2. GetMap:根据用户的须要返回地图的图像。

  对如下类型的支持是可选的:

    • 1. GetFeatureInfo:在查询(鼠标单击)位置返回关于feature(要素)的信息。MapServer支持3种类型的响应:
      • text/plain 附带属性信息的文本输出
      • text/html 在经过MapServer经过指定 CLASS TEMPLATE 参数(参数的文件名必须以.html做为后缀名) 查询 相应模板。MIME经过 CLASS TEMPLATE 转换为默认的 text/html 输出,并经过“wms_feature_info_mime_type”元数据(metadata)控制。
      • application/vnd.ogc.gml,GML.1 或 GML for GML 要素(features)。
    • 2. DescribeLayer:返回一个或多个映射层描述:
      • 矢量层:一我的有效的描述返回必须先设置wfs_onlineresource(或ows_onlineresource)元数据在地图中的级别(map level)或层级级别(layer level)。
      • 栅格层:设置wcs_onlineresource元数据在相应的图层中。
    • 3. GetLegendGraphic:返回请求层的图例图像(图标)和标签

  WFS(Web Feature Service)

  描述:

  WFS是基于地理要素级别的数据共享和数据操做,WFS规范定义了若干基于地理要素(Feature)级别的数据操做接口,并以 HTTP 做为分布式计算平台。经过 WFS服务,客户端能够获得矢量数据格式描述的单个地理要素的空间数据或要素集的空间数据,并能够对单个地理要素进行编辑、 删除、 添加等数据操做。WFS采用 GML描述地理要素特征, 根据用户请求的内容返回 GML描述的空间数据。

  应用操做:

    • 1. GetCapabilities:生成一个服务元数据文档,描述服务器提供的WFS服务,须要生产KVP编码(选择性生产XML编码)。
    • 2. DescribeFeatureType:返回WFS实例提供的要素(Feature)类型描述。该描述定了WFS对要素文件的插入、更新、替换的操做规范。以及要是(Feature)是如何输出的。
    • 3. GetFeature:从数据存储中返回所选的要素(Feature)。WFS处理GetFeature请求并向客户机返回一个响应文档,该文档包含零个或多个知足请求中指定的查询表达式的要素(Feature)实例。
    • 4. StoredQuery:
      • 4.1 ListStoredQueries:列出了服务器上可用的存储查询
      • 4.2 DescribeStoredQueries:提供查询时,每一个metadata的详细信息。
      • 4.3 CreateStoredQuery:建立查询。
      • 4.4 DropStoredQuery:关闭查询
    • 5. LockFeature:Web链接本质上是无状态的。客户端获取一个Feature实例。而后在客户端修改该Feature,并经过事务请求更新将其提交回WFS。因为没法保证在客户端修改Feature时,不会出现另外一个客户端更新数据库中的相同Feature,所以丧失了可序列化性。操做 WFS能够在一个事务处理期间锁定一个地理要素类型中的一个或多个地理Feature要素实例, 这使 WFS具备支持可序列化事务的能力。
    • 6. Transaction:用于描述将应用于WFS服务控制下的Feature实例的数据转换操做。使用事务操做客户端能够在web feature service的数据存储中建立、修改、替换和删除feature。GML(参见ISO 19136:2007)做为Feature的规范描述,特定WFS实现须要将这种规范的GML描述转换为数据存储中使用的内部描述(也能够是GML,在这种状况下不须要进行转换)。

  WCS(Web Coverage Service)

  描述:

  OGC Web Coverage Service (WCS)支持将地理空间数据的电子检索做为“覆盖物”——即表示空间/时变物候的数字地理空间信息。WCS以对客户端呈现、对科学模型的输入以及对其余客户端有用的形式提供对覆盖率数据的访问。能够将WCS与OGC Web Feature Service (WFS)和Web Map Service (WMS)进行比较。做为WMS和WFS服务实例,WCS容许客户端基于空间约束和其余查询条件选择服务器的部分信息。

  应用操做:

    • 1. GetCapabilities:根据OWS Common [OGC 06-121r9]的要求,容许WCS客户机检索WCS服务器提供的服务和覆盖元数据。
    • 2. DescribeCoverage:提供覆盖标识符列表,并提示服务器为每一个标识符返回相应覆盖的描述。
    • 3. GetCoverage:提示WCS服务处理从服务提供中选择的特定覆盖率,并返回派生覆盖率。WCS核心标准定义了域子集操做,该操做相对于覆盖率信封(更准确地说,是请求信封与覆盖率信封的交集),从指定的请求信封(“边界框”)内的覆盖率交付全部数据。

  相关资料下载:WMS.pdfWFS.pdfWSC.pdf 

建立Example1.7 Adding a wms layer

  操做:

    •   1. 在cmd中输入:cd /d E:\SvnWorkspace\LY_WEB_GIS\branches\Documents\ms4w-mapserver-for-wimdows\release-1911-x64-gdal-2-3-3-mapserver-7-2-1\apps
    •   2. 在cmd中输入:md Example1.7
    •   3. 在cmd中输入:cd Example1.7
    •   4. 在cmd中输入:md data
    •   5. 在cmd中输入:md logs
    •   6. 在cmd中输入:md symbols
    •   7. 在cmd中输入:md fonts
    •   8. 在cmd中输入:md tmp
    •   9. 在cmd中输入:cd.>web.config
    • 10. 在cmd中输入:cd.>example1_7.map
    • 11. 在cmd中输入:cd data
    • 12. 在cmd中输入:md raster

  将 apps/tutorial/data 中的 states_ugl.dbf、states_ugl.shp、states_ugl.shx 三个文件拷贝到 apps/Example1.7/data 文件夹下面

  将 apps/tutorial/data/raster 中的 mod09a12003161_ugl_ll_8bit.tif 复制到 apps/Example1.7/data/raster 文件夹下面

  将 apps/tutorial/symbols 中的 symbols35.sym 复制到 apps/Example1.7/data/symbols 文件夹下

  将 apps/tutorial/fonts 中的全部文件 复制到  apps/Example1.7/data/fonts 文件夹下

  修改 web.config 文件以下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="MapServerFastCgi" path="*" verb="*" type="" modules="FastCgiModule" 
          scriptProcessor
="E:\SvnWorkspace\LY_WEB_GIS\branches\Documents\ms4w-mapserver-for-wimdows\release-1911-x64-gdal-2-3-3-mapserver-7-2-1\bin\mapserv.exe"
          resourceType
="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="" /> </handlers> <caching enabled="true" enableKernelCache="true" /> </system.webServer> </configuration>

  修改 example1_7.map 文件以下:

# The annotated map file (sort of)
# Created by Pericles S. Nacionales for the MapServer tutorial
# 20050408
#
# MapServer map file uses the pound sign (#) to denote the start of a line
# comment--each line that needs to be commented has to be prepended with a "#".
#
# Map files begin with MAP keyword to signify the start of the map object.
# Well, the entire map file is THE map object. Enclosed between MAP and END
# at the very bottom of this map file, are keyword/value pairs and other
# objects.
MAP
IMAGETYPE PNG
EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # LAEA
#EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic
SIZE 400 300
SHAPEPATH "./data"
SYMBOLSET "./symbols/symbols35.sym"
FONTSET "./fonts/fonts.list"

# The projection object is typically used within the map and the layer
# objects. You only define it once within the map object and this definition
# becomes your output projection--MapServer will render your maps in this
# projection. You also use the projection object within the layer object to
# define your input projection. Your layers can be in different
# projections--MapServer will reproject them into your output projection.
# If no projection is defined within the layer object, MapServer assumes
# your input projection is the same as your output projection. This is not
# a required object unless you're creating a map file that supports one of
# the OGC interoperability web services specifications (WMS/WFS/WCS).
#
# This is the output PROJECTION definition ------
PROJECTION
# Projection parameters can be defined in two ways...
# This is the traditional PROJ.4 definition of Lambert Azimuthal Equal-Area
# projection for the Continental U.S.
# "proj=laea"
# "ellps=clrk66"
# "lat_0=45"
# "lon_0=-100"
#
# Alternatively, you can specify an EPSG code.
# This is the EPSG code for Lambert Azimuthal Equal-Area
# projection for the U.S.
"init=epsg:2163"
END

# The web object is defined at the level below the map object. All
# web-related parameters (I interchange "parameters" and "keyword/value
# pairs" quite frequently, sorry about that) are defined in this object.
WEB
IMAGEPATH "/tmp/"
IMAGEURL "/tmp/"
END

# Layer objects are defined beneath the map object. You need at least one
# layer defined in your map file before you can display a map... You can
# define as many layers as you'd like although a limit is typically hard-coded
# in map.h in the MapServer source. The default limit is set at 100. You'd
# have to have a very specialized application to need more than 100 layers in
# your application.
#
# Start of LAYER DEFINITIONS ---------------------------------------------
LAYER # States polygon layer begins here
NAME states_polygon
DATA states_ugl
STATUS OFF
TYPE POLYGON

# Here's an example of the input projection definition.
# EPSG:4326 is code for geographic (latlong) projection
# using the WGS84 datum.
#
# PROJECTION objects within the LAYER object define the input
# projection--this is the native projection of your data.
PROJECTION
"init=epsg:4326"
END

# CLASSITEM defines the non-spatial attribute that you will be using to
# separate a layer into classes. This attribute will be in the DBF file
# of your shapefile (it will be different for each data format). In this
# example the shapefile states_ugl has an associated database
# (states_ugl.dbf) that contains an attribute called "CLASS". You will be
# using two values in the CLASS attribute to separate the classes (also
# called themes) used in this layer--land and water. CLASSITEM is used in
# association with the EXPRESSION parameter in the CLASS object. See below.
CLASSITEM "CLASS"

# The class object is defined within the layer object. You can define as
# many classes as you need (well, there are limits as with layers, but it's
# senseless to define more than ten on a "normal" layer. There are
# situations, however, where you might have to do it.)
CLASS
NAME 'States'
EXPRESSION 'land'

# There are styles in a class, just like there are classes in a layer,
# just like there are layers in a map. You can define multiple styles in
# a class just as you can define multiple classes in a layer and multiple
# layers in a map.
STYLE
COLOR 232 232 232
END
END
END # States polygon layer ends here

# In addition to vector data (shapefiles are vector data), MapServer supports
# a host of raster formats. In GIS world, one of the most common raster
# formats is GeoTIFF, a TIFF image with geospatial headers. MapServer also
# supports JPEG, PNG, GIF, and other common formats. Other raster formats
# supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,
# Generic raster binaries, OGC Web Map Service (WMS) layers, etc. Pretty much
# any raster format you can think of is probably supported, thanks to the
# impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"
# or GOODLE?). More information on GDAL is available at http://www.gdal.org.
#
# MapServer 4.x can read and display bitmapped (like GIFs), RGB/A (true
# color), and multispectral (images with more than 3 bands, like raw LandSat
# images) rasters.
LAYER # MODIS raster layer begins here
NAME modis
DATA "raster/mod09a12003161_ugl_ll_8bit.tif"
STATUS OFF
TYPE RASTER
PROCESSING "BANDS=1,2,3"
OFFSITE 71 74 65

PROJECTION
"init=epsg:4326"
END
END # MODIS raster layer ends here

# MapServer can consume (in ESRI parlance) layers from other map servers as
# long as those servers are Web Mapping Service (WMS) providers. WMS is a
# web service specification from Open Geospatial Consortium (OGC) and is
# intended to be an interoperability standard for web mapping applications.
# This allows us to display layers we don't usually have (or can't store in
# our computers due to space limitations). The downside is that we have to
# depend on some other server to display our layer, and that server can be
# down when you really need it. The cool thing is that JPL has a WMS server
# that serves out MODIS and LandSat maps for the whole world--try storing
# those datasets on your computer!
LAYER # MODIS WMS map from JPL
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 # Modis WMS image ends here

LAYER # States line layer begins here
NAME states_line
DATA states_ugl
STATUS OFF
TYPE LINE

PROJECTION
"init=epsg:4326"
END

CLASSITEM "CLASS"
CLASS
NAME 'State Boundary'
EXPRESSION 'land'
STYLE
SYMBOL 'line5'
COLOR 32 32 32
SIZE 1
END
END
END # States line layer ends here

LAYER # States label layer begins here
NAME states_label
DATA states_ugl
STATUS OFF
TYPE POLYGON

PROJECTION
"init=epsg:4326"
END

CLASSITEM "CLASS"

# Just like CLASSITEM, LABELITEM defines the database attribute that you
# will be using to draw labels. In this case, the values of the attribute
# "STATE" will be used to label the states polygons.
LABELITEM "STATE"

CLASS
EXPRESSION 'land'
STYLE
COLOR -1 -1 -1
END

# There can be labels in a class, just like there are classes in a layer,
# just like there are layers in a map. You can define multiple labels in
# a class just as you can define multiple classes in a layer and multiple
# layers in a map.
# MapServer has a very flexible labeling system. With that flexibility
# comes complexity, specially when using truetype fonts. Please read
# through the LABEL section of the MapServer map file documentation at
# http://www.mapserver.org/mapfile for more information.
LABEL
COLOR 132 31 31
#SHADOWCOLOR 218 218 218
#SHADOWSIZE 2 2
TYPE TRUETYPE
FONT arial-bold
SIZE 12
ANTIALIAS TRUE
POSITION CL
PARTIALS FALSE
MINDISTANCE 300
BUFFER 4
END # end of label
END # end of class
END # States label layer ends here
# End of LAYER DEFINITIONS -------------------------------

END # end of map file

  建立站点

    名称为:Exapmle1.7,端口:8017,应用程序池:Example1.7

    设置应用程序池对日志目录的读写权限,在cmd中输入:icacls "E:\SvnWorkspace\LY_WEB_GIS\branches\Documents\ms4w-mapserver-for-wimdows\release-1911-x64-gdal-2-3-3-mapserver-7-2-1\apps\Example1.7\logs" /grant "IIS AppPool\Example1.7":(OI)(CI)RW

  打开站点

    在浏览器中输入:http://localhost:8017/mapserv?map=../apps/Example1.7/example1_7.map&layer=states_polygon&layer=modis&layer=modis_jpl&layer=states_line&layer=states_label&mode=map

  

MapFile(example1_7.map)文件解析

  WMS Layer

    LAYER # MODIS WMS map from JPL

      • WMS LAYER层的开始标签。

    NAME modis_jpl

      • LAYER层的惟一命名

    TYPE RASTER

      • 因为WMS层是一个图像,咱们使用光栅做为层类型。

    OFFSITE 0 0 0

      • 忽略背景颜色

    STATUS OFF

      • 当前层默认关闭状态

    CONNECTIONTYPE WMS

      • 当前LAYER层的WMS连接,默认是本地。注意,若是必须显式,咱们将在mapfile中的全部othe vector和raster层中添加CONNECTIONTYPE LOCAL。相反,咱们只定义外部链接类型。WMS是一个外部数据层,来自另外一个map服务器。

    CONNECTION “http://mapus.jpl.nasa.gov/wms.cgi?”

      • 容许咱们从另外一台服务器获取数据的链接字符串。对于WMS链接,这是一个URL。若是咱们使用PostGIS数据库,它将是一条SQL语句。请注意,字符串必须在mapfile中的一行中设置,不能换行。

    METADATA

      • 标记WMS层的元数据(metadata)对象的开始。MapServer在这个对象中定义的参数以及使用上面的链接参数来造成对WMS服务器的有效WMS请求。

    “wms_srs” “epsg:4326”

      • WMS投影(坐标系)。有时WMS服务器支持多个投影。若是是这种状况,您可能但愿在输出投影中请求映射(epsg:2163)。可是,JPL服务器不支持这种投影。

    “wms_name” “modis”

      • WMS层名称

    “wms_server_version” “1.1.1”

      • WMS服务器版本信息

    “wms_format” “image/jpeg”

      • 咱们指望从WMS服务器接收的图像格式

    END

      • LAYER 标签结束

  WEB标签

    • IMAGEPATH:web站点服务器访问的临时目录。运行web服务器进程的用户应该可以写入这个目录。确保路径末尾包含一个斜杠(/)。(您的IMAGEPATH多是这样的:“/home/apache/htdocs/tmp/”或“C:/Inetpub/wwwroot/tmp/”。)
    • IMAGEURL:这就是IMAGEPATH相对于web服务器根目录的显示方式。若是咱们必须为此输入完整的URL,它将是“http://terrasip.gis.umn.edu/tmp/”。确保路径末尾包含一个斜杠(/)。
相关文章
相关标签/搜索