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图像和多光谱图像(多层级multi-layer)。此示例演示如何选择使用多光谱数据时要显示的图层。官网地址:https://www.mapserver.org/tutorial/example1-5.html
注意 在使用RGB和多光谱图像时,可能会出现明显的性能问题。
因为MapServer5.x后使用AGG或GD2.x来生成输出的图像,它还支持RGB(24位或真彩色)输出。因此,除了8位(灰度图像或伪彩色图像)png8之外,现在还可以使用png(真颜色)进行输出。此示例使用PNG作为ImageType。
注意 与RGB输入一样,与PNG8相比,使用PNG时可能会出现明显的性能问题。
MapServer实际上也可以使用gdal生成输出图像,但这是另一个主题。如果您想了解更多信息,请查看mapfile引用中的outputformat对象。
二、创建站点Example1.5 Adding a raster layer
1.文件准备
在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.5
在cmd中输入:cd Example1.5
在cmd中输入:md data
在cmd中输入:md logs
在cmd中输入:md fonts
在cmd中输入:md symbols
在cmd中输入:cd.>web.config
在cmd中输入:cd.>example1_5.map
在cmd中输入:cd data
在cmd中输入:md raster
修改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>
将 app\tutorial\fonts 中的所有内容拷贝到 app\Example1.5\fonts 文件夹中(字体文件)
将 app\tutorial\data 中的 states_ugl.dbf、states_ugl.shp、states_ugl.shx 拷贝到 app\Example1.5\data 文件夹中(数据文件)
将 app\tutorial\symbols 中的 symbols35.sym 拷贝到 app\Example1.5\symbols 文件夹中(符号文件)
将 app\tutorial\data\raster 中的 mod09a12003161_ugl_ll_8bit.tif、mod09a12003161_ugl_ll_idxa.tif 拷贝到 app\Example1.5\data\raster 文件夹中(图层数据文件)
2.在IIS中创建站点Example1.5
应用程序池名称:Example1.5;站点端口:8015
3.给应用程序池读写log文件夹权限
在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.5\logs" /grant "IIS AppPool\Example1.5":(OI)(CI)RW
4.修改example1_5.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. MAPIMAGETYPE PNGEXTENT -97.238976 41.619778 -82.122902 49.385620SIZE 400 300SHAPEPATH "./data"IMAGECOLOR 255 255 255FONTSET "./fonts/fonts.list"SYMBOLSET "./symbols/symbols35.sym"# 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 hereNAME statesDATA states_uglSTATUS OFFTYPE 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.)CLASSNAME 'States'EXPRESSION 'land'# 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.STYLECOLOR 232 232 232ENDENDEND # States polygon layer ends here# In addition to vector data (shapefiles are vector data), MapServer supports# a host of raster formats. In GIS world, one of the most common raster# formats is GeoTIFF, a TIFF image with geospatial headers. MapServer also# supports JPEG, PNG, GIF, and other common formats. Other raster formats# supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,# Generic raster binaries, OGC Web Map Service (WMS) layers, etc. Pretty much# any raster format you can think of is probably supported, thanks to the# impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"# or GOODLE?). More information on GDAL is available at http://www.gdal.org.## MapServer 4.x can read and display bitmapped (like GIFs), RGB/A (true# color), and multispectral (images with more than 3 bands, like raw LandSat# images) rasters.LAYER # MODIS raster layer begins hereNAME modisDATA "raster/mod09a12003161_ugl_ll_8bit.tif"STATUS OFFTYPE RASTERPROCESSING "BANDS=1,2,3"OFFSITE 71 74 65END # MODIS raster layer ends hereLAYER # States line layer begins hereNAME states_lineDATA states_uglSTATUS OFFTYPE LINECLASSITEM "CLASS"CLASSNAME 'State Boundary'EXPRESSION 'land'STYLESYMBOL 'line5'COLOR 64 64 64SIZE 1ENDENDEND # States line layer ends here# Labels can be defined in its own layer. This is useful if, say, you want# to label a polygon layer that's covered by another layer. By keeping the# label separate from the polygon and placing it near the bottom of the map# file (so its drawn on, or near the, top), you can still see the label even# though you might not be able to see the polygon. It is also a good# alternate to point symbols.## A label layer is actually defined with ANNOTATION type (This is derived from# points, Node IDs for lines, or polygon IDs).LAYER # States label layer begins hereNAME states_labelDATA states_uglSTATUS OFFTYPE POLYGON #ANNOTATION 此类型的LAYER已经被移除。此处需要表达的是标签,请查看上一章《MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map》 #LAYER 官网:https://www.mapserver.org/mapfile/layer.html ,定位到 TYPE 对象处查看。CLASSITEM "CLASS"# Just like CLASSITEM, LABELITEM defines the 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"CLASSEXPRESSION 'land'STYLECOLOR -1 -1 -1END# There can be labels in a class, just like there are classes in a layer,# just like there are layers in a map. You can define multiple labels in# a class just as you can define multiple classes in a layer and multiple# layers in a map.# MapServer has a very flexible labeling system. With that flexibility# comes complexity, specially when using truetype fonts. Please read# through the LABEL section of the MapServer map file documentation at# http://www.mapserver.org/mapfile for more information.LABELCOLOR 132 31 31#SHADOWCOLOR 218 218 218 # deprecated, use STYLE and GEOMTRANSFORM#SHADOWSIZE 2 2 # deprecated, use STYLE and GEOMTRANSFORMTYPE TRUETYPEFONT arial-boldSIZE 12ANTIALIAS TRUEPOSITION CLPARTIALS FALSEMINDISTANCE 300BUFFER 4END # end of labelEND # end of classEND # States label layer ends here# End of LAYER DEFINITIONS -------------------------------DEBUG 5CONFIG "MS_ERRORFILE" "logs\ms.log" END # All map files must come to an end just as all other things must come to...
5.浏览查看
在浏览器中输入:http://localhost:8015/mapserv?map=../apps/Example1.5/example1_5.map&layer=states&layer=modis&layer=states_line&layer=states_label&mode=map
三、MapFile文件解析
1.文件结构
MAPLAYER #1-------------LAYER #2----|----LAYER #3--------LAYER #4(states) (modis) (states_line) (states_label)| | | (land) CLASS-|-CLASS (water) |-CLASS |-CLASS| | | |STYLE-| |-STYLE |-STYLE STYLE-|-LABEL
当前案例分为四个图层:
- tsates用来展示几何区域
- modis展示tiff图像文件,栅格数据
- states_line展示的是CLASSITEM=CLASS,EXPRESSION=land 的线条数据,其中线条符号为 line5
# 12 Symbol NAME 'line5' Type VECTOR TRANSPARENT 0 Points 1 0 0 1 0 1 1 0 END END #line的数据类型为 VECTOR 矢量数据,详情请看:https://www.mapserver.org/mapfile/symbology/construction.html中 Symbols of TYPE vector and ellipse#同时,请查看:https://www.mapserver.org/mapfile/symbol.html#此处可以理解为构建了一个矢量区域,有个坐标系,点(1,0)、(0,1)、(0,1)、(1,0)画了一个矩形,然而此矩形看起来没有宽度,长为 2 的开方(三角形勾股定理)#同时,将这个矢量矩形(看起来就是短的线)中心基于 dbf 数据中 CLASS = land 的 POLYGON 中的点数据来展示,这样看起来就给 land 外面画了一个线。
2.对象参数解释
IMAGETYPE
MapServer生成输出数据的格式。在cmd中输入:mapserv -v 查看。值PNG是值输出24位PNG或真色PNG。
SYMBOLSET
SYMBOL集合的文件位置。可以使绝对路径,也可以是和mapfile(example1_5.map)的相对路径。字符集位置。可以先了解一下SYMBOL,资料如下:
SYMBOL的讲解:https://www.mapserver.org/mapfile/symbol.html
创建字符集文件:https://www.mapserver.org/mapfile/symbology/construction.html
DATA raster/mod09a12003161_ugl_ll_8bit.tif
在NAME为modis的图层中,添加的是一个GeoTIFF图层数据。MapServer支持矢量数据和栅格数据。这个图层为栅格类型。这个图层是通过GDAL的库来完成支持的。MapSeerver上不同的栅格支持和生成请查看:https://www.mapserver.org/input/raster.html#raster
modis数据了解请进:https://modis.gsfc.nasa.gov/
TYPE RASTER
在NAME为modis的图层中,当前LAYER的数据类型。此处使用的是RASTER。同时在LAYER中,MapServer还支持POLYGON,LINE,POINT,LABEL中支持ANNOTATION等。
PROCESSING "BANDS=1,2,3"
这个位置我觉得很难理解。查了相关资料。大概意思是,MapServer调用GDAL库来处理tiff图像,并输出显示。
PROCESSING表示进程。根据进程值来决定调用那个库。请查看:https://www.mapserver.org/mapfile/layer.html 中PROCESSING 段落。
BANDS表示波段,GDAL源码中通过RasterIO来读取波段数据。
TIFF文件时位图,在windows中的存储格式为BGR,然后MapServer根据参数调用时,对参数做了调整顺序的相关处理。1,2,3表示Red,Green和blue三种波段选择。
具体的我也不大清楚,总之尝试后,发现1,2,3在浏览器中显示的是和直接看到tiff相差不远,只是灰色的底色变成白色的。
同时也请查看:https://www.mapserver.org/input/raster.html 中 BANDS=red_or_grey[,green,blue[,alpha]] 处的解释。
OFFSITE
设置当前LAYER层的背景颜值组成。(Sets the color index to treat as transparent for raster layers.)
告诉MapServer按照像素值渲染背景(或忽略)。
想了半天没弄懂,最后乱改这个值也没发现什么。知道读到or ignore之后。忽略,这个tif文件正好背景颜色值RGB是:71 74 65 ,是否设置OFFSITE值和背景颜色值一样时,做忽略处理。
但是在设置为其他颜色值时,却还是显示当前tif文件的背景颜色。这就十分尴尬了,是否是因为当前tif文件有背景颜色,然后将OFFSITE设置的颜色给覆盖了。
颜色组成分多种形式,当前案例是:Indexed Color Image(伪彩色图像)。还有:RGB、RGBA等。
四、RGB vs Indexed Color Image 真彩色和伪彩色的对比
1.关于伪彩色,可以查看:https://en.wikipedia.org/wiki/Indexed_color
2.修改mapfile的相关配置,将
DATA "raster/mod09a12003161_ugl_ll_8bit.tif" STATUS DEFAULT TYPE RASTER PROCESSING "BANDS=1,2,3" OFFSITE 71 74 65
修改为
DATA "raster/mod09a12003161_ugl_ll_idxa.tif" STATUS DEFAULT TYPE RASTER OFFSITE 70 74 66
看看效果
显示的效果已经改变。去掉GDAL的程序处理后,也不显示背景色了。
五、后记
感觉模拟样例做一个很简单,但是弄清楚相关的mapfile对象却很头痛,涉及的知识点太多,不理解的位置太多。比如:OFFSITE就不动。继续深入学习,相信随着了解的越来越多,就会知道其作用。
转载于:https://www.cnblogs.com/eshinex/p/10291336.html
MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.5 Adding a raster layer...相关推荐
- Normalizing Flows Tutorial(标准化流教程)第一部分
0.背景 0.0 交代故事 你是个机器学习从业者,正苦哈哈地研究着产生式模型.贝叶斯深度学习.深度强化学习之类的玩意儿,趁手的工具捉襟见肘.今天我就给你带一件儿不错的东西:标准化流,相信我,它会武装你 ...
- SQL基础教程学习第六站:数据更新
仅用于记录学习,欢迎批评指正,共同交流,共同进步,大神勿喷 系列文章 SQL基础教程学习第一站:PostgreSQL下载安装以及如何创建并登录数据库: SQL基础教程学习第二站:数据库基本知识: SQ ...
- 一站式SpringBoot for NoSQL Study Tutorial 开发教程学习手册
SpringBoot2.0 + NoSQL使用教程,项目名称:"SpringBoot2NoSQL" 项目地址: https://gitee.com/475660/SpringBoo ...
- keras构建卷积神经网络_通过此简单教程学习在网络上构建卷积神经网络
keras构建卷积神经网络 by John David Chibuk 约翰·大卫·奇布克(John David Chibuk) 通过此简单教程学习在网络上构建卷积神经网络 (Learn to buil ...
- 【从零开始的大数据学习】Flink官方教程学习笔记(一)
Flink官方教程学习笔记 学习资源 基础Scala语法 Scala数据结构专题 声明变量 代码块 函数(function) 方法(methods) Traits (接口) class(类) tupl ...
- Arduino可穿戴教程之第一个程序——Blink(一)
Arduino可穿戴教程之第一个程序--Blink(一) 至此我们的硬件和软件部分都准备好了,是时候测试一下他们是否可以和谐地合作了.当然,第一个程序我们并不需要自己来写,因为我们还没有了解过Ardu ...
- python菜鸟教程字典-python教程菜鸟教程学习路线
python教程菜鸟教程学习路线,需要学Python 环境搭建.Python 中文编码.Python 基础语法.Python 变量类型.Python 运算符.Python 条件语句.Python 循环 ...
- jQuery框架学习第一天:开始认识jQuery
jQuery框架学习第一天:开始认识jQuery jQuery框架学习第二天:jQuery中万能的选择器 jQuery框架学习第三天:如何管理jQuery包装集 jQuery框架学习第四天:使用jQu ...
- python基础开发环境_Python基础教程,第一讲,开发环境搭建
今天是写Python基础教程的第一课,也是下定决心做技术分享的第一篇文章.先扯几句和技术无关的吧,也便于大家了解这套课程的内容,适不适合自己学习,我做开发6年了,已年过30,一直从事的WEB方面的开发 ...
最新文章
- 4399积分小游戏_分数提交规则
- 东风畅行java_东风畅行载货车为何可以口碑很好吗?是配置高?或者另有原因?...
- 将来时态:I will fly - I'm going to fly - I'm flying_48
- 使用NPM和Nodejs编写编译工具
- Vue 路由懒加载
- 详解:IDEA不能自动加载import问题
- linux+yum安装终端php,centos下yum搭建安装linux+apache+mysql+php环境教程
- C#曲线分析平台的制作(二,echarts前后台数据显示)
- 408计算机考研2012真题解析,2018年计算机408统考考研真题及答案解析.pdf
- Excel数据的筛选
- Win7下安装ubuntu14.10系统
- Fiddler调式使用(一)深入研究[转载]
- 如何用tushare复盘
- ROS装乐视奥比中光(astra pro)摄像头
- 如何把时间转换为时间戳?
- 基于python+pyqt+halcon实现视觉定位(halcon12.0)【附部分源码】
- 情怀被消费完了,共享民宿靠什么坚守岗位?
- SSD固态硬盘安装后:AS SSD Benchmark检测pciide-BAD解决办法
- 超简单的统计结果可视化工具,推荐~~
- CC1310低功耗高速率Sub1G微控制器芯片CC1310F128RSMR
热门文章
- 树莓派各版本配置对比
- LINUX脚本报错捕捉,Linux01-BASH脚本编程之信号捕捉及任务计划53
- clistctrl 单机空白处 会取消选中_官方默许BUG:无法选中也能被控制?这些秘密很多玩家到现在都没发现!...
- 安卓应用用户数据_Android手机用户注意,你要知道的中国十大安卓应用商店
- unity 安卓 后台运行_iOS14多任务界面放出,类似iPad,实现安卓锁定后台的功能?...
- 基于android的视频采集系统的设计与实现,基于Android的视频通话系统的设计与实现.docx...
- python selenium鼠标点击_Python+Selenium学习--鼠标事件
- python语言的作者是_Python是一门动态语言
- java 拼sql最大长度,java.sql.SQLNonTransientConnectionException: 用户 ID 长度 (0) 超出 1 到 255 的范围...
- php 获取文件扩展名的方法,PHP获取文件扩展名的4种方法,_PHP教程