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/tutorial/example1-2.html#example1-2

  翻译对于我而言只是一个过程,主要是自己边翻译,边实践,边记载。

二、实现 Static Map with Two Layers

  1.Static Map with Two Layers例子实践前说明

    

    上一个例子中,通过打开:http://localhost:8011/mapserv?map=../apps/Example1.1/example1_1.map&layer=states&mode=map实现地图图片的生成。这是本节中大多数例子工作方式。

    但是Static Map with Two Layers 这个例子的mapfile文件不一样。

  2.准备创建站点

    老规矩,老规则。在E:\SvnWorkspace\LY_WEB_GIS\branches\Documents\ms4w-mapserver-for-wimdows\release-1911-x64-gdal-2-3-3-mapserver-7-2-1\apps文件夹下面创建Example1.2文件夹

    在Example1.2文件下面创建data、logs文件夹,以及 web.config、example1_2.map文件

    在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.2

    在cmd中输入:cd Example1.2

    在cmd中输入:md data

    在cmd中输入:md logs

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

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

    web.config文件如下:

1 <?xml version="1.0" encoding="UTF-8"?>
2 <configuration>
3     <system.webServer>
4         <handlers>
5             <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=""  />
6         </handlers>
7         <caching enabled="true" enableKernelCache="true" />
8     </system.webServer>
9 </configuration>

    example1_2.map格式如下:

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

    # 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"

      # 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

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

    CLASS
      NAME       "State Boundary"
      STYLE
        COLOR    255 0 0
      END
    END
  END # States line layer ends here
  # End of LAYER DEFINITIONS -------------------------------
  DEBUG 5
  CONFIG "MS_ERRORFILE" "logs\ms.log"
END 

    打开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.1\logs" /grant "IIS AppPool\Example1.2\logs" :(OI)(CI)RW

    是MapServer对logs文件夹有读写权限

    在浏览器中输入:http://localhost:8012/mapserv?map=../apps/Example1.2/example1_2.map&layer=states_poly&layer=states_line&mode=map

    

  3.URL参数说明

    map=../apps/Example1.2/example1_2.map 表示 MapServer 与 mapfile(example1_2.map)的相对路径

    layer=states_poly 表示打开 NAME 值为 states_poly 的 polygon(多边形)layer层

    layer=states_line 表示打开 NAME 值为 states_line 的 line(线)layer层

    mode=map 表示告诉MapServer对mapfile文件的输出格式,这里是告诉MapServer直接将图像投影到浏览器,无需先在服务器端创建零时的图像。

    在 mapfile(example1_2.map)中 NAME 值为 states_line 的 line(线)layer层的 CLASS 对象的 COLOR    255 0 0 表示红色,顾浏览器中的边线为红色。

三、Mapfile结构解释说明

  其结构如下:

           MAP
      LAYER-|-LAYER
   CLASS-|     |-CLASS
STYLE-|           |-STYLE

  在这个mapfile里面,我们将原始层分为两层。第一层是多边层(polygon)layer,但是第一层没有边线颜色(OUTLINECOLOR)设置。(其实通过OUTLINECOLOR设置第一个层也可以实现上图红色边线的视觉效果,但是现在学习的是用两个层来表示)。

  第二个层将TYPE对象值由POLYGON修改为LINE,然后设置了 COLOR 对象值为 255 0 0 表示红色。

  那么TYPE对象有几种值,然后又是如何区分的呢?详见:https://www.mapserver.org/mapfile/layer.html

  其中对TYPE对象的定义如下:

    TYPE [chart|circle|line|point|polygon|raster|query](这个中括号里面竖线分割的就是TYPE对象的各种值)
      Specifies how the data should be drawn. Need not be the same as the shapefile type. For example, a polygon shapefile may be drawn as a point layer, but a point shapefile may not be drawn as a polygon layer. Common sense rules.

      In order to differentiate between POLYGONs and POLYLINEs (which do not exist as a type), simply respectively use or omit the COLOR keyword when classifying.

      If you use it, it’s a polygon with a fill color, otherwise it’s a polyline with only an OUTLINECOLOR.

      A circle must be defined by a a minimum bounding rectangle. That is, two points that define the smallest square that can contain it. These two points are the two opposite corners of said box. The following is an exampl using inline points to draw a circle:

LAYER
  NAME ‘inline_circles‘
  TYPE CIRCLE
  STATUS ON
  FEATURE
    POINTS
      74.01 -53.8
      110.7 -22.16
    END
  END
  CLASS
    STYLE
      COLOR 0 0 255
    END
  END
END

     TYPE query means the layer can be queried but not drawn.

    Note TYPE annotation has been deprecated since version 6.2. Identical functionality can be obtained by adding LABEL level STYLE blocks, and do not require loading the datasets twice in two different layers as was the case with layers of TYPE annotation.

    See also The Dynamic Charting HowTo for TYPE chart.

    (后续我也肯定会写各种TYPE值的实现,毕竟是自己学习的过程)

四、为什么这么做而不直接在第一个层中定义OUTLINECOLOR呢?

  如果我们继续在状态层的顶部添加层,那么轮廓很可能会被这些其他层覆盖。为了在添加这些其他层之后仍能看到状态边界,我们必须将状态边界线层与状态多边形层分离,并将其放在其他层的顶部。我们如何定义/添加层是有顺序的。

五、后记

  这节案例中,其实学到的东西分为以下几点:

    1.强化记忆了mapfile的应用

    2.对 LAYER 对象中 TYPE 对象有了更加明确的认识

    3.运用了多个层,知道为什么要这么用。目前还不明白MapServer中,层的顺序是否是按照mapfile中定义的顺序加载的。如:一个layer是最下面,然后一级一级的网上放。有待资料查询和证实。

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

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

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

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.3 Displaying Classes in a Layer

MapServer Tutorial--MapServer7.2.1教程学习--第一节用例实践:Example1.3 Displaying Classes in a Layer 一.前言 关于第一节的案例,分别介绍了一个基本的地图站点应用程序创建和多图层地图站点 应用程序创建.这个案例 主要来介绍一下mapfile文件中 LAYER 对象里面,CLASS对象的应用. 同时还有如何根据CLASSITEM.EXPRESSION等配置去修改地图的显示方式. 最后还有一个很酷炫的方法一次性读取shp文件

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进行数据编辑.整饰和输出的流程 · 如何使用