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. 小程序movable-area置于顶层遮盖下方元素无法操作的解决方案

    小程序项目中有个需求,右下角按钮可以在页面中随意拖动,此时查看文档找到了一个自带的标签可以实现此功能,代码如下 <movable-area> <movable-view x=&quo ...

  2. 基于usb4java的usb通讯

    下载java API及lib库地址:http://usb4java.org/index.html 1.导入所需要的库: 2.添加配置文件:文件名:javax.usb.properties:内容:jav ...

  3. shiro学习总结

    首先4个比较好的例子供参考: 1.常规Spring MVC拦截器实现的认证和权限管理例子 https://blog.csdn.net/u013647382/article/details/539956 ...

  4. https://github.com/tensorflow/models/blob/master/research/slim/datasets/preprocess_imagenet_validation_data.py 改编版

    #!/usr/bin/env python # Copyright 2016 Google Inc. All Rights Reserved. # # Licensed under the Apach ...

  5. python_WSGI接口

    WSGI:Web Server Gateway Interface WSGI接口定义非常简单,它只要求Web开发者实现一个函数,就可以响应HTTP请求.我们来看一个最简单的Web版本的“Hello, ...

  6. mybatis源码解析11---ParameterHandler解析

    ParameterHandler接口是参数处理器,位于mybatis包的org.apache.ibatis.executor.parameter下,源码如下: public interface Par ...

  7. flask_mail发送163邮件,报553错误的原因

    最近在练习用flask_mail发送163邮件时报错: reply: '553 authentication is required,163 smtp9,DcCowAD3eEQZ561caRiaBA- ...

  8. Field amqpTemplate in * required a single bean, but 3 were found:

    Field amqpTemplate in * required a single bean, but 3 were found: Spring Boot 启动的时候报的错 使用Spring Boot ...

  9. 怎样从外网访问内网Sysbase数据库

    外网访问内网Sysbase数据库 本地安装了Sysbase数据库,只能在局域网内访问,怎样从外网也能访问本地Sysbase数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Sys ...

  10. 第五讲 DOM基础

    DOM基础: 什么是DOM:其实就是dovument,div获取.修改样式等等,但是不只是js的组成部分,而且还是一套规范,规定了这些浏览器怎么处理这些操作: 浏览器支持情况:IE(IE7-8,10% ...