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文件中的相关数据。

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

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

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.7 Adding a wms layer 前言 Add OGC WMS Layers( ...

  2. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.6 Defining Projections and Extents

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.6 Defining Projections and Extents 一.前言 当在m ...

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

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

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

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map 一.前言 MapServer拥有非常灵活的标签 ...

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

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.2 Static Map with Two Layers 一.前言 上一篇博客< ...

  6. 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用 ...

  7. MapServer Tutorial——MapServer7.2.1教程学习——第一节:MapServer的基本配置管理,静态地图应用以及MapFile文件

    MapServer Tutorial——MapServer7.2.1教程学习——第一节:MapServer的基本配置管理,静态地图应用以及MapFile文件 前言 万事开头难,有了<MapSer ...

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

    MapServer Tutorial——MapServer7.2.1教程学习(大纲) 前言 最近在学习Gis方面的知识,因为电脑硬件配置偏低,顾选择MapServer入手.网上搜索MapServer系 ...

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

    MapServer Tutorial——MapServer7.2.1教程学习——教程背景 一.前言 目前处于MapServer学习入门阶段,所以每一步都需要打下扎实基础.尽自己最大的努力,去学习知识的 ...

随机推荐

  1. React时间组件(时分秒补0)页面全局引用

    1.common.js export function formatTime(data){ var d = new Date(data); function doTime(d){ if(d<10 ...

  2. javascript笔记——源生js实现each方法

    出处:http://www.lovejavascript.com/#!zone/blog/content.html?id=48 jquery里面有个each方法,将循环操作简化.便捷. 随后es出了个 ...

  3. 邮件发送 utils

    package cn.itcast.bos.utils;   import java.util.Properties;   import javax.mail.Message; import java ...

  4. linux下视频转gif

    title: linux下视频转gif date: 2017-11-23 16:55:26 tags: linux categories: linux 安装ffmpeg ffmpeg是一套非常强大的音 ...

  5. C# AsyncCallback异步回调用法示例

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  6. Oracle expdp impdp中 exclude/include 的使用

    exclude和include参数能够在使用expdp或impdp是对特定的对象或对象类型进行筛选或过滤.比如因工作的需要导出特定的表或不导出特定的表.视图以及存储过程.索引.约束.授权统计信息等等. ...

  7. Linux基础命令---lp打印文件

    lp lp指令用来打印文件,也可以修改存在的打印任务.使用该指令可以指定打印的页码.副本等. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.openSUSE.SU ...

  8. Unable to construct api.Node object for kubelet: can't get ip address of node master.example.com: lookup master.example.com on : no such host

    openshift首页进不去 启动openshift时报的错,大意是: 无法为kubelet构造api.Node对象:无法获取节点master.example.com的IP地址: 所以就联想到新装的c ...

  9. pjax转发

    pjax几大特点: 1.异步(ajax) 2.地址栏改变路径 3.实现前进和后退back和forword 如何解决:地址变了之后,万一F5刷新的问题,主要是通过后台判断是否为pjax请求,是的话做个标 ...

  10. Javascript 面向对象编程2:构造函数的继承

    这个系列的第一部分,主要介绍了如何"封装"数据和方法,以及如何从原型对象生成实例.对象之间的"继承"的五种方法.比如,现在有一个"动物"对象 ...