MapServer6.4.1教程学习--添加OGC WMS图层(1-7)

示例1.7添加OGC WMS图层

(http://www.mapserver.org/tutorial/example1-7.html#example1-7)

MapServer6.4.1教程学习--添加OGC WMS图层(1-7)_第1张图片

MapServer另一个让人兴奋的特点在于它具备使用其他地图服务器的能力。此例中MapServer应用成为了WMS(或WFS)客户端。MapServer也可以与其他地图服务器共享(或作为服务)mapfile文件中的图层。这样它就是一个WMS(或WFS)服务器。什么是WMS或WFS?这些是开放地理联盟(Open Geospatial Consortium , OGC)发布的“基于网络的互操作服务”规范。WMS代表网络地图服务,WFS代表网络要素服务。简单来说这两个规范之间的差别在于WMS是用网络栅格格式(PNG,GIF,JPEG)来使用图层,而WFS用的是地理标记语言(GeographyMarkup Language, GML)。第三OGC互操作规范是网络覆盖服务规范(Web Coverage Services, WCS)。MapServer仅支持服务端层次的WCS。可以去 OGC’s web site查找关于WMS,WFS和WCS的更多信息,也可以看看OGC ImplementationSpecifications 或 OGC AbstractSpecifications。MapServer官网上也有这些规范的文档和WIKI页。

这个例子向你展示了如何在你的mapfile文件中添加一个WMS图层。

MapFile

下面是示例1-7的mapfile文件:

Theannotated 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.2853331425518.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 usedwithin the map and the layer

  # objects. You only define it once withinthe map object and this definition

          # becomes your outputprojection--MapServer will render your maps in this

  # projection.  You also use the projection object within thelayer object to

  # define your input projection.  Your layers can be in different

          # projections--MapServer willreproject them into your output projection.

  # If no projection is defined within thelayer object, MapServer assumes

  # your input projection is the same asyour output projection.  This is not

  # a required object unless you're creatinga map file that supports one of

  # the OGC interoperability web servicesspecifications (WMS/WFS/WCS).

  #

  # This is the output PROJECTION definition------

  PROJECTION

    # Projection parameters can be definedin two ways...

    # This is the traditional Proj.4definition 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 EPSGcode.

    # This is the EPSG code for LambertAzimuthal Equal-Area

    # projection for the U.S.

    "init=epsg:2163"

         END

 

  # The web object is defined at the levelbelow the map object.  All

  # web-related parameters (I interchange"parameters" and "keyword/value

  # pairs" quite frequently, sorryabout that) are defined in this object.

  WEB

    IMAGEPATH "/ms4w/tmp/"

    IMAGEURL  "/tmp/"

  END

 

  # Layer objects are defined beneath themap object.  You need at least one

  # layer defined in your map file beforeyou can display a map...  You can

  # define as many layers as you'd likealthough 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 applicationto need more than 100 layers in

  # your application.

  #

  # Start of LAYER DEFINITIONS---------------------------------------------

  LAYER # States polygon layer beginshere

    NAME         states

    DATA         states_ugl

    STATUS       OFF

    TYPE         POLYGON

 

    # Here's an example of the inputprojection definition.

    # EPSG:4326 is code for geographic(latlong) projection

    # using the WGS84 datum.

    #

    # PROJECTION objects within the LAYERobject define the input

    #projection--this is the native projection of your data.

    PROJECTION

      "init=epsg:4326"

    END

 

    # CLASSITEM defines the non-spatialattribute that you will be using to

    # separate a layer into classes.  This attribute will be in the DBF file

    # of your shapefile (it will bedifferent for each data format).  In this

    # example the shapefile states_ugl hasan associated database

    # (states_ugl.dbf) that contains anattribute called "CLASS".  Youwill be

    # using two values in the CLASSattribute to separate the classes (also

    # called themes) used in thislayer--land and water.  CLASSITEM is usedin

    # association with the EXPRESSIONparameter in the CLASS object.  Seebelow.

    CLASSITEM    "CLASS"

 

    # The class object is defined within thelayer object.  You can define as

    # many classes as you need (well, thereare limits as with layers, but it's

    # senseless to define more than ten on a"normal" layer.  There are

    # situations, however, where you mighthave to do it.)

    CLASS

      NAME 'States'

      EXPRESSION 'land'

 

      # There are styles in a class, justlike there are classes in a layer,

      # just like there are layers in amap.  You can define multiple styles in

      # a class just as you can definemultiple classes in a layer and multiple

      # layers in a map.

      STYLE

        COLOR      232 232 232

      END

    END

  END # States polygon layer endshere

 

  # In addition to vector data (shapefilesare vector data), MapServer supports

  # a host of raster formats.  In GIS world, one of the most common raster

  # formats is GeoTIFF, a TIFF image withgeospatial headers.  MapServer also

  # supports JPEG, PNG, GIF, and othercommon formats.  Other raster formats

  # supported by MapServer include ESRIArc/Info grid, HDF and HDF-EOS, NetCDF,

  # Generic raster binaries, OGC Web MapService (WMS) layers, etc.  Pretty much

  # any raster format you can think of isprobably supported, thanks to the

  # impressive Geospatial Data AbstractionLibrary (GDAL, pronounced "GOODALL"

  # or GOODLE?).  More information on GDAL is available athttp://www.gdal.org.

  #

  # MapServer 4.x can read and displaybitmapped (like GIFs), RGB/A (true

  # color), and multispectral (images withmore than 3 bands, like raw LandSat

  # images) rasters.

  LAYER # MODIS raster layer beginshere

    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 MappingService (WMS) providers.  WMS is a

  # web service specification from OpenGeospatial Consortium (OGC) and is

  # intended to be an interoperabilitystandard for web mapping applications.

  # This allows us to display layers wedon'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 displayour layer, and that server can be

          # down when you really needit.  The cool thing is that JPL has a WMSserver

  # that serves out MODIS and LandSat mapsfor 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 beginshere

    NAME         states

    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 beginshere

    NAME         states_label

    DATA         states_ugl

    STATUS       OFF

    TYPE         ANNOTATION

 

    PROJECTION

      "init=epsg:4326"

    END

 

    CLASSITEM    "CLASS"

 

    # Just like CLASSITEM, LABELITEM definesthe 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, justlike there are classes in a layer,

      # just like there are layers in amap.  You can define multiple labels in

      # a class just as you can definemultiple classes in a layer and multiple

      # layers in a map.

      # MapServer has a very flexiblelabeling system.  With that flexibility

      #comes complexity, specially when using truetype fonts.  Please read

      # through the LABEL section of theMapServer map file documentation at

      # http://www.mapserver.org/mapfile formore information.

      LABEL

        COLOR 132 31 31

        SHADOWCOLOR218 218 218

        SHADOWSIZE 1 1

        TYPE TRUETYPE

        FONT arial-bold

        SIZE 12

        ANTIALIAS TRUE

        POSITION CL

        PARTIALS FALSE

        MINDISTANCE 200

        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

图层对象和WMS参数

让我们看看WMS图层。

LAYER  #MODISWMS map from JPL

              WMS LAYER对象开始标记。

NAME  modis-jpl

LAYER标识符

TYPE RASTER

             因为WMS图层是一个图像,我们设置LAYERTYPE 为 RASTER。

OFFSITE 0 0 0

              忽略的背景色。

STATUS OFF

              默认关闭这个图层。

CONNECTIONTYPE WMS

              LAYER连接类型。默认值是LOCAL。

              注意:如果需要显示定义LOCAL,需要在mapfile文件所有矢量和栅格图层中加入CONNECTIONTYPELOCAL。否则只需要定义外部图层的连接类型。WMS是另一个地图服务器上的外部数据图层。

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

              允许我们从另一个服务器上获取数据的连接字符串。在WMS连接示例中,它就是一个网址(URL)。如果使用PostGIS数据库,它可能就是一个SQL语句。请注意字符串在mapfile文件中必须是单独一行。

METADATA

              WMS图层METADATA对象开始标记。MapServer用它与此对象内前面CONNECTION参数组合成一个合法的WMS请求,传递给WMS服务器。

“wms_srs” “epsg:4326”

              WMS投影。有时WMS服务器支持多个投影。如果是这种情况你可能想以你输出投影方式(epsg:2163)请求地图。不幸的是JPL服务器不支持这种投影。

"wms_name" "modis"

              WMS图层名称。这就像添加了参数“layers=modis”

"wms_server_version""1.1.1"

              服务器编译的WMS版本。可查看MapServer OGCSpecification support.获得更多选项。

"wms_format" "image/jpeg"

              希望从WMS服务器接收的图像格式。你可以试着用image/png或其他格式替换这个值。

END

              METADATA对象结束标记。

要了解关于添加WMS图层到应用中的更多信息,请访问MapServerWMS Client Howto.

 

WEB对象参数

除了洄WMS图层对象外,在MAP下面还有一个新对象。它就是WEB对象。在WEB对象里面有两个参数:

IMAGEPATH "/ms4w/tmp/"

网络可访问临时目录的本地绝对路径。运行网络服务器进程的用户必须具备对此目录的写权限。确保此路径最后包含斜杠(/)。(你的IMAGEPATH可能看起来像 “/home/apache/htdocs/tmp/” 或“C:/Inetpub/wwwroot/tmp/”.)

IMAGEURL "/tmp/"

IMAGEPATH相对于网络服务器要目录的相对目录。如果我们输入完整URL,将会是 “http://terrasip.gis.umn.edu/tmp/”.确保路径末尾包含斜杠(/)。

 

最后在MAP对象内添加了一个新参数:NAME。这个是MAP对象的标识符。MapServer将它作为服务器产生并输出到tmp目录的所有图像的前缀。此刻还不需要,但是放在这里也没有什么不对。

 

如果你想与其他地图服务器共享你的数据图层,你需要在你所有想要共享的MAP对象和LAYER对象内添加METADATA对象。你从其他服务器所有WMS图层也将自动级连并可被他人访问。为了解如何将MapServer应用变成WMS服务器的更多信息,请阅读 MapServer WMSServer HowTo.。那里也存在配置MapServer应用(作为服务器或客户端)使之支持WFS标准的文档。

 

PS:中文版权为asswclw所有,请尊重劳动成果,转载将注明出处。

你可能感兴趣的:(MapServer,Mapserver,WEBGIS,中文教程,地图)