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

一、前言

  当在mapfile文件中定义PROJECTION对象时,MapServer将图层和投影信息传递给proj.4库执行重投影。详情请看:https://proj4.org/

  有数以千计的地理参考系统。为了将数据集与不同地理参考系统结合到地图中,必须将数据集转换(投影)到地图中选定的地理参考系统。

  PROJECTION在MapServe中,则是制定使用哪种地理残念考系统。(同属理解,就是你当前的数据是使用哪种坐标信息。)

  既然PROJECTION是用来指定数据所使用的坐标系信息,那么,它出现的位置就应该在需要使用显示数据的地方。

  第一个就是mapfile的MAP标签里面,用来定义输出坐标系;第二个位置就是LAYER标签里面,定义输入坐标系。

二、在MapServer中使用投影(Projections with MapServer)

  如果要使用PROJECTION,你必须在mapfile中MAP标签下面定义一个输出PROJECTION。然后每个LAYER里面必须定义输入坐标系。(注意是必须定义)

  PROJECTION对象是有一系列的PROJ.4库关键字构成。要么直接用关键书写;要么引用EPSG文件。格式如下。(EPSG详见:https://www.mapserver.org/glossary.html#term-epsg

  EPSG代码是与坐标系定义相关联的数字代码。如:EPSG:4326(EPSG:4326就是WGS84)

  ESPG相关资料:

#直接使用PROJ.4库关键字构建PROJECTION

PROJECTION
"proj=utm"
"ellps=GRS80"
"datum=NAD83"
"zone=15"
"units=m"
"north"
"no_defs"
END #通过EPSG构建PROJECTION
PROJECTION
"init=epsg:26915"
END

三、创建Example1.6站点

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

  在cmd中输入:cd Example1.6

  在cmd中输入:md data

  在cmd中输入:md fonts

  在cmd中输入:md symbols

  在cmd中输入:md logs

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

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

  在cmd中输入:cd data

  在cmd中输入:md raster

  将 app/tutorial/fonts 文件夹中的所有文件拷贝到 apps/Example1.6/fonts 文件夹中

  将 app/tutorial/symbols 文件夹中的 symbols35.sym 文件拷贝到 apps/Example1.6/symbols 文件夹中

  将 app/tutorial/data 文件夹中的 states_ugl.dbf、states_ugl.shp、states_ugl.shx 文件拷贝到 apps/Example1.6/data 文件夹中

  将 app/tutorial/data/raster 中的 mod09a12003161_ugl_ll_8bit.tif 文件拷贝到 apps/Example1.6/data/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>

  修改MapFIle(example1_6.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 PNG24
IMAGETYPE PNG
#EXTENT       -97.238976 41.619778 -82.122902 49.385620                      # WGS84            经纬度坐标数据
#EXTENT        201621.496941 -294488.285333 1425518.020722 498254.511514      # LAEA 原始官网mapfile中的数据
EXTENT         230147.11 -371641.81 1285308.08 632638.93                      # LAEA 自己通过命令计算的坐标数据
#EXTENT        -97.5 41.619778 -82.122902 49.38562                            # Geographic
SIZE 400 300
SHAPEPATH "./data"
SYMBOLSET "./symbols/symbols35.sym"
FONTSET "./fonts/fonts.list" # The projection object is typically used within the map and the layer
# objects. You only define it once within the map object and this definition
# becomes your output projection--MapServer will render your maps in this
# projection. You also use the projection object within the layer object to
# define your input projection. Your layers can be in different
# projections--MapServer will reproject them into your output projection.
# If no projection is defined within the layer object, MapServer assumes
# your input projection is the same as your output projection. This is not
# a required object unless you're creating a map file that supports one of
# the OGC interoperability web services specifications (WMS/WFS/WCS).
#
# This is the output PROJECTION definition ------
PROJECTION
# Projection parameters can be defined in two ways...
# This is the traditional PROJ.4 definition of Lambert Azimuthal Equal-Area
# projection for the Continental U.S.
"proj=laea"
"ellps=clrk66"
"lat_0=45"
"lon_0=-100" # Alternatively, you can specify an EPSG code.
# This is the EPSG code for Lambert Azimuthal Equal-Area
# projection for the U.S.
#
# "init=epsg:2163"
END # End of the output Projection definition --- # 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_polygon
DATA states_ugl
STATUS OFF
TYPE POLYGON # Here's an example of the input projection definition.
# EPSG:4326 is code for geographic (latlong) projection
# using the WGS84 datum.
#
# PROJECTION objects within the LAYER object define the input
# projection--this is the native projection of your data.
PROJECTION
"init=epsg:4326"
END # 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' # 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 # 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 here
NAME modis
DATA "raster/mod09a12003161_ugl_ll_8bit.tif"
STATUS OFF
TYPE RASTER
PROCESSING "BANDS=1,2,3"
OFFSITE 71 74 65 PROJECTION
"init=epsg:4326"
END
END # MODIS raster layer ends here LAYER # States line layer begins here
NAME states_line
DATA states_ugl
STATUS OFF
TYPE LINE PROJECTION
"init=epsg:4326"
END CLASSITEM "CLASS"
CLASS
NAME 'State Boundary'
EXPRESSION 'land'
STYLE
SYMBOL 'line5'
COLOR 64 64 64
SIZE 1
END
END
END # States line layer ends here LAYER # States label layer begins here
NAME states_label
DATA states_ugl
STATUS OFF
TYPE POLYGON PROJECTION
"init=epsg:4326"
END 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"
CLASS
EXPRESSION 'land'
STYLE
COLOR -1 -1 -1
END # 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.
LABEL
COLOR 132 31 31
#SHADOWCOLOR 218 218 218
#SHADOWSIZE 2 2
TYPE TRUETYPE
FONT arial-bold
SIZE 12
ANTIALIAS TRUE
POSITION CL
PARTIALS FALSE
MINDISTANCE 300
BUFFER 4
END # end of label
END # end of class
END # States label 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...

  在 IIS 中创建站点 Example1.6,端口为8016,应用程序池为 Example1.6

  设置应用程序池对 apps/Example1.6/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.6\logs" /grant "IIS AppPool\Example1.6":(OI)(CI)RW

  在浏览器中打开:http://localhost:8016/mapserv?map=../apps/Example1.6/example1_6.map&layer=states_polygon&layer=modis&layer=states_line&layer=states_label&mode=map

 四、EXTENT的改变

  查看mapfile(example1_6.map)文件后,首先,你会发现最明显的改变是 MAP 标签下面的 EXTENT 标签的数据。

  EXTENT 表示当前数据文件的显示范围。现在的显示方为值如下:

EXTENT       201621.496941 -294488.285333 1425518.020722 498254.511514

#Example1.5 中是:EXTENT         -97.238976 41.619778 -82.122902 49.385620

  为什么会发生这样的改变呢,应为我们修改了MapServer 的输出坐标系,即添加了 PROJECTION 对象。

  EXTENT对象的输出单位必须与 MapServer 中的输出坐标系一致。

  先前的坐标系是经纬度。现在 PROJECTION  设置为:

  # The projection object is typically used within the map and the layer
# objects. You only define it once within the map object and this definition
# becomes your output projection--MapServer will render your maps in this
# projection. You also use the projection object within the layer object to
# define your input projection. Your layers can be in different
# projections--MapServer will reproject them into your output projection.
# If no projection is defined within the layer object, MapServer assumes
# your input projection is the same as your output projection. This is not
# a required object unless you're creating a map file that supports one of
# the OGC interoperability web services specifications (WMS/WFS/WCS).
#
# This is the output PROJECTION definition ------
PROJECTION
# Projection parameters can be defined in two ways...
# This is the traditional PROJ.4 definition of Lambert Azimuthal Equal-Area
# projection for the Continental U.S.
"proj=laea"
"ellps=clrk66"
"lat_0=45"
"lon_0=-100" # Alternatively, you can specify an EPSG code.
# This is the EPSG code for Lambert Azimuthal Equal-Area
# projection for the U.S.
#
# "init=epsg:2163"
END # End of the output Projection definition ---

  现在的 PROJECTION 设置为:Lambert Azimuthal Equal-Area,其单位为米,所以我们现在的范围 EXTENT 也要设置为米。

  可以通过 ArcView、PROJ4 的 cs2cs 或其他GIS包做转换。下面的命令可用于重新投影原始范围值:

#第一步
#在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\tutorial\data
#在cmd中输入:ogrinfo -ro -al -so states_ugl.shp
#获取到states_ugl.shp 的范围信息:Extent: (-97.238976, 41.619778) - (-82.122902, 49.385620)。 Extent的格式为:<Lower Left X> <Lower Left Y> <Upper Right X> <Upper Right Y> #然后在cmd中输入下面的命令,回车 cs2cs +proj=latlong +datum=WGS84 +to +proj=laea +ellps=clrk66 +lat_0=45 +lon_0=-100 #执行当前计算转换,是在数据命令后,在输出原始范围的西南坐标值。即左下角坐标值,用空格分割开 -97.238976 41.619778 #回车后得到三个值,分别为:西南方向 X、Y、单位精度,其中第三个参数可以忽略。 230147.11       -371641.81 0.00 #接着再输入东北方向坐标参数 -82.122902 49.385620 #得到东北方向的转换输出范围: 1285308.08      632638.93 0.00 #所以转换后的EXTENT值为:
EXTENT 230147.11 -371641.81 1285308.08 632638.93

#转换完毕

#但是原始官网mapfile文件中给出的 EXTENT 值与计算值不符合。这是为什么呢?

EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514      # LAEA 原始官网mapfile中的数据

#因为地图在数据范围中并不居中,你可以适当的增加其范围,加以调整使其居中。官网案例是通过ArcView获取的。

  当使用自己计算的范围时和官网通过ArcView修改后的范围,其显示为分别如下:

    

  对比会发现,官网给定的做了相关边距接线的调整。

五、后记

  在做本样例中,对MapServer又有了新的认识:

    • 可以自定义投影坐标系的输出类型。
    • PROJECTION中是如何通过PROJ4关键词参数定义输出坐标系的。
    • PROJECTION是如何EPSG文件。
    • EPSG文件到底是个什么东西:http://www.epsg.org/
    • EPSG文件也可以自定义其目录位置。
    • PROJ4中cs2cs命令的使用
MAP
CONFIG "PROJ_LIB" "/usr/share/proj/" #UNIX的绝对路径,如果是未定义,则按照安装MapServer中的 E:\SvnWorkspace\LY_WEB_GIS\branches\Documents\ms4w-mapserver-for-wimdows\release-1911-x64-gdal-2-3-3-mapserver-7-2-1\bin\proj\SHARE 路径查找(个人理解)
PROJECTION
"init=epsg:3857"
END # PROJECTION
...

    后面还想写一篇关于关于PROJ4坐标转换的文章。一部一部学习。

  

MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.6 Defining Projections and Extents的更多相关文章

  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.5 Adding a raster layer

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

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

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

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

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

  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. appium1.4版本,每次运行appium时需要安装unlock,setting文件的解决方法

    在使用appium执行自动化脚本时,首次运行脚本时会在手机中安装unlock,setting,inputmanager三个apk,以达到让appium控制app的目的,但是运行完一次之后,在OPPO, ...

  2. LeetCode Weekly Contest 118

    要死要死,第一题竟然错误8次,心态崩了呀,自己没有考虑清楚,STL用的也不是很熟,一直犯错. 第二题也是在室友的帮助下完成的,心态崩了. 970. Powerful Integers Given tw ...

  3. P4174 [NOI2006]最大获利(网络流)

    P4174 [NOI2006]最大获利 还是最大权闭合子图的题 对于每个中转站$k$:$link(k,T,P_k)$ 对于每个用户$i$.中转站$A_i,B_i$.贡献$C_i$ $link(S,i, ...

  4. 2019-泰迪杯c题数据处理,WGS-84(世界标准地理坐标系) 转为 BD-09(百度地理坐标系)

    2019-泰迪杯c题数据处理,WGS-84(世界标准地理坐标系) 转为 BD-09(百度地理坐标系) 本次泰迪杯的数据为经纬度数据,并且题目给的是WGS-84(世界标准地理坐标系)格式的,所有如果调用 ...

  5. Python线程模块threading

    线程,程序执行的最小单元,单线程处理多个任务只能一个处理完后继续处理下一个直到全部处理完,多线程处理任务会比单线程处理起来快吗?在python程序里得看情况,首先有GIL锁的存在导致同一时刻只能有一个 ...

  6. bzoj2131 免费的馅饼——树状数组优化dp

    中文题目,问你最后能最多够得到多少价值的馅饼.因为宽度10^8且个数为10^5.所以不可以用dp[x][y]表示某时间某地点的最大权值. 假设你在x点处接到饼后想去y点接饼.那么需要满足的条件是t[y ...

  7. ArcGIS Pro开发Web3D应用(4)——Portal发布三维没有“发布”选项解决

    如题,将三维场景包.slpk上传并发布,未看到发布选项. 问题核心就在于环境没配置好,主要有2点: 1.验证联合托管状态 需要将托管服务器与Portal进行联合,并进行验证,此情况需要在WebAdap ...

  8. java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details

    Caused by: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Except ...

  9. 【设计模式】抽象工厂模式(Abstract Factory Pattern)

    [前言] 上次针对自己的理解书写一篇工厂模式的文章,后面对于工厂模式进行更加多的学习,于是了解到了抽象工厂模式.其实网上大多数人们都是抽象工厂模式是工厂模式的升级版本,虽然我并不知道所说的升级是什么意 ...

  10. 雷林鹏分享:Composer 安装

    下午在安装 Laravel 框架过程中,遇到了不少问题,因为 Laravel 的安装依赖于 composer,这里就先介绍一下 composer 的安装方法: 安装方法: #下载 sudo curl ...