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/」。確保路徑末尾包含一個斜槓(/)。
相關文章
相關標籤/搜索