MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer

MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer

一、前言

  关于第一节的案例,分别介绍了一个基本的地图站点应用程序创建和多图层地图站点 应用程序创建。这个案例 主要来介绍一下mapfile文件中 LAYER 对象里面,CLASS对象的应用。

  同时还有如何根据CLASSITEM、EXPRESSION等配置去修改地图的显示方式。

  最后还有一个很酷炫的方法一次性读取shp文件中的数据信息。

  当前案例官网:https://www.mapserver.org/tutorial/example1-3.html#example1-3

  附带一点其他的,当前系列博客的大纲博文《MapServer Tutorial——MapServer7.2.1教程学习(大纲)》,我会持续更新。

  以及我所写博文的应用环境 《MapServer Configuring with IIS》。

  希望能够给新手带来帮助。

二、创建Example1.3 Displaying Classes in a Layer站点

  老规矩,按照先前的创建站点规则。

  在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

  在cmd中输入:md Example1.3

  在cmd中输入:cd Example1.3

  在cmd中输入:md data

  在cmd中输入:md logs

  在cmd中输入:cd.>web.config

  在cmd中输入:cd.>example1_3.map

  红色标记路径部分,按照你站点创建位置填写。

  修改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>

  打开IIS创建站点,站点名称、应用程序池名称为:Example1.3。端口号:8013。

  给应用程序池添加对logs文件夹的读写权限。

  在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.3\logs" /grant "IIS AppPool\Example1.3":(OI)(CI)RW

  将states_ugl.dbf、states_ugl.shp、states_ugl.shx等文件复制到Example1.3中的data文件夹下面。

  mapfile(example1_3.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         -97.238976 41.619778 -82.122902 49.385620
  SIZE           400 300
  SHAPEPATH      "./data"
  IMAGECOLOR     255 255 255

  # 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_poly
    DATA         states_ugl
    STATUS       OFF
    TYPE         POLYGON

    # 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‘ # Only polygons where "CLASS" = ‘land‘ will be drawn.

      # 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
    CLASS
      NAME ‘Water‘
      EXPRESSION ‘water‘ # Only polygons where "CLASS" = ‘water‘ will be drawn.
      STYLE
        COLOR      198 198 255
      END
    END
  END # States polygon layer ends here

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

    CLASSITEM    "CLASS"
    CLASS
      NAME       ‘State Boundary‘
      EXPRESSION ‘land‘
      STYLE
        COLOR    32 32 32
      END
    END
  END # States line layer ends here
  # End of LAYER DEFINITIONS -------------------------------
  DEBUG 5
  CONFIG "MS_ERRORFILE" "logs\ms.log"
END # All map files must come to an end just as all other things must come to...

  在浏览器中输入:http://localhost:8013/mapserv?map=../apps/Example1.3/example1_3.map&layer=states_poly&layer=states_line&mode=map

  

  URL参数解析通上一章《MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.2 Static Map with Two Layers》相同,详见上一章URL参数解析。

  同样的shp数据文件,只是mapfile文件不同,然后 polygon 区域的颜色就不同。这就是mapfile中CLASS对象的不同配置导致的。

三、MapFile文件解析

  mapfile文件结构如下:

                            MAP
(states_poly) LAYER----------|---------LAYER (states_line)
               |                        |
(land) CLASS---|---CLASS (water)        |-CLASS
          |         |                      |
    STYLE-|         |-STYLE                |-STYLE

  当前mapfile同样只有两个图层(layer),但是 polygon(NAME值为states_poly)的图层却有两个 CLASS 对象。其中 polygon 颜色的区分是通过:CLASSITEM、EXPRESSION等两个对象座椅区分的。

  CLASSITEM

    当一个layer使用多个CLASS时,CLASSITEM用于指定DBF文件(可理解为shp文件的数据库表)中,根据哪个属性(可理解为当前表的字段)去使用对应的CLASS。

    当前案例 states_ugl.shp 文件有多个 polygon 区域,states_ugl.shp记录这个区域的矢量数据 polygon 所在区域、数量等。同时每个polygon还包含其他哪些属性。

    但是,states_ugl.shp 中的 polygon 的其他属性数据在 states_ugl.dbf 文件里面。

    打开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\Example1.3\data

    在cmd中输入:ogrinfo -al -so states_ugl.shp,查看当前shp文件的相关属性数据。数据如下:

    

INFO: Open of `states_ugl.shp‘
      using driver `ESRI Shapefile‘ successful.

Layer name: states_ugl
Metadata:
  DBF_DATE_LAST_UPDATE=2002-03-07
Geometry: Polygon
Feature Count: 204
Extent: (-97.238976, 41.619778) - (-82.122902, 49.385620)
Layer SRS WKT:
(unknown)
AREA: Real (12.3)
PERIMETER: Real (12.3)
STATESP020: Integer64 (11.0)
STATE: String (20.0)
STATE_FIPS: String (2.0)
CLASS: String (5.0)

    可以看到,shp的属性中包含一个叫做CLASS的属性。

    在cmd中输入:ogrinfo -al -ro states_ugl.dbf 。可以查看当前shp文件的所有数据。

    当然,输入:ogrinfo -al -ro states_ugl.shp也可以。因为目前案例中的数据文件是ESRI Shapefiles,所以最少包含三个文件,后缀名分别是:dbf、shp、shx,可以查看:https://www.mapserver.org/input/vector/format_types.html

    相关命令查看:https://gdal.org/ogrinfo.html

    

  EXPRESSION

    EXPRESSION,字面意思就是表达式。

    当前mapfile中,对于 CLASS 对象,我们根据 EXPRESSION 指定的属性值去选择 CLASS 应用到 LAYER 层上。

    当然,EXPRESSION 可以多个值,也可以是逻辑表达式。详情请看:https://www.mapserver.org/mapfile/expressions.html#expressions

四、后记

  通过当前案例,主要学习了CLASSITEM、EXPRESSION等的简单使用。

  同时,也知道了如何通过GDAL包中的相关ogrinfo命令去查看shape文件中的相关数据。

原文地址:https://www.cnblogs.com/eshinex/p/10289011.html

时间: 2024-07-30 19:12:44

MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer的相关文章

MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.1 A map with single layer

MapServer Tutorial--MapServer7.2.1教程学习--第一节用例实践:Example1.1 A map with single layer 一.前言 开始MapServer用例实践之旅,做项目算是可以比喻为考试,但是考试之前,还是以做练习题模拟考为主.下面实践一下官网的第一个例子:Example1.1 A map with single layer(官网地址:https://www.mapserver.org/tutorial/example1-1.html#examp

MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.2 Static Map with Two Layers

MapServer Tutorial--MapServer7.2.1教程学习--第一节用例实践:Example1.2 Static Map with Two Layers 一.前言 上一篇博客<MapServer Tutorial--MapServer7.2.1教程学习--第一节用例实践:Example1.1 A map with single layer>中介绍了单图层的地图加载显示.下面根据官网的例子介绍两个图层的加载显示.官网地址:https://www.mapserver.org/tu

MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map

MapServer Tutorial--MapServer7.2.1教程学习--第一节用例实践:Example 1.4 Labeling the Map 一.前言 MapServer拥有非常灵活的标签标记系统.它支持bitmap以及truetype字体等.使用truetype字体同时还支持其缩放.标签的角度和位置是可以自定义的. 通过把标签的位置和角度以及其他参数的设置使用,你可以把你的地图装饰得更加美观,信息体现的更加丰富. 二.搭建Example1.4站点 所有的学习都要通过实践,还是从搭建

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

MapServer Tutorial--MapServer7.2.1教程学习--第一节用例实践:Example1.5 Adding a  raster layer 一.前言 MapServer不仅支持矢量数据(point, lines, polygons, and annotations),同时也支持栅格数据.通过GDAL库,MapServer可以输入输出多种类型的栅格数据. 在4.x版本前,MapServer输出栅格数据仅限于单个图层.灰度图像或伪彩色图像. 当前版本支持RGB图像和多光谱图像

MapServer Tutorial——MapServer7.2.1教程学习(大纲)

MapServer Tutorial--MapServer7.2.1教程学习(大纲) 前言 最近在学习Gis方面的知识,因为电脑硬件配置偏低,顾选择MapServer入手.网上搜索MapServer系列教程较少,对于入门级开发人员而言,还是有一定的难度,所以在自己通过官网学习之余,也将官网的案例加以实践和记录,方便自己学习实践和后续查阅.也为其他入门新手略尽绵薄之力.官网地址:https://www.mapserver.org/tutorial/index.html. 其实我自己下载的是编译好的

MapServer Tutorial——MapServer7.2.1教程学习——教程背景

MapServer Tutorial--MapServer7.2.1教程学习--教程背景 一.前言 目前处于MapServer学习入门阶段,所以每一步都需要打下扎实基础.尽自己最大的努力,去学习知识的细节.一步一步按照官网上的教程操作.争取掌握MapServer. 二.教程时间表 高手可能在一天内就完成了所有的操作,新手可能需要一个星期.(希望给每个公司都能入职的新人拟定相关的学习计划和给定适当的时间周期去学习,不是每个人生来就是天才,但是给他们学习和挖掘的机会.) 三.教程数据资源 教程的数据

.Net程序员之Python基础教程学习----列表和元组 [First Day]

一. 通用序列操作: 其实对于列表,元组 都属于序列化数据,可以通过下表来访问的.下面就来看看序列的基本操作吧. 1.1 索引: 序列中的所有元素的下标是从0开始递增的. 如果索引的长度的是N,那么所以的范围是-N~N-1之间,超过这个范围就会提示 IndexError:  index out of range >>> greeting ='Hello world' >>> print greeting Hello world >>> print gr

ReactiveCocoa入门教程:第一部分

本文翻译自RayWenderlich,原文:ReactiveCocoa Tutorial--The Definitive Introduction: Part 1/2 作为一个iOS开发者,你写的每一行代码几乎都是在相应某个事件,例如按钮的点击,收到网络消息,属性的变化(通过KVO)或者用户位置的变化(通过CoreLocation).但是这些事件都用不同的方式来处理,比如action.delegate.KVO.callback等.ReactiveCocoa为事件定义了一个标准接口,从而可以使用一

ArcGIS for Desktop入门教程_第一章_引言 - ArcGIS知乎-新一代ArcGIS问答社区

原文:ArcGIS for Desktop入门教程_第一章_引言 - ArcGIS知乎-新一代ArcGIS问答社区 1 引言 1.1 读者定位 我们假设用户在阅读本指南前应已具备以下知识: · 熟悉Windows的基本操作 · 接触过地理信息系统的概念 · 理解地理数据的特点 1.2 预期效果 我们期望用户在阅读完本指南后对以下知识有一定的了解: · 了解ArcGIS for Desktop的组成与功能 · 熟悉使用ArcGIS for Desktop进行数据编辑.整饰和输出的流程 · 如何使用