第二章 Tutorial 教程

MapServer Tutorial MapServer教程

  • Tutorial background 教程背景
  • Section 1: Static Maps and the MapFile 第一阶段:静态地图Maps和地图文件MapFile
  • Section 2: CGI variables and the User Interface 第二阶段:CGI变量和用户界面
  • Section 3: Query and more about HTML Templates 第三阶段:查询和HTML模板
  • Section 4: Advanced User Interfaces 第四阶段:增强用户界面

Tutorial background教程背景

  • Tutorial Timeframe 教程时间框架

虽然有些用户可以在一天内完成本教程,但那些详细研究每个示例的用户可能期望在一周内完成本教程。

  • Tutorial Data 教程数据

本教程中使用的数据集取自美国内政部a zs美国国家地图集(现在由data.gov托管)。数据集被裁剪到上五大湖地区(明尼苏达州、密歇根州和威斯康星州),以减少存储空间。额外的光栅图像是由明尼苏达大学的Terrasip项目提供的。使用本教程时,鼓励您使用自己的数据集。

与MapServer本身一样,本教程对任何人都是开放的和可自定义的。这样做的目的是希望有人(或某些人)能够帮助设计和进一步开发它。

在http://download.osgeo.org/mapserver/docs/mapserver-tutorial.zip下载本教程的数据(以及所有HTML文件)。

  • Before Using the Tutorial 在使用本教程之前

使用本教程有一些先决条件:
1。用户需要在其计算机上安装并运行Web服务器。此Web服务器必须支持通用网关接口(CGI)程序。
2。用户应该对Web服务器和Internet安全有基本的了解。配置不正确的Web服务器很容易被恶意的人攻击。你的软件安装会失败你zll会损失数小时的工作效率,最坏的情况是你的电脑可以用来攻击互联网上的其他电脑。
3。建议本教程的用户在继续此操作之前先阅读MapServer简介。
4。要使用本教程,用户需要在他们的系统。MapServer源代码可在此处下载。关于如何编译的文档已经存在并安装MapServer:
•对于Unix用户,请阅读MapServer Unix编译和安装指南。
•Windows用户应阅读MapServer Win32编译和安装指南
此外,许多平台都存在预编译的二进制文件(请参见下载页)。

Windows, UNIX/Linux Issues  Windows、Unix/Linux问题

Paths

路径

本教程是在Linux/Unix上创建的,但是应该在Windows平台上进行最小的更改。主要区别在于map文件中的路径。Windows用户需要指定其教程文件所在硬盘的驱动器号。这里是一个例子:

Unix地图文件可能包含如下参数:

在Windows中,相同的参数可能如下所示:

或者:

请注意,斜杠或反斜杠在Windows中都有效。如果您想区分映射文件中的虚拟路径(如URL或Web地址)和本地路径,通常的反斜杠可能对您很有用。但是,如果您计划在某个时间点将应用程序移动到Unix,那么您的zll有一项单调的任务,即将所有反斜杠切换为斜杠。

当我们讨论路径的主题时,请记住,map文件中的路径通常与系统的根目录相关:UNIX中的斜杠(_aij/_ a i)或Windows中的某些驱动器号(_aijc:_ a i)。这是正确的,除非特别要求输入URL或引用URL。使用HTML模板文件时,路径是相对于Web服务器的根目录。也就是说,“/tutorial/“是相对于“https://demo.mapserver.org/“的。请阅读http://www.alistaparate.com/articles/slashforward/了解有关URL的一些细节。

Executable

可执行文件

另一个问题是,Unix可执行文件不需要.exe或.com扩展名,但在Windows中需要。如果您使用的是Windows,请将.exe附加到所有实例中的”/cgi bin/mapserv“或”/cgi-bin/mapserv“改为"cgi-bin/mapserv.exe"或"/cgi-bin/mapserv50.exe "。

Other Resources 其他资源
还有其他文档可以让您更好地了解MapServer提供的许多定制。请访问MapServer文档页面:http://www.mapserver.org/documentation.html。在这里,您可以找到几个howto文档,从入门到使用mapscript,这是一个针对mapserver的脚本接口。

Section 1: Static Maps and the MapFile

• 拿个shapefile,任何人我们可以用鼠标在一个浏览器上显示该shapefile形状文件。看:

– Example 1.1 - A map with a single layer:http://localhost/tutorial/example1-1.html

mapserver可以创建一个地图并将其转储到本地目录,或者直接发送到请求的Web浏览器,如本例所示。您可以在不需要HTML页面的情况下查看它,只需输入以下URL:http://<insert hostname or ip address here>/cgi bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1.map&amp;layer=states&amp;mode=map(记住将“<insert hostname or ip address here>”替换为Web服务器的名称,例如“localhost”,或其IP地址,例如“127.0.0.1”)。

这个URL可以分为三部分:第一部分,http://<insert hostname or ip address here>/cgi bin/mapserv.exe?,调用mapserver cgi程序。如果您按原样调用它,您将得到这个熟悉的消息:

No query information to decode. QUERY_STRING is set, but empty.

接下来的三个部分是组成查询字符串的部分。查询字符串包含CGI参数(变量及其值),每个参数由一个与(&amp;)分隔。因此,查看查询字符串,第一个参数“map”有一个值“/ms4w/apps/tutorial/htdocs/example1-1.map”--这告诉mapserver cgi程序(mapserv或mapserv.exe)要处理/解析什么mapfile。下一个参数“layer=states”告诉mapserv.exe“打开”状态层——回想一下,我们将层对象命名为“states”。最后一个参数“mode=map”告诉mapserv.exe如何处理来自mapfile的输出。在本例中,它告诉mapserv.exe直接将映像转储到Web浏览器(客户端),而不首先在服务器上创建临时映像。mapserver“模式”cgi变量可以采用“map”以外的值。例如,如果使用“mode=browse”,mapserver将把映像转储到服务器上的临时目录。浏览模式现在不起作用,但稍后我们将再次使用。

这是map文件的外观(例如1-1.map):

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. IMAGETYPE PNG
  14. EXTENT -97.238976 41.619778 -82.122902 49.385620
  15. SIZE
  16. SHAPEPATH "../data"
  17. IMAGECOLOR
  18.  
  19. # Layer objects are defined beneath the map object. You need at least one
  20. # layer defined in your map file before you can display a map... You can
  21. # define as many layers as you'd like although a limit is typically hard-coded
  22. # in map.h in the MapServer source. The default limit is set at . You'd
  23. # have to have a very specialized application to need more than layers in
  24. # your application.
  25.  
  26. # Start of LAYER DEFINITIONS ---------------------------------------------
  27. LAYER # States polygon layer begins here
  28. NAME states
  29. DATA states_ugl
  30. STATUS OFF
  31. TYPE POLYGON
  32.  
  33. # The class object is defined within the layer object. You can define as
  34. # many classes as you need (well, there are limits as with layers, but it's
  35. # senseless to define more than ten on a "normal" layer. There are
  36. # situations, however, where you might have to do it.)
  37. CLASS
  38. NAME "The Upper Great Lakes States"
  39.  
  40. # There are styles in a class, just like there are classes in a layer,
  41. # just like there are layers in a map. You can define multiple styles in
  42. # a class just as you can define multiple classes in a layer and multiple
  43. # layers in a map.
  44. STYLE
  45. COLOR
  46. OUTLINECOLOR
  47. END
  48. END
  49. END # States polygon layer ends here
  50. # End of LAYER DEFINITIONS -------------------------------
  51.  
  52. END # All map files must come to an end just as all other things must come to...

mapfile是mapserver的基本配置机制。它由“对象”组成,每个对象可以有关键字或其他对象。它有一个层次结构,一些对象落在其他对象之下…在这个层次结构的顶部是映射对象,所有其他对象都属于它。这个例子显示了对象的一个非常直接的继承关系。当您通过每个示例时,这些层次树的复杂性将增加。

关于mapfiles的一些简短说明:我们用对象名定义mapfile中的每个对象,并用“end”关闭它,在注释前面加上一个磅()符号。

让我们按对象分解“example1-1.map”。其结构如下:

让我们看下Map文件中的关键字:

MAP地图
每个MAP地图文件都以MAP开始——整个地图文件就是MAP地图对象。

IMAGETYPE图像类型
关键字imagetype用于定义mapserver cgi程序应用于输出的图像格式。在本例中,我们使用索引颜色png(类似于gif)。如果我们使用gif支持、wbmp或jpeg编译gd库,这可能是gif。我们还可以指定其他输出选项(pdf、swf、geotiff),前提是我们编译了对它们的支持并使用outputformat对象指定它们。输出格式超出了本教程的范围,但您可以通过阅读MapServer网站中的文档了解更多信息。

EXTENT范围
此参数指定地图的输出范围——初始地图的边界框。范围值按以下格式给出:<lower left x><lower left y><upper right x><upper right y>,每个值之间用空格分隔。这需要与数据使用相同的单位,或者,如果指定了不同的输出投影,则需要与输出投影使用相同的单位。

在这个例子中,我们的数据是地理投影的,所以单位是十进制的。您可以使用作为gdal/ogr库包一部分的实用程序“ogrinfo”来获取特定形状文件(或其他支持的矢量格式)的范围。下面是我用于获取此示例范围的命令:

  1. ogrinfo -al -so states_ugl.shp

这将返回以下输出:

  1. INFO: Open of `states_ugl.shp'
  2. using driver `ESRI Shapefile' successful.
  3.  
  4. Layer name: states_ugl
  5. Geometry: Polygon
  6. Feature Count:
  7. Extent: (-97.238976, 41.619778) - (-82.122902, 49.385620)
  8. Layer SRS WKT:
  9. (unknown)
  10. AREA: Real (12.3)
  11. PERIMETER: Real (12.3)
  12. STATESP020: Real (11.0)
  13. STATE: String (20.0)
  14. STATE_FIPS: String (2.0)
  15. CLASS: String (5.0)

您还可以使用ArcView或其他开源的GIS包——Quantum GIS、Thuban等。
请随意更改范围的值,以便更好地了解它如何更改您的地图。

SIZE 尺寸
这是MapServer将生成的图像(地图)的大小(像素)。所以我们的地图是400像素宽,300像素高。再次,把它改为你喜欢的内容,看看它是如何影响你的地图的。

SHAPEPATH 形状路径
这是到数据层的路径。您可以提供绝对路径(即“/ms4w/apps/tutorial/data”或“c:/ms4w/apps/tutorial/data”)或相对于map地图文件位置的路径(在本例中,您将使用“../data”)。此路径不必是可访问Web的,除非您希望任何人下载您的原始数据,否则可能不应该是。它与Web没有直接关系,因此在这里甚至不要考虑URL——只需确保运行Web服务器的用户(通常是*nix世界中的“nobody”或“apache”)可以读取shapepath中的数据。

IMAGECOLOR 图像颜色
这是地图的背景色。这些值是RGB值,因此255红色、255绿色和255b会产生白色背景。继续玩这个value。

现在让我们看看图层对象参数:

Layer图层
标记地图对象中图层的开始。尽管默认情况下限制为100,但可以指定任意多个层。要更改此限制,必须编辑map.h头文件(在soure树中)并重新编译mapserver。

NAME名字
这是层标识符。MapServer使用此名称打开和关闭图层。在本例中,它不起作用,因为我们将图层状态STATUS属性设置为默认。在后面的例子中我们将回到这个问题。

DATA数据
数据的名称(本例中为shapefile)。请阅读MapServer矢量数据指南以了解有关如何访问MapServer中的矢量数据的更多信息。

MAPServer通过使用ogr库(gdal软件包的一部分)支持ESRI的shapefile以外的矢量数据格式。请访问gdal项目网站http://www.gdal.org/并阅读http://www.gdal.org/ogr/ogr_formats.html,了解有关各种支持的ogr格式的更多信息。

TYPE类型
它是什么类型的数据?如果是矢量数据,则可以指定它是多边形、直线(即使数据在技术上是多段线,也可以使用直线)还是点。也可以指定光栅或注释数据。这里我们要显示多边形。

STATUS状态
层根据其状态打开或关闭。DEFAULT默认值始终为“开”。当层名称作为查询字符串的一部分传递时,打开或关闭工作。

让我们看看CLASS类对象参数:

CLASS类
标记Layer层对象中CLASS类对象的开头。您可以在一个层中指定任意多个类,尽管默认情况下限制为50个类。您必须重新编译mapserver才能更改此默认值。

NAME名字
此类的描述性标识符。图层对象可以有多个类,就像地图对象可以有多个图层一样。MapServer将类名用作图例的标签,因此在命名类时请确保使用适当的描述性名称。我们稍后将在本教程中讨论图例。

最后,我们来看一下STYLE样式对象参数:

STYLE风格
标记样式对象的开始。您可以在一个类中定义多个样式——当您想将一个样式覆盖到另一个样式上时,这很有用。

COLOR颜色
这是多边形的填充颜色。如果类型是line,这是line颜色。这些值采用RGB格式。

OUTLINECOLOR轮廓颜色
这是多边形的轮廓颜色。这些值采用RGB格式。默认情况下,MapServer不绘制多边形轮廓,因此如果要查看多边形边界,则需要定义一个大纲颜色。

这结束了本教程中的第一个示例。建议您更改映射文件中关键字的值。它将帮助您理解这些关键字的作用。

Example 1.2: Static Map with Two Layers

• 我们可以重复显示相同的shapefile数据集。我们可以在一个图层中显示多边形属性,在另一个图层中显示线条属性。˘

– Example 1.2 - A map with two layers

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-2.map&layer=states_poly&layer=states_line&mode=map

与第一个示例一样,此图像是通过将<img>标记的源链接到此URL生成的。这就是本节中大多数示例的工作方式。

无论如何,您会注意到这里的地图与第一个示例相同。是的,但地图文件不同。看看。

这是映射文件的外观(example 1-2.map):

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. IMAGETYPE PNG
  14. EXTENT -97.238976 41.619778 -82.122902 49.385620
  15. SIZE
  16. SHAPEPATH "../data"
  17. IMAGECOLOR
  18.  
  19. # Layer objects are defined beneath the map object. You need at least one
  20. # layer defined in your map file before you can display a map... You can
  21. # define as many layers as you'd like although a limit is typically hard-coded
  22. # in map.h in the MapServer source. The default limit is set at . You'd
  23. # have to have a very specialized application to need more than layers in
  24. # your application.
  25.  
  26. # Start of LAYER DEFINITIONS ---------------------------------------------
  27. LAYER # States polygon layer begins here
  28. NAME states_poly
  29. DATA states_ugl
  30. STATUS OFF
  31. TYPE POLYGON
  32.  
  33. # The class object is defined within the layer object. You can define as
  34. # many classes as you need (well, there are limits as with layers, but it's
  35. # senseless to define more than ten on a "normal" layer. There are
  36. # situations, however, where you might have to do it.)
  37. CLASS
  38. NAME "States"
  39.  
  40. # There are styles in a class, just like there are classes in a layer,
  41. # just like there are layers in a map. You can define multiple styles in
  42. # a class just as you can define multiple classes in a layer and multiple
  43. # layers in a map.
  44. STYLE
  45. COLOR
  46. END
  47. END
  48. END # States polygon layer ends here
  49.  
  50. LAYER # States line layer begins here
  51. NAME states_line
  52. DATA states_ugl
  53. STATUS OFF
  54. TYPE LINE
  55.  
  56. CLASS
  57. NAME "State Boundary"
  58. STYLE
  59. COLOR
  60. END
  61. END
  62. END # States line layer ends here
  63. # End of LAYER DEFINITIONS -------------------------------
  64.  
  65. END # All map files must come to an end just as all other things must come to...

按对象划分的map文件结构如下所示:

在这里,我们将原始层分为两层。第一层仍然是多边形层,但样式不再具有outline颜色。第二层与第一层类似,只是类型更改为线条,样式中的颜色更改为与第一个示例中的outline轮廓颜色相同的颜色。这将生成与第一个图像相同的图像…那么,为什么要这样做?如果我们继续在状态层的顶部添加层,那么轮廓很可能会被其他层覆盖。为了在添加这些其他层之后仍能看到状态边界,我们必须将状态边界线层与状态多边形层分离,并将其放在其他层的顶部。我们如何定义/添加层是有顺序的,在本节中,您将清楚地看到它。

Example 1.3: Displaying Classes in a Layer
• 我们可以选择要显示的形状文件的哪些部分。我们使用类对象来完成这项工作…
– 示例1.3-使用类制作“有用”地图

这是map地图文件的外观(Example 1-3.map):

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. IMAGETYPE PNG
  14. EXTENT -97.238976 41.619778 -82.122902 49.385620
  15. SIZE
  16. SHAPEPATH "../data"
  17. IMAGECOLOR
  18.  
  19. # Layer objects are defined beneath the map object. You need at least one
  20. # layer defined in your map file before you can display a map... You can
  21. # define as many layers as you'd like although a limit is typically hard-coded
  22. # in map.h in the MapServer source. The default limit is set at . You'd
  23. # have to have a very specialized application to need more than layers in
  24. # your application.
  25.  
  26. # Start of LAYER DEFINITIONS ---------------------------------------------
  27. LAYER # States polygon layer begins here
  28. NAME states_poly
  29. DATA states_ugl
  30. STATUS OFF
  31. TYPE POLYGON
  32.  
  33. # CLASSITEM defines the non-spatial attribute that you will be using to
  34. # separate a layer into classes. This attribute will be in the DBF file
  35. # of your shapefile (it will be different for each data format). In this
  36. # example the shapefile states_ugl has an associated database
  37. # (states_ugl.dbf) that contains an attribute called "CLASS". You will be
  38. # using two values in the CLASS attribute to separate the classes (also
  39. # called themes) used in this layer--land and water. CLASSITEM is used in
  40. # association with the EXPRESSION parameter in the CLASS object. See below.
  41. CLASSITEM "CLASS"
  42.  
  43. # The class object is defined within the layer object. You can define as
  44. # many classes as you need (well, there are limits as with layers, but it's
  45. # senseless to define more than ten on a "normal" layer. There are
  46. # situations, however, where you might have to do it.)
  47. CLASS
  48. NAME 'States'
  49. EXPRESSION 'land' # Only polygons where "CLASS" = 'land' will be drawn.
  50.  
  51. # There are styles in a class, just like there are classes in a layer,
  52. # just like there are layers in a map. You can define multiple styles in
  53. # a class just as you can define multiple classes in a layer and multiple
  54. # layers in a map.
  55. STYLE
  56. COLOR
  57. END
  58. END
  59. CLASS
  60. NAME 'Water'
  61. EXPRESSION 'water' # Only polygons where "CLASS" = 'water' will be drawn.
  62. STYLE
  63. COLOR
  64. END
  65. END
  66. END # States polygon layer ends here
  67.  
  68. LAYER # States line layer begins here
  69. NAME states_line
  70. DATA states_ugl
  71. STATUS OFF
  72. TYPE LINE
  73.  
  74. CLASSITEM "CLASS"
  75. CLASS
  76. NAME 'State Boundary'
  77. EXPRESSION 'land'
  78. STYLE
  79. COLOR
  80. END
  81. END
  82. END # States line layer ends here
  83. # End of LAYER DEFINITIONS -------------------------------
  84.  
  85. END # All map files must come to an end just as all other things must come to...

按对象划分的map文件结构如下所示:

我们的地图文件仍然只有两个图层,但是多边形图层被分解为两个类。让我们看看其他参数:

CLASSITEM

此关键字用于指定用于分隔类对象的属性。在这个例子中,属性是“class”。如果打开与该层的shapefile关联的数据库文件,您将看到有一个名为“class”的列(属性)。

我们如何知道要使用哪个属性?好吧,shapefiles中的数据库记录存储在dbf文件中。您可以在电子表格程序(如openoffice.org的calc)或桌面地理信息系统软件(如qgis、thuban或arcview)中打开它。如果您的数据带有元数据(应该是!),您可以浏览该元数据文件以获取属性信息。您还可以使用“ogrinfo”在shapefiles中显示基本属性信息——回顾示例1.1(在“layer srs wkt:”后面的最后几行显示属性名称和类型)。

EXPRESSION

对于每个类,我们指定要使用的属性值。这是最简单的表达形式。表达式可能比这更复杂,允许计算正则表达式或逻辑表达式。请查看mapfile引用页,了解如何使用表达式。

Example 1.4: Labeling the Map

我们也可以在地图上添加标签…

MapServer有一个非常灵活的标签引擎。它支持本机位图和TrueType字体。TrueType支持字体缩放。标签的角度和位置可以定制…如果您花时间学习创建好标签所涉及的许多参数,您将获得信息丰富、美观的地图。

这是map文件的外观(例如1-4.map):

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. IMAGETYPE PNG
  14. EXTENT -97.238976 41.619778 -82.122902 49.385620
  15. SIZE
  16. SHAPEPATH "../data"
  17. IMAGECOLOR
  18. FONTSET "../fonts/fonts.list"
  19.  
  20. # Layer objects are defined beneath the map object. You need at least one
  21. # layer defined in your map file before you can display a map... You can
  22. # define as many layers as you'd like although a limit is typically hard-coded
  23. # in map.h in the MapServer source. The default limit is set at . You'd
  24. # have to have a very specialized application to need more than layers in
  25. # your application.
  26.  
  27. # Start of LAYER DEFINITIONS ---------------------------------------------
  28. LAYER # States polygon layer begins here
  29. NAME states_poly
  30. DATA states_ugl
  31. STATUS OFF
  32. TYPE POLYGON
  33.  
  34. # CLASSITEM defines the non-spatial attribute that you will be using to
  35. # separate a layer into classes. This attribute will be in the DBF file
  36. # of your shapefile (it will be different for each data format). In this
  37. # example the shapefile states_ugl has an associated database
  38. # (states_ugl.dbf) that contains an attribute called "CLASS". You will be
  39. # using two values in the CLASS attribute to separate the classes (also
  40. # called themes) used in this layer--land and water. CLASSITEM is used in
  41. # association with the EXPRESSION parameter in the CLASS object. See below.
  42. CLASSITEM "CLASS"
  43.  
  44. # Just like CLASSITEM, LABELITEM defines the database attribute that you
  45. # will be using to draw labels. In this case, the values of the attribute
  46. # "STATE" will be used to label the states polygons.
  47. LABELITEM "STATE"
  48.  
  49. # The class object is defined within the layer object. You can define as
  50. # many classes as you need (well, there are limits as with layers, but it's
  51. # senseless to define more than ten on a "normal" layer. There are
  52. # situations, however, where you might have to do it.)
  53. CLASS
  54. NAME 'States'
  55. EXPRESSION 'land'
  56.  
  57. # There are styles in a class, just like there are classes in a layer,
  58. # just like there are layers in a map. You can define multiple styles in
  59. # a class just as you can define multiple classes in a layer and multiple
  60. # layers in a map.
  61. STYLE
  62. COLOR
  63. END
  64.  
  65. # There can be labels in a class, just like there are classes in a layer,
  66. # just like there are layers in a map. You can define multiple labels in
  67. # a class just as you can define multiple classes in a layer and multiple
  68. # layers in a map.
  69. # MapServer has a very flexible labeling system. With that flexibility
  70. # comes complexity, specially when using truetype fonts. Please read
  71. # through the LABEL section of the MapServer map file documentation at
  72. # http://www.mapserver.org/mapfile for more information.
  73. LABEL
  74. COLOR
  75. SHADOWCOLOR
  76. SHADOWSIZE
  77. TYPE TRUETYPE
  78. FONT arial-bold
  79. SIZE
  80. ANTIALIAS TRUE
  81. POSITION CL
  82. PARTIALS FALSE
  83. MINDISTANCE
  84. BUFFER
  85. END # end of label
  86. END
  87.  
  88. CLASS
  89. NAME 'Water'
  90. EXPRESSION 'water'
  91.  
  92. STYLE
  93. COLOR
  94. END
  95. END
  96. END # States polygon layer ends here
  97.  
  98. LAYER # States line layer begins here
  99. NAME states_line
  100. DATA states_ugl
  101. STATUS OFF
  102. TYPE LINE
  103.  
  104. CLASSITEM "CLASS"
  105. CLASS
  106. NAME 'State Boundary'
  107. EXPRESSION 'land'
  108. STYLE
  109. COLOR
  110. END
  111. END
  112. END # States line layer ends here
  113. # End of LAYER DEFINITIONS -------------------------------
  114.  
  115. END # All map files must come to an end just as all other things must come to...

按对象划分的map文件结构如下所示:

这里我们介绍LABEL对象的几个参数:

FONTSET字体集
这里我们指定TrueType字体列表(或字体集)文件的完整路径。此文件列出了每个可用字体。有关详细信息,请参见文件本身和mapfile引用。fontset是地图对象的参数。

LABELITEM
这将指定要用于标记的数据属性,在本例中为“STATE”。labelitem是层对象的参数。

LABEL标签
标记标签对象的开头。标签对象可用于其他对象(即scaleBar对象)下。

COLOR颜色
在标签对象中,颜色指定标签文本的颜色。

SHADOWCOLOR阴影颜色
指定标签文本的阴影颜色。

SHADOWSIZE阴影大小
指定阴影大小。该值对应于x和y以像素为单位移动。所以,“2 2”是指两个像素宽两个像素高。

TYPE类型
在Label对象中,TYPE指定要使用的字体类型。我们可以选择TrueType或BitMap(内置字体)。我们选择TrueType。

FONT字体
如果将TYPE指定为TrueType,则需要指定要使用的字体。这里的值是字体列表文件中的“别名”。

SIZE尺寸
如果使用TrueType字体,则值为像素大小。如果是位图,可以说“小”或“大”。

ANTIALIAS
这将打开或关闭TrueType抗锯齿。请记住,值不是开或关,而是真或假。

POSITION位置
标签文本相对于标签点的位置。该值是垂直和水平位置的组合。垂直对齐有以下选项:C代表中心,U代表上部,L代表下部。对于水平对齐,您有以下选项:C代表中心,L代表左侧,R代表右侧。因此,要将标签文本与标签ID的中心对齐,需要使用值“cc”(中心)。或者如果你想把它放在身份证的左下角,你可以用LL。另一种方法是让MapServer决定标签的最佳位置。为此,您将使用值“auto”。

PARTIALS部分
告诉MapServer是否生成不完整的标签文本。这里的默认设置是不生成标签文本的片段。该值为真或假。

MINDISTANCE最小距离
这是重复标签之间的最小距离(像素)。看看如果增加或减少这个值会发生什么。

BUFFER缓冲器
每个标签的填充(像素)。这用于增强可读性。4个像素的缓冲区意味着在4个像素的范围内不会绘制任何标签。再次,改变看看它是如何工作的。

还可以创建与多边形层分离的标签。对ANNOTATION数据类型执行此操作。查看下一个示例的映射文件,了解如何实现这种标记。您将注意到“label”层中的类对象的颜色参数值为“-1-1-1”。负数告诉MapServer给这个类一个透明的颜色(标签ID不显示)。再次,使用这些值了解它如何影响地图。

 Example 1.5: Adding a Raster Layer

除了支持矢量数据(点、线、多边形和注释),MapServer还可以显示光栅数据。通过使用gdal库,mapserver可以输入和输出多种光栅格式。在4.x之前的版本中,光栅输入仅限于单层、灰度或索引彩色图像,而MapServer现在支持RGB和多光谱(多层)图像。此示例演示如何选择使用多光谱数据时要显示的图层。在使用RGB和多光谱图像时,可能会出现明显的性能问题。

因为MapServer5.x使用gd版本2.0.x库来生成输出图像,所以它也支持RGB(24位或真彩色)输出。因此,除了8位(索引颜色或灰度)PNG,您现在还可以使用PNG24(真颜色)进行输出。此示例使用PNG24作为ImageType。与RGB输入一样,使用PNG24时可能会出现明显的性能问题。

mapserver实际上也可以使用gdal生成输出图像,但这是另一个主题。如果您想了解更多信息,请查看mapfile引用中的outputformat对象。

这是映射文件的外观(例如1-5.map):

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. IMAGETYPE PNG24
  14. EXTENT -97.238976 41.619778 -82.122902 49.385620
  15. SIZE
  16. SHAPEPATH "../data"
  17. IMAGECOLOR
  18. FONTSET "../fonts/fonts.list"
  19. SYMBOLSET "../symbols/symbols35.sym"
  20.  
  21. # Layer objects are defined beneath the map object. You need at least one
  22. # layer defined in your map file before you can display a map... You can
  23. # define as many layers as you'd like although a limit is typically hard-coded
  24. # in map.h in the MapServer source. The default limit is set at . You'd
  25. # have to have a very specialized application to need more than layers in
  26. # your application.
  27. #
  28. # Start of LAYER DEFINITIONS ---------------------------------------------
  29. LAYER # States polygon layer begins here
  30. NAME states
  31. DATA states_ugl
  32. STATUS OFF
  33. TYPE POLYGON
  34.  
  35. # CLASSITEM defines the non-spatial attribute that you will be using to
  36. # separate a layer into classes. This attribute will be in the DBF file
  37. # of your shapefile (it will be different for each data format). In this
  38. # example the shapefile states_ugl has an associated database
  39. # (states_ugl.dbf) that contains an attribute called "CLASS". You will be
  40. # using two values in the CLASS attribute to separate the classes (also
  41. # called themes) used in this layer--land and water. CLASSITEM is used in
  42. # association with the EXPRESSION parameter in the CLASS object. See below.
  43. CLASSITEM "CLASS"
  44.  
  45. # The class object is defined within the layer object. You can define as
  46. # many classes as you need (well, there are limits as with layers, but it's
  47. # senseless to define more than ten on a "normal" layer. There are
  48. # situations, however, where you might have to do it.)
  49. CLASS
  50. NAME 'States'
  51. EXPRESSION 'land'
  52.  
  53. # There are styles in a class, just like there are classes in a layer,
  54. # just like there are layers in a map. You can define multiple styles in
  55. # a class just as you can define multiple classes in a layer and multiple
  56. # layers in a map.
  57. STYLE
  58. COLOR
  59. END
  60. END
  61. END # States polygon layer ends here
  62.  
  63. # In addition to vector data (shapefiles are vector data), MapServer supports
  64. # a host of raster formats. In GIS world, one of the most common raster
  65. # formats is GeoTIFF, a TIFF image with geospatial headers. MapServer also
  66. # supports JPEG, PNG, GIF, and other common formats. Other raster formats
  67. # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,
  68. # Generic raster binaries, OGC Web Map Service (WMS) layers, etc. Pretty much
  69. # any raster format you can think of is probably supported, thanks to the
  70. # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"
  71. # or GOODLE?). More information on GDAL is available at http://www.gdal.org.
  72. #
  73. # MapServer .x can read and display bitmapped (like GIFs), RGB/A (true
  74. # color), and multispectral (images with more than bands, like raw LandSat
  75. # images) rasters.
  76. LAYER # MODIS raster layer begins here
  77. NAME modis
  78. DATA "raster/mod09a12003161_ugl_ll_8bit.tif"
  79. STATUS OFF
  80. TYPE RASTER
  81. PROCESSING "BANDS=1,2,3"
  82. OFFSITE
  83. END # MODIS raster layer ends here
  84.  
  85. LAYER # States line layer begins here
  86. NAME states_line
  87. DATA states_ugl
  88. STATUS OFF
  89. TYPE LINE
  90.  
  91. CLASSITEM "CLASS"
  92. CLASS
  93. NAME 'State Boundary'
  94. EXPRESSION 'land'
  95. STYLE
  96. SYMBOL 'line5'
  97. COLOR
  98. SIZE
  99. END
  100. END
  101. END # States line layer ends here
  102.  
  103. # Labels can be defined in its own layer. This is useful if, say, you want
  104. # to label a polygon layer that's covered by another layer. By keeping the
  105. # label separate from the polygon and placing it near the bottom of the map
  106. # file (so its drawn on, or near the, top), you can still see the label even
  107. # though you might not be able to see the polygon. It is also a good
  108. # alternate to point symbols.
  109. #
  110. # A label layer is actually defined with ANNOTATION type (This is derived from
  111. # points, Node IDs for lines, or polygon IDs).
  112. LAYER # States label layer begins here
  113. NAME states_label
  114. DATA states_ugl
  115. STATUS OFF
  116. TYPE ANNOTATION
  117.  
  118. CLASSITEM "CLASS"
  119.  
  120. # Just like CLASSITEM, LABELITEM defines the database attribute that you
  121. # will be using to draw labels. In this case, the values of the attribute
  122. # "STATE" will be used to label the states polygons.
  123. LABELITEM "STATE"
  124.  
  125. CLASS
  126. EXPRESSION 'land'
  127. STYLE
  128. COLOR - - -
  129. END
  130.  
  131. # There can be labels in a class, just like there are classes in a layer,
  132. # just like there are layers in a map. You can define multiple labels in
  133. # a class just as you can define multiple classes in a layer and multiple
  134. # layers in a map.
  135. # MapServer has a very flexible labeling system. With that flexibility
  136. # comes complexity, specially when using truetype fonts. Please read
  137. # through the LABEL section of the MapServer map file documentation at
  138. # http://www.mapserver.org/mapfile for more information.
  139. LABEL
  140. COLOR
  141. SHADOWCOLOR
  142. SHADOWSIZE
  143. TYPE TRUETYPE
  144. FONT arial-bold
  145. SIZE
  146. ANTIALIAS TRUE
  147. POSITION CL
  148. PARTIALS FALSE
  149. MINDISTANCE
  150. BUFFER
  151. END # end of label
  152. END # end of class
  153. END # States label layer ends here
  154. # End of LAYER DEFINITIONS -------------------------------
  155.  
  156. END # All map files must come to an end just as all other things must come to...

按对象划分的map地图文件结构如下所示:

当您查看map地图文件时,您将看到新的图层对象被添加到区域polygon多边形图层的下面(后面)。为什么?mapserver以相反的顺序显示层——后进先出(lifo)。地图文件中定义的第一个图层绘制在地图的底部。

所以,如果我们画了state多边形层,它会在底部。因为光栅图层被绘制在上面,所以我们看不到它。这就是为什么第一层的状态值为off的原因。状态线图层定义在光栅图层的下方,以便在顶部绘制(您可以看到)。这就是我们将状态线层与状态多边形层分离的原因。当然,标签是在最上面。

MapServer可以根据其他图层的状态自动打开或关闭图层——比如说,当光栅图层打开时,希望关闭状态多边形图层。这是通过使用Requires参数来完成的。记住这一点,因为一旦开始创建自己的MapServer应用程序,您可能会想要使用它。

让我们看看mapfile中引入的新参数:

IMAGETYPE 图像类型
这不是新的,但值“png24”是。PNG24是PNG格式的24位或真彩色版本。mapserver现在拥有数百万个颜色组合,而不是仅限于输出图像的256种颜色组合。顺便说一下,试着把这个值改回png。请注意,使用这两种格式生成图像所需的时间。在选择真彩色和索引颜色时,要考虑生成图像所需的时间。

SYMBOLSET符号集
指向符号定义文件的路径。此文件中的符号由类对象中的符号参数引用。现在不需要,但我想我现在就把它扔到这里。更多信息,请参考地图文件参考和地图服务器的地图符号构造。

DATA数据“光栅/mod09a1203161_ugl_ll_8bit.tif”
在新添加的图层对象中,数据参数指向geotiff图像。与矢量数据集一样,MapServer支持多种光栅文件格式。这种支持是通过使用gdal库来实现的。有关MapServer支持的不同光栅格式的详细信息,以及有关在MapServer中使用光栅的一般性讨论,请阅读http://www.mapserver.org/input/graster.html上的光栅数据操作方法。

TYPE RASTER类型光栅
当使用光栅数据(图像)时,我们使用值光栅作为参数类型,而不是矢量数据的多边形、直线和点值以及标签ID的注释。

PROCESSING "BANDS=1,2,3"处理“波段=1,2,3”
在MapServer 4.x中,这个层对象参数是新的。处理关键字有很多值,但在本例中,我们使用它来选择要显示多光谱图像中的波段。这里的值是将传递到gdal库的字符串。有关这一点的文档目前是最少的,但有关使用processing关键字的更多示例,请参阅mapfile参考。

OFFSITE
此参数告诉MapServer要渲染为背景(或忽略)的像素值。您可以使用图像处理或图像操作程序(例如,Imagine、Photoshop、Gimp)获取像素值。

要在使用RGB图像而不是索引颜色图像时比较地图创建速度,请替换地图文件中的以下行:

  1. DATA "raster/mod09a12003161_ugl_ll_8bit.tif"
  2. STATUS DEFAULT
  3. TYPE RASTER
  4. PROCESSING "BANDS=1,2,3"
  5. OFFSITE

为:

  1. DATA "raster/mod09a12003161_ugl_ll_idxa.tif"
  2. STATUS DEFAULT
  3. TYPE RASTER
  4. OFFSITE

另外,尝试将imagetype从png24更改为png。

Example 1.6: Defining Projections and Extents

我们可以将我们的数据从几乎任何投影重新投影到几乎任何…是的,看看!

哇!这里发生了什么?

你刚刚经历了一次on-the-fly的再投射。在map文件中定义投影对象时,MapServer将图层和投影信息传递给执行重投影的proj.4库。有关proj.4库的更多信息,请访问http://trac.osgeo.org/proj/。

这个例子试图为MapServer中的投影支持提供一些帮助。

这是map文件的外观(例如1-6.map):

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. IMAGETYPE PNG24
  14. # EXTENT 199949.651166 -371954.772084 1472121.6862 632767.19157
  15. EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # LAEA
  16. #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic
  17. SIZE
  18. SHAPEPATH "../data"
  19. SYMBOLSET "../symbols/symbols35.sym"
  20. FONTSET "../fonts/fonts.list"
  21.  
  22. # The projection object is typically used within the map and the layer
  23. # objects. You only define it once within the map object and this definition
  24. # becomes your output projection--MapServer will render your maps in this
  25. # projection. You also use the projection object within the layer object to
  26. # define your input projection. Your layers can be in different
  27. # projections--MapServer will reproject them into your output projection.
  28. # If no projection is defined within the layer object, MapServer assumes
  29. # your input projection is the same as your output projection. This is not
  30. # a required object unless you're creating a map file that supports one of
  31. # the OGC interoperability web services specifications (WMS/WFS/WCS).
  32. #
  33. # This is the output PROJECTION definition ------
  34. PROJECTION
  35. # Projection parameters can be defined in two ways...
  36. # This is the traditional Proj. definition of Lambert Azimuthal Equal-Area
  37. # projection for the Continental U.S.
  38. "proj=laea"
  39. "ellps=clrk66"
  40. "lat_0=45"
  41. "lon_0=-100"
  42.  
  43. # Alternatively, you can specify an EPSG code.
  44. # This is the EPSG code for Lambert Azimuthal Equal-Area
  45. # projection for the U.S.
  46. #
  47. # "init=epsg:2163"
  48. END # End of the output Projection definition ---
  49.  
  50. # Layer objects are defined beneath the map object. You need at least one
  51. # layer defined in your map file before you can display a map... You can
  52. # define as many layers as you'd like although a limit is typically hard-coded
  53. # in map.h in the MapServer source. The default limit is set at . You'd
  54. # have to have a very specialized application to need more than layers in
  55. # your application.
  56. #
  57. # Start of LAYER DEFINITIONS ---------------------------------------------
  58. LAYER # States polygon layer begins here
  59. NAME states
  60. DATA states_ugl
  61. STATUS OFF
  62. TYPE POLYGON
  63.  
  64. # Here's an example of the input projection definition.
  65. # EPSG: is code for geographic (latlong) projection
  66. # using the WGS84 datum.
  67. #
  68. # PROJECTION objects within the LAYER object define the input
  69. # projection--this is the native projection of your data.
  70. PROJECTION
  71. "init=epsg:4326"
  72. END
  73.  
  74. # CLASSITEM defines the non-spatial attribute that you will be using to
  75. # separate a layer into classes. This attribute will be in the DBF file
  76. # of your shapefile (it will be different for each data format). In this
  77. # example the shapefile states_ugl has an associated database
  78. # (states_ugl.dbf) that contains an attribute called "CLASS". You will be
  79. # using two values in the CLASS attribute to separate the classes (also
  80. # called themes) used in this layer--land and water. CLASSITEM is used in
  81. # association with the EXPRESSION parameter in the CLASS object. See below.
  82. CLASSITEM "CLASS"
  83.  
  84. # The class object is defined within the layer object. You can define as
  85. # many classes as you need (well, there are limits as with layers, but it's
  86. # senseless to define more than ten on a "normal" layer. There are
  87. # situations, however, where you might have to do it.)
  88. CLASS
  89. NAME 'States'
  90. EXPRESSION 'land'
  91.  
  92. # There are styles in a class, just like there are classes in a layer,
  93. # just like there are layers in a map. You can define multiple styles in
  94. # a class just as you can define multiple classes in a layer and multiple
  95. # layers in a map.
  96. STYLE
  97. COLOR
  98. END
  99. END
  100. END # States polygon layer ends here
  101.  
  102. # In addition to vector data (shapefiles are vector data), MapServer supports
  103. # a host of raster formats. In GIS world, one of the most common raster
  104. # formats is GeoTIFF, a TIFF image with geospatial headers. MapServer also
  105. # supports JPEG, PNG, GIF, and other common formats. Other raster formats
  106. # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,
  107. # Generic raster binaries, OGC Web Map Service (WMS) layers, etc. Pretty much
  108. # any raster format you can think of is probably supported, thanks to the
  109. # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"
  110. # or GOODLE?). More information on GDAL is available at http://www.gdal.org.
  111. #
  112. # MapServer .x can read and display bitmapped (like GIFs), RGB/A (true
  113. # color), and multispectral (images with more than bands, like raw LandSat
  114. # images) rasters.
  115. LAYER # MODIS raster layer begins here
  116. NAME modis
  117. DATA "raster/mod09a12003161_ugl_ll_8bit.tif"
  118. STATUS OFF
  119. TYPE RASTER
  120. PROCESSING "BANDS=1,2,3"
  121. OFFSITE
  122.  
  123. PROJECTION
  124. "init=epsg:4326"
  125. END
  126. END # MODIS raster layer ends here
  127.  
  128. LAYER # States line layer begins here
  129. NAME states
  130. DATA states_ugl
  131. STATUS OFF
  132. TYPE LINE
  133.  
  134. PROJECTION
  135. "init=epsg:4326"
  136. END
  137.  
  138. CLASSITEM "CLASS"
  139. CLASS
  140. NAME 'State Boundary'
  141. EXPRESSION 'land'
  142. STYLE
  143. SYMBOL 'line5'
  144. COLOR
  145. SIZE
  146. END
  147. END
  148. END # States line layer ends here
  149.  
  150. LAYER # States label layer begins here
  151. NAME states_label
  152. DATA states_ugl
  153. STATUS OFF
  154. TYPE ANNOTATION
  155.  
  156. PROJECTION
  157. "init=epsg:4326"
  158. END
  159.  
  160. CLASSITEM "CLASS"
  161.  
  162. # Just like CLASSITEM, LABELITEM defines the database attribute that you
  163. # will be using to draw labels. In this case, the values of the attribute
  164. # "STATE" will be used to label the states polygons.
  165. LABELITEM "STATE"
  166. CLASS
  167. EXPRESSION 'land'
  168. STYLE
  169. COLOR - - -
  170. END
  171.  
  172. # There can be labels in a class, just like there are classes in a layer,
  173. # just like there are layers in a map. You can define multiple labels in
  174. # a class just as you can define multiple classes in a layer and multiple
  175. # layers in a map.
  176. # MapServer has a very flexible labeling system. With that flexibility
  177. # comes complexity, specially when using truetype fonts. Please read
  178. # through the LABEL section of the MapServer map file documentation at
  179. # http://www.mapserver.org/mapfile for more information.
  180. LABEL
  181. COLOR
  182. SHADOWCOLOR
  183. SHADOWSIZE
  184. TYPE TRUETYPE
  185. FONT arial-bold
  186. SIZE
  187. ANTIALIAS TRUE
  188. POSITION CL
  189. PARTIALS FALSE
  190. MINDISTANCE
  191. BUFFER
  192. END # end of label
  193. END # end of class
  194. END # States label layer ends here
  195. # End of LAYER DEFINITIONS -------------------------------
  196.  
  197. END # All map files must come to an end just as all other things must come to...

在我们的地图文件中,您可能注意到的第一件事是原始范围已被注释掉,新的范围值看起来与纬度和经度值不同。另外,我们在顶部附近和每个Layer层中添加了一个投影对象。

让我们看看新的对象和参数:

EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514

我们提供给MapServer的范围需要与输出投影使用相同的单位。由于兰伯特方位角的等面积单位是米,我们必须给新的范围以米。我们可以使用arcview或其他一些gis包计算新的范围,也可以使用proj.4的cs2cs实用程序。下面的命令可用于重新投影原始范围值:

  1. cs2cs +proj=latlong +datum=WGS84 +to +proj=laea +ellps=clrk66 +lat_0=45 +lon_0=-100

键入命令后,输入西南坐标对(左下角坐标),用空格分隔:-97.5 41.619778
“cs2cs”实用程序给出的值:

  1. 208398.01 -372335.44 0.000

然后键入东北坐标对(右上角坐标),再次用空格分隔:-82.122902 49.38562,并返回以下值:

  1. 1285308.08 632638.93 0.000

您会注意到“cs2cs”返回一组三个值。您可以忽略第三个值0.000,因为它表示高度(我们不使用)。无论如何,我们不能将范围表示为:

  1. EXTENT 208398.01 -372335.44 1285308.08 632638.93

但这与上面的范围不符,你说。好吧,这就是你回绝的时候通常会发生的事情——地图不一定像你想象的那样居中。你可以绕着它转,向左走几千米,向右再加几米。或者,您可以使用图形化的地理信息系统包来提供范围。以下是使用ArcView获取范围的说明。

MapServer可以通过两种方式获取投影定义。第一个显示在映射文件的输出投影对象(第一个投影块)中。这是将参数传递到proj.4库的传统方法。另一种方法是使用EPSG代码。这些代码是欧洲石油调查集团(EPSG)定义的标准投影代码(或空间参考标识符)。在我们的兰伯特方位角等面积投影,它有一个代码“2163”。如果在投影后注释掉这四行,并取消对行“init=epsg:2163”的注释,这将向项目4提供相同的信息。如果您想了解EPSG代码的更多信息,请查看“/usr/local/share/proj/epsg”或“c:/proj/nad/epsg”(MS4W中的“/ms4W/proj/nad”)。此外,请访问EPSG网站http://www.epsg.org。

如果您需要了解有关投影的更多信息,请查看以下链接:

http://www.colorado.edu/geography/gcraft/notes/mapproj/mapproj_f.html
http://www.geography.hunter.cuny.edu/mp/
http://www.nationalatlas.gov/articles/mapping/a_projections.html
http://en.wikipedia.org/wiki/Map_projection
http://erg.usgs.gov/isb/pubs/MapProjections/projections.html

你可以通过在网上搜索“地图投影”找到更多信息。

 Example 1.7: Adding OGC WMS Layers

我们可以使用来自互联网上其他地图服务器的层(只要它们是WMS服务器)。

MapServer的另一个令人兴奋的特性是它能够使用来自其他地图服务器的层。在这种情况下,MapServer应用程序将成为WMS(或WFS)客户机。mapserver还可以将map文件中的层共享(或服务于其他地图服务器)。这使应用程序成为一个WMS(或WFS)服务器。什么是WMS或WFS?这些是由开放地理空间联盟(OGC)发布的“基于Web的互操作性服务”规范。

wms代表web map服务,wfs代表web feature服务。简单来说,这两种规范的区别在于,WMS使用Web光栅格式(PNG、GIF、JPEG)共享层,而WFS使用地理标记语言GML。第三个OGC互操作性规范是Web Coverage Services规范或WCS——MapServer仅在服务器级别支持此规范。要查找有关WMS、WFS和WCS的更多信息,请访问OGC的网站,并查找OGC实现规范或OGC抽象规范。MapServer网站还提供了这些规范的文档。

此示例演示如何在map地图文件中添加WMS层。

这是map文件的外观(示例1-7.map):

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. IMAGETYPE PNG24
  14. EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # LAEA
  15. #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic
  16. SIZE
  17. SHAPEPATH "../data"
  18. SYMBOLSET "../symbols/symbols35.sym"
  19. FONTSET "../fonts/fonts.list"
  20.  
  21. # The projection object is typically used within the map and the layer
  22. # objects. You only define it once within the map object and this definition
  23. # becomes your output projection--MapServer will render your maps in this
  24. # projection. You also use the projection object within the layer object to
  25. # define your input projection. Your layers can be in different
  26. # projections--MapServer will reproject them into your output projection.
  27. # If no projection is defined within the layer object, MapServer assumes
  28. # your input projection is the same as your output projection. This is not
  29. # a required object unless you're creating a map file that supports one of
  30. # the OGC interoperability web services specifications (WMS/WFS/WCS).
  31. #
  32. # This is the output PROJECTION definition ------
  33. PROJECTION
  34. # Projection parameters can be defined in two ways...
  35. # This is the traditional Proj. definition of Lambert Azimuthal Equal-Area
  36. # projection for the Continental U.S.
  37. # "proj=laea"
  38. # "ellps=clrk66"
  39. # "lat_0=45"
  40. # "lon_0=-100"
  41. #
  42. # Alternatively, you can specify an EPSG code.
  43. # This is the EPSG code for Lambert Azimuthal Equal-Area
  44. # projection for the U.S.
  45. "init=epsg:2163"
  46. END
  47.  
  48. # The web object is defined at the level below the map object. All
  49. # web-related parameters (I interchange "parameters" and "keyword/value
  50. # pairs" quite frequently, sorry about that) are defined in this object.
  51. WEB
  52. IMAGEPATH "/ms4w/tmp/"
  53. IMAGEURL "/tmp/"
  54. END
  55.  
  56. # Layer objects are defined beneath the map object. You need at least one
  57. # layer defined in your map file before you can display a map... You can
  58. # define as many layers as you'd like although a limit is typically hard-coded
  59. # in map.h in the MapServer source. The default limit is set at . You'd
  60. # have to have a very specialized application to need more than layers in
  61. # your application.
  62. #
  63. # Start of LAYER DEFINITIONS ---------------------------------------------
  64. LAYER # States polygon layer begins here
  65. NAME states
  66. DATA states_ugl
  67. STATUS OFF
  68. TYPE POLYGON
  69.  
  70. # Here's an example of the input projection definition.
  71. # EPSG: is code for geographic (latlong) projection
  72. # using the WGS84 datum.
  73. #
  74. # PROJECTION objects within the LAYER object define the input
  75. # projection--this is the native projection of your data.
  76. PROJECTION
  77. "init=epsg:4326"
  78. END
  79.  
  80. # CLASSITEM defines the non-spatial attribute that you will be using to
  81. # separate a layer into classes. This attribute will be in the DBF file
  82. # of your shapefile (it will be different for each data format). In this
  83. # example the shapefile states_ugl has an associated database
  84. # (states_ugl.dbf) that contains an attribute called "CLASS". You will be
  85. # using two values in the CLASS attribute to separate the classes (also
  86. # called themes) used in this layer--land and water. CLASSITEM is used in
  87. # association with the EXPRESSION parameter in the CLASS object. See below.
  88. CLASSITEM "CLASS"
  89.  
  90. # The class object is defined within the layer object. You can define as
  91. # many classes as you need (well, there are limits as with layers, but it's
  92. # senseless to define more than ten on a "normal" layer. There are
  93. # situations, however, where you might have to do it.)
  94. CLASS
  95. NAME 'States'
  96. EXPRESSION 'land'
  97.  
  98. # There are styles in a class, just like there are classes in a layer,
  99. # just like there are layers in a map. You can define multiple styles in
  100. # a class just as you can define multiple classes in a layer and multiple
  101. # layers in a map.
  102. STYLE
  103. COLOR
  104. END
  105. END
  106. END # States polygon layer ends here
  107.  
  108. # In addition to vector data (shapefiles are vector data), MapServer supports
  109. # a host of raster formats. In GIS world, one of the most common raster
  110. # formats is GeoTIFF, a TIFF image with geospatial headers. MapServer also
  111. # supports JPEG, PNG, GIF, and other common formats. Other raster formats
  112. # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,
  113. # Generic raster binaries, OGC Web Map Service (WMS) layers, etc. Pretty much
  114. # any raster format you can think of is probably supported, thanks to the
  115. # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"
  116. # or GOODLE?). More information on GDAL is available at http://www.gdal.org.
  117. #
  118. # MapServer .x can read and display bitmapped (like GIFs), RGB/A (true
  119. # color), and multispectral (images with more than bands, like raw LandSat
  120. # images) rasters.
  121. LAYER # MODIS raster layer begins here
  122. NAME modis
  123. DATA "raster/mod09a12003161_ugl_ll_8bit.tif"
  124. STATUS OFF
  125. TYPE RASTER
  126. PROCESSING "BANDS=1,2,3"
  127. OFFSITE
  128.  
  129. PROJECTION
  130. "init=epsg:4326"
  131. END
  132. END # MODIS raster layer ends here
  133.  
  134. # MapServer can consume (in ESRI parlance) layers from other map servers as
  135. # long as those servers are Web Mapping Service (WMS) providers. WMS is a
  136. # web service specification from Open Geospatial Consortium (OGC) and is
  137. # intended to be an interoperability standard for web mapping applications.
  138. # This allows us to display layers we don't usually have (or can't store in
  139. # our computers due to space limitations). The downside is that we have to
  140. # depend on some other server to display our layer, and that server can be
  141. # down when you really need it. The cool thing is that JPL has a WMS server
  142. # that serves out MODIS and LandSat maps for the whole world--try storing
  143. # those datasets on your computer!
  144. LAYER # MODIS WMS map from JPL
  145. NAME modis_jpl
  146. TYPE RASTER
  147. OFFSITE
  148. STATUS OFF
  149. CONNECTIONTYPE WMS
  150. CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?"
  151.  
  152. METADATA
  153. "wms_srs" "EPSG:4326"
  154. "wms_name" "modis"
  155. "wms_server_version" "1.1.1"
  156. "wms_format" "image/jpeg"
  157. END
  158.  
  159. PROJECTION
  160. "init=epsg:4326"
  161. END
  162. END # Modis WMS image ends here
  163.  
  164. LAYER # States line layer begins here
  165. NAME states
  166. DATA states_ugl
  167. STATUS OFF
  168. TYPE LINE
  169.  
  170. PROJECTION
  171. "init=epsg:4326"
  172. END
  173.  
  174. CLASSITEM "CLASS"
  175. CLASS
  176. NAME 'State Boundary'
  177. EXPRESSION 'land'
  178. STYLE
  179. SYMBOL 'line5'
  180. COLOR
  181. SIZE
  182. END
  183. END
  184. END # States line layer ends here
  185.  
  186. LAYER # States label layer begins here
  187. NAME states_label
  188. DATA states_ugl
  189. STATUS OFF
  190. TYPE ANNOTATION
  191.  
  192. PROJECTION
  193. "init=epsg:4326"
  194. END
  195.  
  196. CLASSITEM "CLASS"
  197.  
  198. # Just like CLASSITEM, LABELITEM defines the database attribute that you
  199. # will be using to draw labels. In this case, the values of the attribute
  200. # "STATE" will be used to label the states polygons.
  201. LABELITEM "STATE"
  202.  
  203. CLASS
  204. EXPRESSION 'land'
  205. STYLE
  206. COLOR - - -
  207. END
  208.  
  209. # There can be labels in a class, just like there are classes in a layer,
  210. # just like there are layers in a map. You can define multiple labels in
  211. # a class just as you can define multiple classes in a layer and multiple
  212. # layers in a map.
  213. # MapServer has a very flexible labeling system. With that flexibility
  214. # comes complexity, specially when using truetype fonts. Please read
  215. # through the LABEL section of the MapServer map file documentation at
  216. # http://www.mapserver.org/mapfile for more information.
  217. LABEL
  218. COLOR
  219. SHADOWCOLOR
  220. SHADOWSIZE
  221. TYPE TRUETYPE
  222. FONT arial-bold
  223. SIZE
  224. ANTIALIAS TRUE
  225. POSITION CL
  226. PARTIALS FALSE
  227. MINDISTANCE
  228. BUFFER
  229. END # end of label
  230. END # end of class
  231. END # States label layer ends here
  232. # End of LAYER DEFINITIONS -------------------------------
  233.  
  234. END # end of map file

让我们来看看WMS层:

LAYER #来自JPL的MODIS WMS地图
标记WMS Layer图层对象的开始。

NAME modis_jpl
The LAYER 标识符.

TYPE RASTER 类型光栅
因为这个WMS层是一个图像,所以我们使用光栅作为层类型。

OFFSITE 0 0 0
Ignore the black background color忽略黑背景色

STATUS OFF
Turn this layer off by default.默认关掉图层

CONNECTIONTYPE WMS WMS连接类型
要使用的层连接类型。默认值是本地的——如果我们想显式定义,我们将向地图文件中的所有其他向量和光栅层添加CONNECTIONTYPE LOCAL 。相反,我们只定义外部的连接类型。WMS是一个外部数据层,来自另一个地图服务器。

连接“http://mapus.jpl.nasa.gov/wms.cgi?”
允许我们从另一个服务器“获取”数据的连接字符串。对于WMS连接,这是一个URL。如果我们使用PostGIS数据库,它将是一个SQL语句。请注意,字符串必须在映射文件中的一行中。

METADATA 元数据
标记WMS层的元数据对象的开头。MapServer使用此对象中定义的参数以及上面的连接参数来形成对WMS服务器的有效WMS请求。

"wms_srs" "epsg:4326"
WMS投影。有时,WMS服务器支持多个投影。如果是这种情况,您可能希望在输出投影中请求映射。不幸的是,JPL服务器不支持这种投影。

"wms_name" "modis"
WMS层名称。这就像添加参数“layers=modis”。

"wms_server_version" "1.1.1"
服务器符合的WMS版本。MapServer遵循1.1.1版。

"wms_format" "image/jpeg"
T我们期望从WMS服务器接收的图像格式。您可以尝试将该值替换为“image/png”或其他内容。

END
标记METADATA元数据对象的结尾

要了解有关向应用程序添加WMS层的更多信息,请访问WMS客户端操作说明文档。

除了添加WMS图层对象,地图下还有一个新对象。这是Web对象。Web对象中有两个参数:

imagepath'/data/tmp/'
指向Web可访问临时目录的绝对本地路径。运行Web服务器进程的用户应该能够写入此目录。确保路径末尾包含斜线(/)。(您的IMAGEPATH可能如下所示:“/home/apache/htdocs/tmp/”或“c:/inetpub/wwwroot/tmp/”。

IMAGEURL '/tmp/'
这是相对于Web服务器的根目录显示ImagePath的方式。如果必须为此键入完整的URL,它将是“http://terrasip.gis.umn.edu/tmp/”。确保路径末尾包含斜线(/)。

最后,在MAP对象中,我添加了一个新参数:NAME。这是MAP对象的标识符。MapServer将此作为它创建的所有图像的前缀,并将其转储到“tmp”目录。在这一点上不需要它,但是拥有它也不会带来伤害。

如果要将数据层共享到其他地图服务器,则需要在地图对象内以及要共享的每个图层对象内添加元数据对象。从另一台服务器添加的所有WMS层将自动层叠,并且也将对其他服务器可用。要了解有关如何使MapServer应用程序成为WMS服务器的更多信息,请阅读WMS服务器操作说明文档。还存在用于配置MapServer应用程序以支持WFS标准的文档,无论是作为WFS服务器还是作为WFS客户机。

Example 1.8: Changing the Map's Output Format

MapServer可以输出各种格式,如PDF和geotiff。

根据您选择的格式,图像可能不会显示在浏览器上。如果链接无法显示在浏览器上,请右键单击上面的图形,并将链接保存为您在地图文件中指定的任何格式。

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. NAME EX1.8_
  14. EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # LAEA
  15. #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic
  16. SIZE
  17. IMAGECOLOR
  18. SHAPEPATH "../data"
  19. SYMBOLSET "../symbols/symbols35.sym"
  20. FONTSET "../fonts/fonts.list"
  21.  
  22. IMAGETYPE PNG24
  23.  
  24. OUTPUTFORMAT
  25. NAME png
  26. DRIVER "GD/PNG"
  27. MIMETYPE "image/png"
  28. IMAGEMODE PC256
  29. EXTENSION "png"
  30. END
  31. OUTPUTFORMAT
  32. NAME png24
  33. DRIVER "GD/PNG"
  34. MIMETYPE "image/png"
  35. IMAGEMODE RGBA
  36. EXTENSION "png"
  37. END
  38. OUTPUTFORMAT
  39. NAME jpeg
  40. DRIVER "GD/JPEG"
  41. FORMATOPTION "QUALITY=75"
  42. MIMETYPE "image/jpeg"
  43. IMAGEMODE RGB
  44. EXTENSION "jpg"
  45. END
  46. OUTPUTFORMAT
  47. NAME GTiff
  48. DRIVER "GDAL/GTiff"
  49. MIMETYPE "image/tiff"
  50. IMAGEMODE RGB
  51. EXTENSION "tif"
  52. END
  53. #OUTPUTFORMAT
  54. # NAME pdf
  55. # MIMETYPE "application/x-pdf"
  56. # DRIVER pdf
  57. # #FORMATOPTION "OUTPUT_TYPE=RASTER" # not mandatory but needed for WMS layer
  58. #END
  59. OUTPUTFORMAT
  60. NAME AGG
  61. DRIVER "AGG/PNG"
  62. IMAGEMODE RGB
  63. END
  64. OUTPUTFORMAT
  65. NAME AGGA
  66. DRIVER "AGG/PNG"
  67. IMAGEMODE RGBA
  68. END
  69. OUTPUTFORMAT
  70. NAME AGGJ
  71. DRIVER "AGG/JPEG"
  72. IMAGEMODE RGB
  73. END
  74.  
  75. # The web object is defined at the level below the map object. All
  76. # web-related parameters (I interchange "parameters" and "keyword/value
  77. # pairs" quite frequently, sorry about that) are defined in this object.
  78. WEB
  79. IMAGEPATH '/ms4w/tmp/ms_tmp/'
  80. IMAGEURL '/ms_tmp/'
  81. END
  82.  
  83. # The projection object is typically used within the map and the layer
  84. # objects. You only define it once within the map object and this definition
  85. # becomes your output projection--MapServer will render your maps in this
  86. # projection. You also use the projection object within the layer object to
  87. # define your input projection. Your layers can be in different
  88. # projections--MapServer will reproject them into your output projection.
  89. # If no projection is defined within the layer object, MapServer assumes
  90. # your input projection is the same as your output projection. This is not
  91. # a required object unless you're creating a map file that supports one of
  92. # the OGC interoperability web services specifications (WMS/WFS/WCS).
  93. #
  94. # This is the output PROJECTION definition ------
  95. PROJECTION
  96. # Projection parameters can be defined in two ways...
  97. # This is the traditional Proj. definition of Lambert Azimuthal Equal-Area
  98. # projection for the Continental U.S.
  99. # "proj=laea"
  100. # "ellps=clrk66"
  101. # "lat_0=45"
  102. # "lon_0=-100"
  103. #
  104. # Alternatively, you can specify an EPSG code.
  105. # This is the EPSG code for Lambert Azimuthal Equal-Area
  106. # projection for the U.S.
  107. "init=epsg:2163"
  108. END
  109.  
  110. # Layer objects are defined beneath the map object. You need at least one
  111. # layer defined in your map file before you can display a map... You can
  112. # define as many layers as you'd like although a limit is typically hard-coded
  113. # in map.h in the MapServer source. The default limit is set at . You'd
  114. # have to have a very specialized application to need more than layers in
  115. # your application.
  116. #
  117. # Start of LAYER DEFINITIONS ---------------------------------------------
  118. LAYER # States polygon layer begins here
  119. NAME states
  120. DATA states_ugl
  121. STATUS OFF
  122. TYPE POLYGON
  123.  
  124. # Here's an example of the input projection definition.
  125. # EPSG: is code for geographic (latlong) projection
  126. # using the WGS84 datum.
  127. #
  128. # PROJECTION objects within the LAYER object define the input
  129. # projection--this is the native projection of your data.
  130. PROJECTION
  131. "init=epsg:4326"
  132. END
  133.  
  134. # CLASSITEM defines the non-spatial attribute that you will be using to
  135. # separate a layer into classes. This attribute will be in the DBF file
  136. # of your shapefile (it will be different for each data format). In this
  137. # example the shapefile states_ugl has an associated database
  138. # (states_ugl.dbf) that contains an attribute called "CLASS". You will be
  139. # using two values in the CLASS attribute to separate the classes (also
  140. # called themes) used in this layer--land and water. CLASSITEM is used in
  141. # association with the EXPRESSION parameter in the CLASS object. See below.
  142. CLASSITEM "CLASS"
  143.  
  144. # The class object is defined within the layer object. You can define as
  145. # many classes as you need but it is good cartographic practice to limit
  146. # classes to to per layer. (There are also limits as with layers and
  147. # it's senseless to define more than ten on a "normal" layer. There are
  148. # situations, however, where you might have to do it.)
  149. CLASS
  150. EXPRESSION 'land'
  151. STYLE
  152. SYMBOL
  153. COLOR
  154. END
  155. END
  156. END # States polygon layer ends here
  157.  
  158. # In addition to vector data (shapefiles are vector data), MapServer supports
  159. # a host of raster formats. In GIS world, one of the most common raster
  160. # formats is GeoTIFF, a TIFF image with geospatial headers. MapServer also
  161. # supports JPEG, PNG, GIF, and other common formats. Other raster formats
  162. # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,
  163. # Generic raster binaries, OGC Web Map Service (WMS) layers, etc. Pretty much
  164. # any raster format you can think of is probably supported, thanks to the
  165. # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"
  166. # or GOODLE?). More information on GDAL is available at http://www.gdal.org.
  167. #
  168. # MapServer .x can read and display bitmapped (like GIFs), RGB/A (true
  169. # color), and multispectral (images with more than bands, like raw LandSat
  170. # images) rasters.
  171. LAYER # MODIS raster layer begins here
  172. NAME modis
  173. DATA "raster/mod09a12003161_ugl_ll_8bit.tif"
  174. STATUS OFF
  175. TYPE RASTER
  176. PROCESSING "BANDS=1,2,3"
  177. OFFSITE
  178.  
  179. PROJECTION
  180. "init=epsg:4326"
  181. END
  182. END # MODIS raster layer ends here
  183.  
  184. LAYER # MODIS WMS map from JPL
  185. NAME modis_jpl
  186. TYPE RASTER
  187. OFFSITE
  188. STATUS OFF
  189. CONNECTIONTYPE WMS
  190. CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?"
  191.  
  192. METADATA
  193. "wms_srs" "EPSG:4326"
  194. "wms_name" "modis"
  195. "wms_server_version" "1.1.1"
  196. "wms_format" "image/jpeg"
  197. END
  198.  
  199. PROJECTION
  200. "init=epsg:4326"
  201. END
  202. END # Modis WMS image ends here
  203.  
  204. LAYER # States line layer begins here
  205. NAME states
  206. DATA states_ugl
  207. STATUS OFF
  208. TYPE LINE
  209.  
  210. PROJECTION
  211. "init=epsg:4326"
  212. END
  213.  
  214. CLASSITEM "CLASS"
  215. CLASS
  216. EXPRESSION 'land'
  217. STYLE
  218. #SYMBOL 'line1'
  219. COLOR
  220. #SIZE
  221. END
  222. END
  223. END # States line layer ends here
  224.  
  225. LAYER # States label layer begins here
  226. NAME states
  227. DATA states_ugl
  228. STATUS OFF
  229. TYPE ANNOTATION
  230.  
  231. PROJECTION
  232. "init=epsg:4326"
  233. END
  234.  
  235. CLASSITEM "CLASS"
  236. LABELITEM "STATE"
  237. CLASS
  238. EXPRESSION 'land'
  239. STYLE
  240. COLOR - - -
  241. END
  242. LABEL
  243. COLOR
  244. TYPE TRUETYPE
  245. FONT arial-bold
  246. SIZE
  247. ANTIALIAS TRUE
  248. POSITION CL
  249. PARTIALS FALSE
  250. MINDISTANCE
  251. BUFFER
  252. END # end of label
  253. END # end of class
  254. END # States label layer ends here
  255. # End of LAYER DEFINITIONS -------------------------------
  256.  
  257. END # end of map file

我们的mapfile现在包含一个新的对象outputformat。此对象在map对象内定义,并与imagetype关键字一起使用。根据您使用MapServer编译的库,您可以有几个输出格式选择——gd库提供PNG(8位和24位)、GIF、JPEG和WBMP;gdal库是许多MapServer输入格式的源,也可以向PNG、JPEG、TIFF/GEOTIFF和其他RASTE提供输出。R格式;pdflib库提供PDF输出;ming库提供闪存输出。查看outputformat对象并通过更改mapfile上的imagetype关键字进行实验。输出格式的名称应用作imagetype值(例如:imagetype png或imagetype png24)。

请在以下位置查阅outputformat对象引用:
http://www.mapserver.org/mapfile/outputformat.html outputformat

Example 1.9: Interactive Maps and the Browse Mode

上面的地图是在“地图”模式下创建的。这是一个静态地图(单击它不会改变)。

这个动态地图是在“浏览”模式下生成的。点击地图上的任何一点,看看会发生什么。

这两个地图都使用相同的mapfiile文件定义。区别在于第二个地图(动态创建的地图)依赖于HTML表单进行交互。如果你看一下这个页面是如何与前一个页面链接的,你会发现它与前一个例子不一样。用mapserver的术语来说,这个页面就是一个HTML模板。您将在第2部分中了解有关HTML模板的更多信息。

查看此页面中的“表单”块(右键单击浏览器并选择“查看源代码”或类似内容):

  1. <!-- START OF MAPSERVER FORM -->
  2. <form name="mapserv" method="GET" action="/cgi-bin/mapserv.exe">
  3. <!-- HIDDEN MAPSERVER CGI VARIABLES -->
  4. <input type="hidden" name="map" value="[map]">
  5. <input type="hidden" name="imgext" value="[mapext]">
  6. <input type="hidden" name="imgxy" value="199.5 149.5">
  7. <input type="hidden" name="zoom" value="">
  8. <input type="hidden" name="mode" value="browse">
  9.  
  10. <div align="center">
  11. <table border="" cellpadding="" cellspacing="">
  12. <tr>
  13. <td>
  14. <!-- THE INTERACTIVE, DYNAMICALLY CREATED MAP --
  15. <input type="image" name="img" src="[img]"
  16. width="" height="">
  17. </td>
  18. </tr>
  19. </table>
  20. </div>
  21. </form>

每当用户单击地图时,此块执行mapserver cgi程序(“/cgi-bin/mapserv.exe”)。地图实际上是另一种形式的“输入”,在这里用行表示:

  1. <input type="image" name="img" src="[img]" width="400" height="300">

方括号([map]、[mapext]和[img])中的项称为mapserver标记——这些是mapserver cgi变量,在重新加载时会被mapserver cgi程序替换。标记[map]是mapfile路径的一个占位符,因此在运行mapserver时,它被替换为“/ms4w/apps/tutorial/htdocs/example1-9.map”。标记[mapext]替换为当前地图范围“91734.994981-533247.003346 1432483.085284 471473.996656”,并且[img]标记替换为mapserver cgi程序创建的图像路径,“/ms_tmp/ex1.9_156222312833540.png”。继续检查映像路径(/ms4w/tmp/)是否存在此映像。(这些参数是在.map文件里获取的吗?:)

值为“browse”的隐藏变量“mode”告诉CGI程序需要在“tmp”目录中创建和转储图像。然后,这个图像被引用为[img],这就是您在浏览器上看到的。

现在,看看地图文件:

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # MapServer map file uses the pound sign (#) to denote the start of a line
  6. # comment--each line that needs to be commented has to be prepended with a "#".
  7. #
  8. # Map files begin with MAP keyword to signify the start of the map object.
  9. # Well, the entire map file is THE map object. Enclosed between MAP and END
  10. # at the very bottom of this map file, are keyword/value pairs and other
  11. # objects.
  12. MAP
  13. NAME EX1.9_
  14. IMAGETYPE PNG24
  15. EXTENT - # LAEA
  16. #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic
  17. SIZE
  18. SHAPEPATH "../data"
  19. SYMBOLSET "../symbols/symbols35.sym"
  20. FONTSET "../fonts/fonts.list"
  21.  
  22. # The web object is defined at the level below the map object. All
  23. # web-related parameters (I interchange "parameters" and "keyword/value
  24. # pairs" quite frequently, sorry about that) are defined in this object.
  25. WEB
  26. TEMPLATE 'example1-9.html'
  27. IMAGEPATH '/ms4w/tmp/ms_tmp/'
  28. IMAGEURL '/ms_tmp/'
  29. END
  30.  
  31. # The projection object is typically used within the map and the layer
  32. # objects. You only define it once within the map object and this definition
  33. # becomes your output projection--MapServer will render your maps in this
  34. # projection. You also use the projection object within the layer object to
  35. # define your input projection. Your layers can be in different
  36. # projections--MapServer will reproject them into your output projection.
  37. # If no projection is defined within the layer object, MapServer assumes
  38. # your input projection is the same as your output projection. This is not
  39. # a required object unless you're creating a map file that supports one of
  40. # the OGC interoperability web services specifications (WMS/WFS/WCS).
  41. #
  42. # This is the output PROJECTION definition ------
  43. PROJECTION
  44. # Projection parameters can be defined in two ways...
  45. # This is the traditional Proj. definition of Lambert Azimuthal Equal-Area
  46. # projection for the Continental U.S.
  47. # "proj=laea"
  48. # "ellps=clrk66"
  49. # "lat_0=45"
  50. # "lon_0=-100"
  51. #
  52. # Alternatively, you can specify an EPSG code.
  53. # This is the EPSG code for Lambert Azimuthal Equal-Area
  54. # projection for the U.S.
  55. "init=epsg:2163"
  56. END
  57.  
  58. # Layer objects are defined beneath the map object. You need at least one
  59. # layer defined in your map file before you can display a map... You can
  60. # define as many layers as you'd like although a limit is typically hard-coded
  61. # in map.h in the MapServer source. The default limit is set at . You'd
  62. # have to have a very specialized application to need more than layers in
  63. # your application.
  64. #
  65. # Start of LAYER DEFINITIONS ---------------------------------------------
  66. LAYER # States polygon layer begins here
  67. NAME states
  68. DATA states_ugl
  69. STATUS OFF
  70. TYPE POLYGON
  71.  
  72. # Here's an example of the input projection definition.
  73. # EPSG: is code for geographic (latlong) projection
  74. # using the WGS84 datum.
  75. #
  76. # PROJECTION objects within the LAYER object define the input
  77. # projection--this is the native projection of your data.
  78. PROJECTION
  79. "init=epsg:4326"
  80. END
  81.  
  82. # CLASSITEM defines the non-spatial attribute that you will be using to
  83. # separate a layer into classes. This attribute will be in the DBF file
  84. # of your shapefile (it will be different for each data format). In this
  85. # example the shapefile states_ugl has an associated database
  86. # (states_ugl.dbf) that contains an attribute called "CLASS". You will be
  87. # using two values in the CLASS attribute to separate the classes (also
  88. # called themes) used in this layer--land and water. CLASSITEM is used in
  89. # association with the EXPRESSION parameter in the CLASS object. See below.
  90. CLASSITEM "CLASS"
  91.  
  92. CLASS
  93. EXPRESSION 'land'
  94. STYLE
  95. SYMBOL
  96. COLOR
  97. END
  98. END
  99. END # States polygon layer ends here
  100.  
  101. # In addition to vector data (shapefiles are vector data), MapServer supports
  102. # a host of raster formats. In GIS world, one of the most common raster
  103. # formats is GeoTIFF, a TIFF image with geospatial headers. MapServer also
  104. # supports JPEG, PNG, GIF, and other common formats. Other raster formats
  105. # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,
  106. # Generic raster binaries, OGC Web Map Service (WMS) layers, etc. Pretty much
  107. # any raster format you can think of is probably supported, thanks to the
  108. # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"
  109. # or GOODLE?). More information on GDAL is available at http://www.gdal.org.
  110. #
  111. # MapServer .x can read and display bitmapped (like GIFs), RGB/A (true
  112. # color), and multispectral (images with more than bands, like raw LandSat
  113. # images) rasters.
  114. LAYER # MODIS raster layer begins here
  115. NAME modis
  116. DATA "raster/mod09a12003161_ugl_ll_8bit.tif"
  117. STATUS OFF #DEFAULT
  118. TYPE RASTER
  119. PROCESSING "BANDS=1,2,3"
  120. OFFSITE
  121.  
  122. PROJECTION
  123. "init=epsg:4326"
  124. END
  125. END # MODIS raster layer ends here
  126.  
  127. LAYER # MODIS WMS map from JPL (or from USGS)
  128. NAME modis_jpl
  129. TYPE RASTER
  130. OFFSITE
  131. STATUS OFF #OFF
  132. CONNECTIONTYPE WMS
  133. CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?"
  134.  
  135. METADATA
  136. "wms_srs" "EPSG:4326"
  137. "wms_name" "daily_terra" #"global_mosaic" "daily_aqua"
  138. "wms_server_version" "1.1.1"
  139. "wms_format" "image/jpeg"
  140. END
  141.  
  142. PROJECTION
  143. "init=epsg:4326"
  144. END
  145. END # MODIS WMS image ends here
  146.  
  147. LAYER # States line layer begins here
  148. NAME states
  149. DATA states_ugl
  150. STATUS OFF
  151. TYPE LINE
  152.  
  153. PROJECTION
  154. "init=epsg:4326"
  155. END
  156.  
  157. CLASSITEM "CLASS"
  158. CLASS
  159. EXPRESSION 'land'
  160. STYLE
  161. SYMBOL 'line5'
  162. COLOR
  163. SIZE
  164. END
  165. END
  166. END # States line layer ends here
  167.  
  168. LAYER # States label layer begins here
  169. NAME states
  170. DATA states_ugl
  171. STATUS OFF
  172. TYPE POLYGON
  173.  
  174. PROJECTION
  175. "init=epsg:4326"
  176. END
  177.  
  178. CLASSITEM "CLASS"
  179. LABELITEM "STATE"
  180. CLASS
  181. EXPRESSION 'land'
  182. STYLE
  183. COLOR - - -
  184. END
  185. LABEL
  186. COLOR
  187. OUTLINECOLOR
  188. SHADOWCOLOR
  189. SHADOWSIZE
  190. TYPE TRUETYPE
  191. FONT arial-bold
  192. SIZE
  193. ANTIALIAS TRUE
  194. POSITION CL
  195. PARTIALS FALSE
  196. MINDISTANCE
  197. BUFFER
  198. END # end of label
  199. END # end of class
  200. END # States label layer ends here
  201. # End of LAYER DEFINITIONS -------------------------------
  202.  
  203. END # All map files must come to an end just as all other things must come to...
  204. # End of section , dude!

只有一件事被添加到map文件中:

TEMPLATE 'example1-9.html'

这将告诉MapServer使用页面“example1-9.html”作为模板文件。MapServer将处理此文件并替换它遇到的标记,然后将其发送到Web浏览器。本教程接下来的两个部分就是这样工作的。

这标志着第1节的结束。我希望您在本节中留下足够的知识,了解如何在MapServer映射文件中设置内容。在创建自己的映射文件和应用程序时,我不能过分强调保持MapServer映射文件引用打开的重要性。没有它,我就不会在这个教程中走得太远。

 Section 2: CGI variables and the User Interface

到目前为止,我们只在创建地图时查看了地图文件。在创建Web地图应用程序时,我们通常打算制作用户(应用程序的用户)可以交互更改的映射。也就是说,用户应该能够更改地图的内容(或其中的信息)。为了实现这种交互性,我们使用mapserver HTML模板。

MapServer HTML模板本质上是一个HTML文件,带有一些特定于MapServer的标记——这些标记是MapServer CGI变量带括在方括号“[]”中。当mapserver cgi程序处理一个应用程序时,它首先解析查询字符串和mapfile并生成必要的输出。其中一些输出将需要写入HTML模板文件,您还必须使用web template关键字(或单独的HTML初始化文件)在mapfile中指定该文件。CGI程序将用适当的值替换HTML模板中的所有变量,然后再将其发送回Web浏览器。如果要在Web浏览器上直接查看HTML模板,则不会呈现任何映射,而是会得到空白图像和其他垃圾。

MapServer为Web映射提供了几个变量——您在示例1.9中看到的“img”变量只是一个示例。最初作为绘图接口的一部分设计的核心CGI变量很少,但实际上所有mapfile参数都可以定义为变量。CGI变量的最终参考可在http://www.mapserver.org/cgi/index.html上找到。

我们还可以定义自己的变量——mapserver将把它传递给我们的应用程序。例如,我们可以创建一个名为“root”的变量来表示本教程的根目录——“root”的值将是“/tutorial”。当mapserver cgi程序处理我们的html模板时,它将用“/tutorial”替换他“[根]”标记的每个实例。您将在下面的每个示例中看到这一点。

所以,让我们为我们的应用程序构建一个交互式界面…

Example 2.1 - Pan and Zoom Controls
示例2.1-平移和缩放控件

Web地图应用程序的用户应该能够在地图上平移和缩放…

查看地图文件:

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # Map files begin with map keyword to signify the start of the map object.
  6. # Well, the entire map file is THE map object. Enclose between MAP and END
  7. # at the very bottom of this map file, are keyword/value pairs and other
  8. # objects.
  9. MAP
  10. NAME EX2_
  11. IMAGETYPE png24
  12. EXTENT - # LAEA
  13. #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic
  14. SIZE
  15. SHAPEPATH "../data"
  16. SYMBOLSET "../symbols/symbols35.sym"
  17. FONTSET "../fonts/fonts.list"
  18.  
  19. # When changing any of the mapfile parameters via the web interface, you
  20. # need to define a TEMPLATEPATTERN. This is required for security reasons.
  21. # Since the example filenames in section begin with "example2" (as in
  22. # example2-.html or example2-.html), you can use it as the pattern.
  23. # The template pattern is a regular expression used by MapServer to match the
  24. # value of map_web_template variable against.
  25. TEMPLATEPATTERN 'example2*'
  26.  
  27. # The web object is defined at the level below the map object. All
  28. # web-related parameters (I interchange "parameters" and "keyword/value
  29. # pairs" quite frequently, sorry about that) are defined in this object.
  30. WEB
  31. TEMPLATE 'to be replaced by map_web_template variable in section2.html'
  32. IMAGEPATH '/ms4w/tmp/ms_tmp/'
  33. IMAGEURL '/ms_tmp/'
  34. END # Every object in MapServer must have an END.;)
  35.  
  36. # The projection object is typically used within the map and the layer
  37. # objects. You only define it once within the map object and this definition
  38. # becomes your output projection--MapServer will render your maps in this
  39. # projection. You also use the projection object within the layer object to
  40. # define your input projection. Your layers can be in different
  41. # projections--MapServer will reproject them into your output projection.
  42. # If no projection is defined within the layer object, MapServer assumes
  43. # your input projection is the same as your output projection. This is not
  44. # a required object unless you're creating a map file that supports one of
  45. # the OGC interoperability web services specifications (WMS/WFS/WCS).
  46. PROJECTION
  47. # Projection parameters can be defined in two ways...
  48. # This is the traditional Proj. definition of Lambert Azimuthal Equal-Area
  49. # projection for the Continental U.S.
  50. # "proj=laea"
  51. # "ellps=clrk66"
  52. # "lat_0=45"
  53. # "lon_0=-100"
  54. #
  55. # Alternatively, you can specify an EPSG code.
  56. # This is the EPSG code for Lambert Azimuthal Equal-Area
  57. # projection for the U.S.
  58. "init=epsg:2163"
  59. END # This is the ending of the output projection
  60.  
  61. #
  62. # Start of legend
  63. #
  64. LEGEND
  65. KEYSIZE
  66. LABEL
  67. TYPE BITMAP
  68. SIZE MEDIUM
  69. COLOR
  70. END
  71. STATUS ON
  72. END
  73.  
  74. # The reference object is used to define a reference map for your mapping
  75. # application. This typically involves defining a small image that covers
  76. # the entire area of the map and defining a box that represents the current
  77. # view on in relation to the entire area.
  78. REFERENCE
  79. IMAGE '../images/ugl_ref1.png' # The reference image
  80. SIZE # The size of the reference image in pixels
  81. EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units
  82. STATUS ON
  83. MINBOXSIZE # How small can the reference box be before it gets drawn as a point, in pixels
  84. MAXBOXSIZE # The maximum size of the reference box, in pixels
  85. COLOR - - - # The reference box fill color, negative numbers mean transparent
  86. OUTLINECOLOR # The reference box outline color
  87. MARKERSIZE # The size of the point marker
  88. MARKER 'star' # The marker symbol
  89. END
  90.  
  91. # A scalebar object is defined one level below the map object. This object
  92. # controls how a scalebar is drawn by MapServer. Scalebars can be embedded
  93. # in the map itself or can be created as a separate image. It has an
  94. # associated MapServer CGI variable called "scalebar" (or [scalebar] when
  95. # used in the HTML template).
  96. SCALEBAR
  97. IMAGECOLOR
  98. LABEL
  99. COLOR
  100. SIZE TINY
  101. END
  102. STYLE
  103. SIZE
  104. COLOR
  105. UNITS MILES
  106. INTERVALS
  107. TRANSPARENT FALSE
  108. STATUS ON
  109. END # Scalebar object ends
  110.  
  111. # Layer objects, too, are defined beneath the map object. Be mindful of the
  112. # order of your layer objects. MapServer "stacks them" in reverse
  113. # order--that is, the last layer you define (at the bottom of the map file)
  114. # will be drawn on top and the first layer you define (right after this
  115. # comment), will be drawn at the bottom. Here's my rule: rasters and
  116. # polygons are defined first, followed by the line layers. The point and
  117. # annotation layers are defined last. You can play around with the ordering
  118. # of your layers until you're satisfied.
  119.  
  120. # Start of LAYER DEFINITIONS ---------------------------------------------
  121. LAYER # States polygon layer begins here
  122. NAME states
  123. DATA states_ugl
  124. STATUS DEFAULT
  125. TYPE POLYGON
  126. REQUIRES "![modis] OR ![modis_jpl]"
  127.  
  128. # Here's an example of the input projection definition.
  129. # EPSG: is code for geographic (latlong) projection
  130. # using the WGS84 datum
  131. PROJECTION
  132. "init=epsg:4326"
  133. END
  134.  
  135. CLASSITEM "CLASS"
  136.  
  137. # The class object is defined within the layer object. You can define as
  138. # many classes as you need (well, there are limits, but it's senseless to
  139. # define more than ten on a "normal" layer. There are situations,
  140. # however, where you might have to do it.)
  141. CLASS
  142. EXPRESSION 'land'
  143.  
  144. # There are styles in a class, just like there are classes in a layer,
  145. # just like there are layers in a map.
  146. STYLE
  147. SYMBOL
  148. COLOR
  149. END # And they all must come to an end.
  150. END # End of this class.
  151. END # States polygon layer ends here
  152.  
  153. LAYER # MODIS raster layer begins here
  154. NAME modis
  155. DATA "raster/mod09a12003161_ugl_ll_idxa.tif"
  156. STATUS OFF
  157. TYPE RASTER
  158. OFFSITE #
  159.  
  160. PROJECTION
  161. "init=epsg:4326"
  162. END
  163. END # MODIS raster layer ends here
  164.  
  165. LAYER # MODIS WMS map from JPL (or from USGS)
  166. NAME modis_jpl
  167. TYPE RASTER
  168. OFFSITE
  169. STATUS OFF
  170. CONNECTIONTYPE WMS
  171. CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?"
  172.  
  173. METADATA
  174. "wms_srs" "EPSG:4326"
  175. "wms_name" "daily_terra" #"global_mosaic" "daily_aqua"
  176. "wms_server_version" "1.1.1"
  177. "wms_format" "image/jpeg"
  178. END
  179.  
  180. PROJECTION
  181. "init=epsg:4326"
  182. END
  183. END # MODIS WMS image ends here
  184.  
  185. LAYER # Hydrography layer begins here
  186. NAME hydro
  187. TYPE POLYGON
  188. STATUS OFF
  189. DATA hydrop_ugl
  190.  
  191. PROJECTION
  192. "init=epsg:4326"
  193. END
  194.  
  195. CLASSITEM 'FEATURE'
  196. CLASS
  197. NAME 'Lakes'
  198. EXPRESSION /(^B|^C|^L|^R)./
  199. STYLE
  200. COLOR
  201. END
  202. END # CLASS
  203. CLASS
  204. NAME 'Rivers'
  205. EXPRESSION 'Stream'
  206. STYLE
  207. COLOR
  208. END
  209. END # CLASS
  210. CLASS
  211. NAME 'Wetlands'
  212. EXPRESSION 'Swamp or Marsh'
  213. STYLE
  214. COLOR
  215. OUTLINECOLOR
  216. SYMBOL 'circle'
  217. SIZE
  218. END
  219. END # CLASS
  220. END # LAYER
  221.  
  222. LAYER # ROADS LAYER
  223. NAME cty_roads
  224. GROUP roads
  225. TYPE LINE
  226. STATUS OFF
  227. DATA roads_ugl
  228. MAXSCALE
  229.  
  230. PROJECTION
  231. "init=epsg:4326"
  232. END
  233.  
  234. CLASSITEM 'CLASS1'
  235. CLASS
  236. NAME 'Minor Arterial Roads'
  237. EXPRESSION ''
  238. STYLE
  239. COLOR
  240. END
  241. END # CLASS
  242. CLASS
  243. EXPRESSION ''
  244. STYLE
  245. COLOR
  246. END
  247. END # CLASS
  248. END # ROADS LAYER
  249.  
  250. LAYER # state highways begin here
  251. NAME state_hwy
  252. GROUP roads
  253. MAXSCALE
  254. STATUS OFF
  255. DATA roads_ugl
  256. TYPE LINE
  257. FILTERITEM 'CLASS1'
  258. FILTER ''
  259.  
  260. CLASS
  261. NAME 'Principal Arterial Roads'
  262. STYLE
  263. COLOR
  264. SIZE
  265. SYMBOL 'circle'
  266. END
  267. END
  268.  
  269. PROJECTION
  270. "init=epsg:4326"
  271. END
  272. END # highways
  273.  
  274. LAYER # interstate highways begin here
  275. NAME interstate
  276. GROUP roads
  277. # MAXSCALE
  278. STATUS OFF
  279. DATA roads_ugl
  280. TYPE LINE
  281. FILTERITEM 'CLASS1'
  282. FILTER ''
  283.  
  284. CLASS
  285. NAME "Interstate Hwy."
  286. STYLE
  287. COLOR
  288. END
  289. END
  290.  
  291. PROJECTION
  292. "init=epsg:4326"
  293. END
  294. END # highways
  295.  
  296. LAYER # States line layer begins here
  297. NAME states
  298. DATA states_ugl
  299. STATUS OFF
  300. TYPE LINE
  301.  
  302. PROJECTION
  303. "init=epsg:4326"
  304. END
  305.  
  306. CLASSITEM "CLASS"
  307. CLASS
  308. NAME 'State Boundary'
  309. EXPRESSION 'land'
  310. STYLE
  311. SYMBOL 'line5'
  312. COLOR
  313. SIZE
  314. END
  315. END
  316. END # States line layer ends here
  317.  
  318. LAYER
  319. NAME roads_anno
  320. GROUP roads
  321. MAXSCALE
  322. STATUS OFF
  323. DATA roads_ugl
  324. TYPE POLYGON
  325. LABELITEM "SIGN"
  326. CLASSITEM "CLASS1"
  327. CLASS
  328. EXPRESSION ""
  329. STYLE
  330. COLOR # dummy color
  331. SYMBOL '../symbols/sthwy.png'
  332. END
  333. LABEL
  334. MINFEATURESIZE
  335. MINDISTANCE
  336. POSITION CC
  337. SIZE TINY
  338. COLOR
  339. END
  340. END
  341. CLASS
  342. EXPRESSION ""
  343. STYLE
  344. COLOR # dummy color
  345. SYMBOL '../symbols/ushwy.png'
  346. END
  347. LABEL
  348. MINFEATURESIZE
  349. MINDISTANCE
  350. POSITION CC
  351. SIZE TINY
  352. COLOR
  353. END
  354. END
  355.  
  356. PROJECTION
  357. "init=epsg:4326"
  358. END
  359. END # highway annotation
  360.  
  361. LAYER
  362. NAME roads_anno1
  363. GROUP roads
  364. STATUS OFF
  365. DATA roads_ugl
  366. TYPE POLYGON
  367. LABELITEM "SIGN"
  368. CLASSITEM "CLASS1"
  369. CLASS
  370. EXPRESSION ""
  371. STYLE
  372. COLOR # dummy color
  373. SYMBOL '../symbols/interstate.png'
  374. END
  375. LABEL
  376. MINFEATURESIZE
  377. MINDISTANCE
  378. POSITION CC
  379. SIZE TINY
  380. COLOR
  381. END
  382. END
  383.  
  384. PROJECTION
  385. "init=epsg:4326"
  386. END
  387. END
  388.  
  389. LAYER # States label layer begins here
  390. NAME states
  391. DATA states_ugl
  392. STATUS OFF
  393. TYPE POLYGON
  394.  
  395. PROJECTION
  396. "init=epsg:4326"
  397. END
  398.  
  399. CLASSITEM "CLASS"
  400. LABELITEM "STATE"
  401. CLASS
  402. EXPRESSION 'land'
  403. STYLE
  404. COLOR - - -
  405. END
  406. LABEL
  407. COLOR
  408. OUTLINECOLOR
  409. SHADOWCOLOR
  410. SHADOWSIZE
  411. TYPE TRUETYPE
  412. FONT arial-bold
  413. SIZE
  414. ANTIALIAS TRUE
  415. POSITION CL
  416. PARTIALS FALSE
  417. MINDISTANCE
  418. BUFFER
  419. END # end of label
  420. END # end of class
  421. END # States label layer ends here
  422. # End of LAYER DEFINITIONS -------------------------------
  423.  
  424. END # end of map file

与第1节中的映射一样,我们通过调用mapserv(“/cgi-bin/mapserv.exe”)初始化应用程序。并将我们的mapfile路径和其他参数(“map=/ms4w/apps/tutorial/htdocs/example2-1.map&amp;mode=browse”)传递给它。所以这个页面有一个来自第2节页面的链接,如下所示:

  1. <a href="/cgi-bin/mapserv.exe?
  2. map=/ms4w/apps/tutorial/htdocs/example2-.map
  3. &mode=browse&root=/tutorial&program=/cgi-bin/mapserv.exe
  4. &map_web=template+example2-.html">
  5. Proceed to Example 2.1</a>

这次我们使用“浏览”模式而不是“地图”。浏览模式告诉mapserv在我们的“/tmp/”目录上创建一个映射(一个图像)。图像路径和名称由名称为“img”的mapserv引用。因此,当mapserv解析我们的HTML模板时,它将用正确的图像路径替换“[img]”/ms_tmp/ex2_156231592315176.png。

你可以用这张地图做一些事情。首先,您可以单击图像的任何部分,地图将刷新并使您单击的点居中。这是平移。如果单击“地图控件”下拉框,可以选择“放大”或“缩小”值。如果将其设置为“放大2倍”,然后单击地图的任何部分,地图将刷新、放大,并以单击的点为中心。反之,如果你缩小。当选择“放大”或“缩小”值并单击“刷新”按钮时,地图将刷新并放大或缩小上一个地图的中心。您可以随时使用“刷新”按钮刷新地图。

缩放/平移控件使用内部mapserver cgi变量。此示例演示如何使用“zoom”变量。缩放值决定放大或缩小的距离。如果值为“0”,则MapServer将根据用户的鼠标单击重新输入图像。如果该值大于“0”,则CGI程序放大(地图的当前比例乘以缩放值)。如果是负数,那么CGI程序会缩小(将当前比例除以缩放值)。其他可用于控制缩放和平移的变量有“zoomdir”和“zoomsize”。这两个变量的作用与“缩放”差不多——“zoomdir”控制缩放方向,“zoomsize”控制放大或缩小的距离。请查看osgeo库或mapserver wiki上的其他示例,以获取其他缩放/平移控制选项。

尝试将“地图模式”从“浏览”更改为“地图”。单击刷新时会发生什么?记住,当我们使用“模式=映射”时,mapserver会返回一个静态映射…它忽略HTML模板,只将映射图像直接流式传输到浏览器。

尽管添加了更多的数据层,但它仍然与第一节中的映射文件相似。我没有什么新的东西可以解释这个地图文件,但是如果你对一些新的关键字感兴趣,请查阅地图文件参考页。

现在,看看HTML模板文件。您会注意到这实际上是一个调用mapserver cgi程序的HTML表单。因为它是一个表单,所以您可以使用单选按钮和复选框以及下拉框来实现您的界面。不要觉得受这个例子的限制——有创造力是件好事。;)有关详细信息,请查看HTML模板引用页。

……他们还应该能够打开和关闭地图上的图层。
示例2.2-层控制

能够打开和关闭地图层是Web映射应用程序的标准功能。使用表单对象作为控件有很多方法可以实现这一点。您可以使用下拉框/菜单、复选框和/或单选按钮。在本例中,您将看到如何使用复选框和放置框实现层选择。

这里是mapfile:

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # Map files begin with map keyword to signify the start of the map object.
  6. # Well, the entire map file is THE map object. Enclose between MAP and END
  7. # at the very bottom of this map file, are keyword/value pairs and other
  8. # objects.
  9. MAP
  10. NAME EX2_
  11. IMAGETYPE png24
  12. EXTENT - # LAEA
  13. #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic
  14. SIZE
  15. SHAPEPATH "../data"
  16. SYMBOLSET "../symbols/symbols35.sym"
  17. FONTSET "../fonts/fonts.list"
  18.  
  19. # When changing any of the mapfile parameters via the web interface, you
  20. # need to define a TEMPLATEPATTERN. This is required for security reasons.
  21. # Since the example filenames in section begin with "example2" (as in
  22. # example2-.html or example2-.html), you can use it as the pattern.
  23. # The template pattern is a regular expression used by MapServer to match the
  24. # value of map_web_template variable against.
  25. TEMPLATEPATTERN 'example2*'
  26.  
  27. # The web object is defined at the level below the map object. All
  28. # web-related parameters (I interchange "parameters" and "keyword/value
  29. # pairs" quite frequently, sorry about that) are defined in this object.
  30. WEB
  31. TEMPLATE 'to be replaced by map_web_template variable in section2.html'
  32. IMAGEPATH '/ms4w/tmp/ms_tmp/'
  33. IMAGEURL '/ms_tmp/'
  34. END # Every object in MapServer must have an END.;)
  35.  
  36. # The projection object is typically used within the map and the layer
  37. # objects. You only define it once within the map object and this definition
  38. # becomes your output projection--MapServer will render your maps in this
  39. # projection. You also use the projection object within the layer object to
  40. # define your input projection. Your layers can be in different
  41. # projections--MapServer will reproject them into your output projection.
  42. # If no projection is defined within the layer object, MapServer assumes
  43. # your input projection is the same as your output projection. This is not
  44. # a required object unless you're creating a map file that supports one of
  45. # the OGC interoperability web services specifications (WMS/WFS/WCS).
  46. PROJECTION
  47. # Projection parameters can be defined in two ways...
  48. # This is the traditional Proj. definition of Lambert Azimuthal Equal-Area
  49. # projection for the Continental U.S.
  50. # "proj=laea"
  51. # "ellps=clrk66"
  52. # "lat_0=45"
  53. # "lon_0=-100"
  54. #
  55. # Alternatively, you can specify an EPSG code.
  56. # This is the EPSG code for Lambert Azimuthal Equal-Area
  57. # projection for the U.S.
  58. "init=epsg:2163"
  59. END # This is the ending of the output projection
  60.  
  61. #
  62. # Start of legend
  63. #
  64. LEGEND
  65. KEYSIZE
  66. LABEL
  67. TYPE BITMAP
  68. SIZE MEDIUM
  69. COLOR
  70. END
  71. STATUS ON
  72. END
  73.  
  74. # The reference object is used to define a reference map for your mapping
  75. # application. This typically involves defining a small image that covers
  76. # the entire area of the map and defining a box that represents the current
  77. # view on in relation to the entire area.
  78. REFERENCE
  79. IMAGE '../images/ugl_ref1.png' # The reference image
  80. SIZE # The size of the reference image in pixels
  81. EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units
  82. STATUS ON
  83. MINBOXSIZE # How small can the reference box be before it gets drawn as a point, in pixels
  84. MAXBOXSIZE # The maximum size of the reference box, in pixels
  85. COLOR - - - # The reference box fill color, negative numbers mean transparent
  86. OUTLINECOLOR # The reference box outline color
  87. MARKERSIZE # The size of the point marker
  88. MARKER 'star' # The marker symbol
  89. END
  90.  
  91. # A scalebar object is defined one level below the map object. This object
  92. # controls how a scalebar is drawn by MapServer. Scalebars can be embedded
  93. # in the map itself or can be created as a separate image. It has an
  94. # associated MapServer CGI variable called "scalebar" (or [scalebar] when
  95. # used in the HTML template).
  96. SCALEBAR
  97. IMAGECOLOR
  98. LABEL
  99. COLOR
  100. SIZE TINY
  101. END
  102. STYLE
  103. SIZE
  104. COLOR
  105. UNITS MILES
  106. INTERVALS
  107. TRANSPARENT FALSE
  108. STATUS ON
  109. END # Scalebar object ends
  110.  
  111. # Layer objects, too, are defined beneath the map object. Be mindful of the
  112. # order of your layer objects. MapServer "stacks them" in reverse
  113. # order--that is, the last layer you define (at the bottom of the map file)
  114. # will be drawn on top and the first layer you define (right after this
  115. # comment), will be drawn at the bottom. Here's my rule: rasters and
  116. # polygons are defined first, followed by the line layers. The point and
  117. # annotation layers are defined last. You can play around with the ordering
  118. # of your layers until you're satisfied.
  119.  
  120. # Start of LAYER DEFINITIONS ---------------------------------------------
  121. LAYER # States polygon layer begins here
  122. NAME states
  123. DATA states_ugl
  124. STATUS DEFAULT
  125. TYPE POLYGON
  126. REQUIRES "![modis] OR ![modis_jpl]"
  127.  
  128. # Here's an example of the input projection definition.
  129. # EPSG: is code for geographic (latlong) projection
  130. # using the WGS84 datum
  131. PROJECTION
  132. "init=epsg:4326"
  133. END
  134.  
  135. CLASSITEM "CLASS"
  136.  
  137. # The class object is defined within the layer object. You can define as
  138. # many classes as you need (well, there are limits, but it's senseless to
  139. # define more than ten on a "normal" layer. There are situations,
  140. # however, where you might have to do it.)
  141. CLASS
  142. EXPRESSION 'land'
  143.  
  144. # There are styles in a class, just like there are classes in a layer,
  145. # just like there are layers in a map.
  146. STYLE
  147. SYMBOL
  148. COLOR
  149. END # And they all must come to an end.
  150. END # End of this class.
  151. END # States polygon layer ends here
  152.  
  153. LAYER # MODIS raster layer begins here
  154. NAME modis
  155. DATA "raster/mod09a12003161_ugl_ll_idxa.tif"
  156. STATUS OFF
  157. TYPE RASTER
  158. OFFSITE #
  159.  
  160. PROJECTION
  161. "init=epsg:4326"
  162. END
  163. END # MODIS raster layer ends here
  164.  
  165. LAYER # MODIS WMS map from JPL (or from USGS)
  166. NAME modis_jpl
  167. TYPE RASTER
  168. OFFSITE
  169. STATUS OFF
  170. CONNECTIONTYPE WMS
  171. CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?"
  172.  
  173. METADATA
  174. "wms_srs" "EPSG:4326"
  175. "wms_name" "daily_terra" #"global_mosaic" "daily_aqua"
  176. "wms_server_version" "1.1.1"
  177. "wms_format" "image/jpeg"
  178. END
  179.  
  180. PROJECTION
  181. "init=epsg:4326"
  182. END
  183. END # MODIS WMS image ends here
  184.  
  185. LAYER # Hydrography layer begins here
  186. NAME hydro
  187. TYPE POLYGON
  188. STATUS OFF
  189. DATA hydrop_ugl
  190.  
  191. PROJECTION
  192. "init=epsg:4326"
  193. END
  194.  
  195. CLASSITEM 'FEATURE'
  196. CLASS
  197. NAME 'Lakes'
  198. EXPRESSION /(^B|^C|^L|^R)./
  199. STYLE
  200. COLOR
  201. END
  202. END # CLASS
  203. CLASS
  204. NAME 'Rivers'
  205. EXPRESSION 'Stream'
  206. STYLE
  207. COLOR
  208. END
  209. END # CLASS
  210. CLASS
  211. NAME 'Wetlands'
  212. EXPRESSION 'Swamp or Marsh'
  213. STYLE
  214. COLOR
  215. OUTLINECOLOR
  216. SYMBOL 'circle'
  217. SIZE
  218. END
  219. END # CLASS
  220. END # LAYER
  221.  
  222. LAYER # ROADS LAYER
  223. NAME cty_roads
  224. GROUP roads
  225. TYPE LINE
  226. STATUS OFF
  227. DATA roads_ugl
  228. MAXSCALE
  229.  
  230. PROJECTION
  231. "init=epsg:4326"
  232. END
  233.  
  234. CLASSITEM 'CLASS1'
  235. CLASS
  236. NAME 'Minor Arterial Roads'
  237. EXPRESSION ''
  238. STYLE
  239. COLOR
  240. END
  241. END # CLASS
  242. CLASS
  243. EXPRESSION ''
  244. STYLE
  245. COLOR
  246. END
  247. END # CLASS
  248. END # ROADS LAYER
  249.  
  250. LAYER # state highways begin here
  251. NAME state_hwy
  252. GROUP roads
  253. MAXSCALE
  254. STATUS OFF
  255. DATA roads_ugl
  256. TYPE LINE
  257. FILTERITEM 'CLASS1'
  258. FILTER ''
  259.  
  260. CLASS
  261. NAME 'Principal Arterial Roads'
  262. STYLE
  263. COLOR
  264. SIZE
  265. SYMBOL 'circle'
  266. END
  267. END
  268.  
  269. PROJECTION
  270. "init=epsg:4326"
  271. END
  272. END # highways
  273.  
  274. LAYER # interstate highways begin here
  275. NAME interstate
  276. GROUP roads
  277. # MAXSCALE
  278. STATUS OFF
  279. DATA roads_ugl
  280. TYPE LINE
  281. FILTERITEM 'CLASS1'
  282. FILTER ''
  283.  
  284. CLASS
  285. NAME "Interstate Hwy."
  286. STYLE
  287. COLOR
  288. END
  289. END
  290.  
  291. PROJECTION
  292. "init=epsg:4326"
  293. END
  294. END # highways
  295.  
  296. LAYER # States line layer begins here
  297. NAME states
  298. DATA states_ugl
  299. STATUS OFF
  300. TYPE LINE
  301.  
  302. PROJECTION
  303. "init=epsg:4326"
  304. END
  305.  
  306. CLASSITEM "CLASS"
  307. CLASS
  308. NAME 'State Boundary'
  309. EXPRESSION 'land'
  310. STYLE
  311. SYMBOL 'line5'
  312. COLOR
  313. SIZE
  314. END
  315. END
  316. END # States line layer ends here
  317.  
  318. LAYER
  319. NAME roads_anno
  320. GROUP roads
  321. MAXSCALE
  322. STATUS OFF
  323. DATA roads_ugl
  324. TYPE POLYGON
  325. LABELITEM "SIGN"
  326. CLASSITEM "CLASS1"
  327. CLASS
  328. EXPRESSION ""
  329. STYLE
  330. COLOR # dummy color
  331. SYMBOL '../symbols/sthwy.png'
  332. END
  333. LABEL
  334. MINFEATURESIZE
  335. MINDISTANCE
  336. POSITION CC
  337. SIZE TINY
  338. COLOR
  339. END
  340. END
  341. CLASS
  342. EXPRESSION ""
  343. STYLE
  344. COLOR # dummy color
  345. SYMBOL '../symbols/ushwy.png'
  346. END
  347. LABEL
  348. MINFEATURESIZE
  349. MINDISTANCE
  350. POSITION CC
  351. SIZE TINY
  352. COLOR
  353. END
  354. END
  355.  
  356. PROJECTION
  357. "init=epsg:4326"
  358. END
  359. END # highway annotation
  360.  
  361. LAYER
  362. NAME roads_anno1
  363. GROUP roads
  364. STATUS OFF
  365. DATA roads_ugl
  366. TYPE POLYGON
  367. LABELITEM "SIGN"
  368. CLASSITEM "CLASS1"
  369. CLASS
  370. EXPRESSION ""
  371. STYLE
  372. COLOR # dummy color
  373. SYMBOL '../symbols/interstate.png'
  374. END
  375. LABEL
  376. MINFEATURESIZE
  377. MINDISTANCE
  378. POSITION CC
  379. SIZE TINY
  380. COLOR
  381. END
  382. END
  383.  
  384. PROJECTION
  385. "init=epsg:4326"
  386. END
  387. END
  388.  
  389. LAYER # States label layer begins here
  390. NAME states
  391. DATA states_ugl
  392. STATUS OFF
  393. TYPE POLYGON
  394.  
  395. PROJECTION
  396. "init=epsg:4326"
  397. END
  398.  
  399. CLASSITEM "CLASS"
  400. LABELITEM "STATE"
  401. CLASS
  402. EXPRESSION 'land'
  403. STYLE
  404. COLOR - - -
  405. END
  406. LABEL
  407. COLOR
  408. OUTLINECOLOR
  409. SHADOWCOLOR
  410. SHADOWSIZE
  411. TYPE TRUETYPE
  412. FONT arial-bold
  413. SIZE
  414. ANTIALIAS TRUE
  415. POSITION CL
  416. PARTIALS FALSE
  417. MINDISTANCE
  418. BUFFER
  419. END # end of label
  420. END # end of class
  421. END # States label layer ends here
  422. # End of LAYER DEFINITIONS -------------------------------
  423.  
  424. END # end of map file

注意图层的STATUS已经被改为OFF,除了“States”多边形背景。

状态背景保留为默认设置,因此在绘制地图时,如果不打开任何图层,则始终会显示某些内容。应用程序的用户应该能够控制打开或关闭哪些层。
如果您查看HTML模板的源代码,您将了解mapserv如何打开/关闭层。

地图应始终包含一个scaleBar。
示例2.3-添加scaleBar

这里是mapfile文件:

  1. # The annotated map file (sort of)
  2. # Created by Pericles S. Nacionales for the MapServer tutorial
  3. #
  4. #
  5. # Map files begin with map keyword to signify the start of the map object.
  6. # Well, the entire map file is THE map object. Enclose between MAP and END
  7. # at the very bottom of this map file, are keyword/value pairs and other
  8. # objects.
  9. MAP
  10. NAME EX2_
  11. IMAGETYPE png24
  12. EXTENT - # LAEA
  13. #EXTENT -97.5 41.619778 -82.122902 49.38562 # Geographic
  14. SIZE
  15. SHAPEPATH "../data"
  16. SYMBOLSET "../symbols/symbols35.sym"
  17. FONTSET "../fonts/fonts.list"
  18.  
  19. # When changing any of the mapfile parameters via the web interface, you
  20. # need to define a TEMPLATEPATTERN. This is required for security reasons.
  21. # Since the example filenames in section begin with "example2" (as in
  22. # example2-.html or example2-.html), you can use it as the pattern.
  23. # The template pattern is a regular expression used by MapServer to match the
  24. # value of map_web_template variable against.
  25. TEMPLATEPATTERN 'example2*'
  26.  
  27. # The web object is defined at the level below the map object. All
  28. # web-related parameters (I interchange "parameters" and "keyword/value
  29. # pairs" quite frequently, sorry about that) are defined in this object.
  30. WEB
  31. TEMPLATE 'to be replaced by map_web_template variable in section2.html'
  32. IMAGEPATH '/ms4w/tmp/ms_tmp/'
  33. IMAGEURL '/ms_tmp/'
  34. END # Every object in MapServer must have an END.;)
  35.  
  36. # The projection object is typically used within the map and the layer
  37. # objects. You only define it once within the map object and this definition
  38. # becomes your output projection--MapServer will render your maps in this
  39. # projection. You also use the projection object within the layer object to
  40. # define your input projection. Your layers can be in different
  41. # projections--MapServer will reproject them into your output projection.
  42. # If no projection is defined within the layer object, MapServer assumes
  43. # your input projection is the same as your output projection. This is not
  44. # a required object unless you're creating a map file that supports one of
  45. # the OGC interoperability web services specifications (WMS/WFS/WCS).
  46. PROJECTION
  47. # Projection parameters can be defined in two ways...
  48. # This is the traditional Proj. definition of Lambert Azimuthal Equal-Area
  49. # projection for the Continental U.S.
  50. # "proj=laea"
  51. # "ellps=clrk66"
  52. # "lat_0=45"
  53. # "lon_0=-100"
  54. #
  55. # Alternatively, you can specify an EPSG code.
  56. # This is the EPSG code for Lambert Azimuthal Equal-Area
  57. # projection for the U.S.
  58. "init=epsg:2163"
  59. END # This is the ending of the output projection
  60.  
  61. #
  62. # Start of legend
  63. #
  64. LEGEND
  65. KEYSIZE
  66. LABEL
  67. TYPE BITMAP
  68. SIZE MEDIUM
  69. COLOR
  70. END
  71. STATUS ON
  72. END
  73.  
  74. # The reference object is used to define a reference map for your mapping
  75. # application. This typically involves defining a small image that covers
  76. # the entire area of the map and defining a box that represents the current
  77. # view on in relation to the entire area.
  78. REFERENCE
  79. IMAGE '../images/ugl_ref1.png' # The reference image
  80. SIZE # The size of the reference image in pixels
  81. EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units
  82. STATUS ON
  83. MINBOXSIZE # How small can the reference box be before it gets drawn as a point, in pixels
  84. MAXBOXSIZE # The maximum size of the reference box, in pixels
  85. COLOR - - - # The reference box fill color, negative numbers mean transparent
  86. OUTLINECOLOR # The reference box outline color
  87. MARKERSIZE # The size of the point marker
  88. MARKER 'star' # The marker symbol
  89. END
  90.  
  91. # A scalebar object is defined one level below the map object. This object
  92. # controls how a scalebar is drawn by MapServer. Scalebars can be embedded
  93. # in the map itself or can be created as a separate image. It has an
  94. # associated MapServer CGI variable called "scalebar" (or [scalebar] when
  95. # used in the HTML template).
  96. SCALEBAR
  97. IMAGECOLOR
  98. LABEL
  99. COLOR
  100. SIZE TINY
  101. END
  102. STYLE
  103. SIZE
  104. COLOR
  105. UNITS MILES
  106. INTERVALS
  107. TRANSPARENT FALSE
  108. STATUS ON
  109. END # Scalebar object ends
  110.  
  111. # Layer objects, too, are defined beneath the map object. Be mindful of the
  112. # order of your layer objects. MapServer "stacks them" in reverse
  113. # order--that is, the last layer you define (at the bottom of the map file)
  114. # will be drawn on top and the first layer you define (right after this
  115. # comment), will be drawn at the bottom. Here's my rule: rasters and
  116. # polygons are defined first, followed by the line layers. The point and
  117. # annotation layers are defined last. You can play around with the ordering
  118. # of your layers until you're satisfied.
  119.  
  120. # Start of LAYER DEFINITIONS ---------------------------------------------
  121. LAYER # States polygon layer begins here
  122. NAME states
  123. DATA states_ugl
  124. STATUS DEFAULT
  125. TYPE POLYGON
  126. REQUIRES "![modis] OR ![modis_jpl]"
  127.  
  128. # Here's an example of the input projection definition.
  129. # EPSG: is code for geographic (latlong) projection
  130. # using the WGS84 datum
  131. PROJECTION
  132. "init=epsg:4326"
  133. END
  134.  
  135. CLASSITEM "CLASS"
  136.  
  137. # The class object is defined within the layer object. You can define as
  138. # many classes as you need (well, there are limits, but it's senseless to
  139. # define more than ten on a "normal" layer. There are situations,
  140. # however, where you might have to do it.)
  141. CLASS
  142. EXPRESSION 'land'
  143.  
  144. # There are styles in a class, just like there are classes in a layer,
  145. # just like there are layers in a map.
  146. STYLE
  147. SYMBOL
  148. COLOR
  149. END # And they all must come to an end.
  150. END # End of this class.
  151. END # States polygon layer ends here
  152.  
  153. LAYER # MODIS raster layer begins here
  154. NAME modis
  155. DATA "raster/mod09a12003161_ugl_ll_idxa.tif"
  156. STATUS OFF
  157. TYPE RASTER
  158. OFFSITE #
  159.  
  160. PROJECTION
  161. "init=epsg:4326"
  162. END
  163. END # MODIS raster layer ends here
  164.  
  165. LAYER # MODIS WMS map from JPL (or from USGS)
  166. NAME modis_jpl
  167. TYPE RASTER
  168. OFFSITE
  169. STATUS OFF
  170. CONNECTIONTYPE WMS
  171. CONNECTION "http://wms.jpl.nasa.gov/wms.cgi?"
  172.  
  173. METADATA
  174. "wms_srs" "EPSG:4326"
  175. "wms_name" "daily_terra" #"global_mosaic" "daily_aqua"
  176. "wms_server_version" "1.1.1"
  177. "wms_format" "image/jpeg"
  178. END
  179.  
  180. PROJECTION
  181. "init=epsg:4326"
  182. END
  183. END # MODIS WMS image ends here
  184.  
  185. LAYER # Hydrography layer begins here
  186. NAME hydro
  187. TYPE POLYGON
  188. STATUS OFF
  189. DATA hydrop_ugl
  190.  
  191. PROJECTION
  192. "init=epsg:4326"
  193. END
  194.  
  195. CLASSITEM 'FEATURE'
  196. CLASS
  197. NAME 'Lakes'
  198. EXPRESSION /(^B|^C|^L|^R)./
  199. STYLE
  200. COLOR
  201. END
  202. END # CLASS
  203. CLASS
  204. NAME 'Rivers'
  205. EXPRESSION 'Stream'
  206. STYLE
  207. COLOR
  208. END
  209. END # CLASS
  210. CLASS
  211. NAME 'Wetlands'
  212. EXPRESSION 'Swamp or Marsh'
  213. STYLE
  214. COLOR
  215. OUTLINECOLOR
  216. SYMBOL 'circle'
  217. SIZE
  218. END
  219. END # CLASS
  220. END # LAYER
  221.  
  222. LAYER # ROADS LAYER
  223. NAME cty_roads
  224. GROUP roads
  225. TYPE LINE
  226. STATUS OFF
  227. DATA roads_ugl
  228. MAXSCALE
  229.  
  230. PROJECTION
  231. "init=epsg:4326"
  232. END
  233.  
  234. CLASSITEM 'CLASS1'
  235. CLASS
  236. NAME 'Minor Arterial Roads'
  237. EXPRESSION ''
  238. STYLE
  239. COLOR
  240. END
  241. END # CLASS
  242. CLASS
  243. EXPRESSION ''
  244. STYLE
  245. COLOR
  246. END
  247. END # CLASS
  248. END # ROADS LAYER
  249.  
  250. LAYER # state highways begin here
  251. NAME state_hwy
  252. GROUP roads
  253. MAXSCALE
  254. STATUS OFF
  255. DATA roads_ugl
  256. TYPE LINE
  257. FILTERITEM 'CLASS1'
  258. FILTER ''
  259.  
  260. CLASS
  261. NAME 'Principal Arterial Roads'
  262. STYLE
  263. COLOR
  264. SIZE
  265. SYMBOL 'circle'
  266. END
  267. END
  268.  
  269. PROJECTION
  270. "init=epsg:4326"
  271. END
  272. END # highways
  273.  
  274. LAYER # interstate highways begin here
  275. NAME interstate
  276. GROUP roads
  277. # MAXSCALE
  278. STATUS OFF
  279. DATA roads_ugl
  280. TYPE LINE
  281. FILTERITEM 'CLASS1'
  282. FILTER ''
  283.  
  284. CLASS
  285. NAME "Interstate Hwy."
  286. STYLE
  287. COLOR
  288. END
  289. END
  290.  
  291. PROJECTION
  292. "init=epsg:4326"
  293. END
  294. END # highways
  295.  
  296. LAYER # States line layer begins here
  297. NAME states
  298. DATA states_ugl
  299. STATUS OFF
  300. TYPE LINE
  301.  
  302. PROJECTION
  303. "init=epsg:4326"
  304. END
  305.  
  306. CLASSITEM "CLASS"
  307. CLASS
  308. NAME 'State Boundary'
  309. EXPRESSION 'land'
  310. STYLE
  311. SYMBOL 'line5'
  312. COLOR
  313. SIZE
  314. END
  315. END
  316. END # States line layer ends here
  317.  
  318. LAYER
  319. NAME roads_anno
  320. GROUP roads
  321. MAXSCALE
  322. STATUS OFF
  323. DATA roads_ugl
  324. TYPE POLYGON
  325. LABELITEM "SIGN"
  326. CLASSITEM "CLASS1"
  327. CLASS
  328. EXPRESSION ""
  329. STYLE
  330. COLOR # dummy color
  331. SYMBOL '../symbols/sthwy.png'
  332. END
  333. LABEL
  334. MINFEATURESIZE
  335. MINDISTANCE
  336. POSITION CC
  337. SIZE TINY
  338. COLOR
  339. END
  340. END
  341. CLASS
  342. EXPRESSION ""
  343. STYLE
  344. COLOR # dummy color
  345. SYMBOL '../symbols/ushwy.png'
  346. END
  347. LABEL
  348. MINFEATURESIZE
  349. MINDISTANCE
  350. POSITION CC
  351. SIZE TINY
  352. COLOR
  353. END
  354. END
  355.  
  356. PROJECTION
  357. "init=epsg:4326"
  358. END
  359. END # highway annotation
  360.  
  361. LAYER
  362. NAME roads_anno1
  363. GROUP roads
  364. STATUS OFF
  365. DATA roads_ugl
  366. TYPE POLYGON
  367. LABELITEM "SIGN"
  368. CLASSITEM "CLASS1"
  369. CLASS
  370. EXPRESSION ""
  371. STYLE
  372. COLOR # dummy color
  373. SYMBOL '../symbols/interstate.png'
  374. END
  375. LABEL
  376. MINFEATURESIZE
  377. MINDISTANCE
  378. POSITION CC
  379. SIZE TINY
  380. COLOR
  381. END
  382. END
  383.  
  384. PROJECTION
  385. "init=epsg:4326"
  386. END
  387. END
  388.  
  389. LAYER # States label layer begins here
  390. NAME states
  391. DATA states_ugl
  392. STATUS OFF
  393. TYPE POLYGON
  394.  
  395. PROJECTION
  396. "init=epsg:4326"
  397. END
  398.  
  399. CLASSITEM "CLASS"
  400. LABELITEM "STATE"
  401. CLASS
  402. EXPRESSION 'land'
  403. STYLE
  404. COLOR - - -
  405. END
  406. LABEL
  407. COLOR
  408. OUTLINECOLOR
  409. SHADOWCOLOR
  410. SHADOWSIZE
  411. TYPE TRUETYPE
  412. FONT arial-bold
  413. SIZE
  414. ANTIALIAS TRUE
  415. POSITION CL
  416. PARTIALS FALSE
  417. MINDISTANCE
  418. BUFFER
  419. END # end of label
  420. END # end of class
  421. END # States label layer ends here
  422. # End of LAYER DEFINITIONS -------------------------------
  423.  
  424. END # end of map file

如果用户要浏览地图,则应提供参考地图。
示例2.4-添加参考图

HTML Template:

  1. <!-- MapServer Template -->
  2. <html>
  3. <head>
  4. <title>MapServer .x Tutorial</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <link type="text/css" rel="stylesheet" href="/tutorial/ms35.css" />
  7. </head>
  8.  
  9. <body bgcolor="#FFFFFF" text="#000000">
  10. <table align="center" border=""><tr>
  11. <td> <h3 align="center">Example 2.4: Adding a Reference Map</h3>
  12.  
  13. <!-- START OF MAPSERVER FORM -->
  14. <form name="mapserv" method="GET" action="/cgi-bin/mapserv.exe">
  15.  
  16. <!-- HIDDEN MAPSERVER CGI VARIABLES -->
  17. <input type="hidden" name="map" value="[map]">
  18. <input type="hidden" name="imgext" value="[mapext]">
  19. <input type="hidden" name="imgxy" value="199.5 149.5">
  20. <table width="" border="" align="center">
  21. <tr>
  22. <td>
  23. <table width="" border="" align="center">
  24. <tr>
  25. <td colspan="">Select Layers:
  26. <!-- SPECIFY VECTOR LAYERS -->
  27. <input type="checkbox" name="layer" value="states"
  28. [states_check] checked>State Boundaries&nbsp;
  29. <input type="checkbox" name="layer" value="hydro"
  30. [hydro_check]>Water Features&nbsp;
  31. <input type="checkbox" name="layer" value="roads"
  32. [roads_check]>Roads<br>
  33.  
  34. <!-- SPECIFY RASTER LAYERS -->
  35. Select Background:
  36. <select name="layer">
  37. <option value=" " [ _select]>No Background</option>
  38. <option value="modis_jpl" [modis_jpl_select]>
  39. Daily MODIS Image</option>
  40. <option value="modis" [modis_select]>
  41. MODIS Surface Reflectance</option>
  42. </select>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td>
  47.  
  48. <!-- SPECIFY MAP MODE -->
  49. <div align="center">Map Mode:<br>
  50. <select name="mode">
  51. <option value="browse" [browse_select]>Browse</option>
  52. </select>
  53. </div>
  54. </td>
  55. <td>
  56. <!-- FORM SUBMIT BUTTON -->
  57. <div align="center">
  58. <input type="submit" name="submit" value="Refresh">
  59. </div>
  60. </td>
  61. <td>
  62. <!-- ZOOM/PAN CONTROLS -->
  63. <div align="center">Map Control: <br>
  64. <select name="zoom">
  65. <option value="" [zoom_4_select]>Zoom In 4x</option>
  66. <option value="" [zoom_3_select]>Zoom In 3x</option>
  67. <option value="" [zoom_2_select]>Zoom In 2x</option>
  68. <option value="" [zoom_1_select]>Recenter</option>
  69. <option value="-2" [zoom_-2_select]>Zoom Out 2x</option>
  70. <option value="-3" [zoom_-3_select]>Zoom Out 3x</option>
  71. <option value="-4" [zoom_-4_select]>Zoom Out 4x</option>
  72. </select>
  73. </div>
  74. </td>
  75. <!-- REFERENCE COLUMN -->
  76. <td rowspan="" valign="top">
  77. <p>Reference:<br>
  78. <input type="image" name="ref" src="[ref]" border=""></p>
  79. </td>
  80. </tr>
  81. <tr>
  82. <!-- DISPLAY THE MAPSERVER-CREATED MAP IMAGE -->
  83. <td colspan="" align="center" valign="top">
  84. <input type="image" name="img" src="[img]" width=""
  85. height="" border="">
  86. </td>
  87. </tr>
  88. </table>
  89. </td>
  90. </tr>
  91. </table>
  92. </form>
  93. </body>
  94. </html>

这段代码中有趣的部分是标签,即[缩放\选择]。当mapserv看到这样的标记时,它将评估是否选择了值(“1”)。如果选中,则MapServ会将此选项标记为“已选中”。再次,转到示例2.1并“查看”代码。“recenter”选项应该是“selected”(这样当我们再次提交表单时,“zoom”的值将是“1”)。

最后一个标签是“[img]”标签。正如您将注意到的,它是表单输入对象的一部分。“[img]”将替换为mapserv生成的映像的完整路径和名称。

一旦mapserver替换了所有标记,它将向浏览器发送一个合适的HTML表单。用户将再次能够进行更改。

像任何好的地图一样,它应该包括一个传说。
示例2.5-添加图例

这里是HTML模板源代码:

  1. <!-- MapServer Template -->
  2. <html>
  3. <head>
  4. <title>MapServer .x Tutorial</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <link type="text/css" rel="stylesheet" href="/tutorial/ms35.css" />
  7. </head>
  8.  
  9. <body bgcolor="#FFFFFF" text="#000000">
  10. <table align="center" border=""><tr>
  11. <td> <h3 align="center">Example 2.5: Adding a Legend</h3>
  12.  
  13. <!-- START OF MAPSERVER FORM -->
  14. <form name="mapserv" method="GET" action="/cgi-bin/mapserv.exe">
  15.  
  16. <!-- HIDDEN MAPSERVER CGI VARIABLES -->
  17. <input type="hidden" name="map" value="[map]">
  18. <input type="hidden" name="imgext" value="[mapext]">
  19. <input type="hidden" name="imgxy" value="199.5 149.5">
  20. <table width="" border="" align="center">
  21. <tr>
  22. <td>
  23. <table width="" border="" align="center">
  24. <tr>
  25. <td colspan="">Select Layers:
  26. <!-- SPECIFY VECTOR LAYERS -->
  27. <input type="checkbox" name="layer" value="states"
  28. [states_check] checked>
  29. State Boundaries&nbsp;
  30. <input type="checkbox" name="layer" value="hydro"
  31. [hydro_check]>
  32. Water Features&nbsp;
  33. <input type="checkbox" name="layer" value="roads"
  34. [roads_check]>
  35. Roads<br>
  36.  
  37. <!-- SPECIFY RASTER LAYERS -->
  38. Select Background:
  39. <select name="layer">
  40. <option value=" " [ _select]>No Background</option>
  41. <option value="modis_jpl" [modis_jpl_select]>
  42. Daily MODIS Image</option>
  43. <option value="modis" [modis_select]>
  44. MODIS Surface Reflectance</option>
  45. </select>
  46. </td>
  47. </tr>
  48. <tr>
  49. <td>
  50.  
  51. <!-- SPECIFY MAP MODE -->
  52. <div align="center">Map Mode:<br>
  53. <select name="mode">
  54. <option value="browse" [browse_select]>Browse</option>
  55. </select>
  56. </div>
  57. </td>
  58. <td>
  59. <!-- FORM SUBMIT BUTTON -->
  60. <div align="center">
  61. <input type="submit" name="submit" value="Refresh">
  62. </div>
  63. </td>
  64. <td>
  65. <!-- ZOOM/PAN CONTROLS -->
  66. <div align="center">Map Control: <br>
  67. <select name="zoom">
  68. <option value="" [zoom_4_select]>Zoom In 4x</option>
  69. <option value="" [zoom_3_select]>Zoom In 3x</option>
  70. <option value="" [zoom_2_select]>Zoom In 2x</option>
  71. <option value="" [zoom_1_select]>Recenter</option>
  72. <option value="-2" [zoom_-2_select]>Zoom Out 2x</option>
  73. <option value="-3" [zoom_-3_select]>Zoom Out 3x</option>
  74. <option value="-4" [zoom_-4_select]>Zoom Out 4x</option>
  75. </select>
  76. </div>
  77. </td>
  78. <!-- REFERENCE AND LEGEND COLUMN -->
  79. <td rowspan="" valign="top">
  80. <p>Reference:<br>
  81. <img name="ref" src="[ref]"></p>
  82. <p>Legend:<br>
  83. <img name="legend" src="[legend]"></p>
  84. </td>
  85. </tr>
  86. <tr>
  87. <!-- DISPLAY THE MAPSERVER-CREATED MAP IMAGE -->
  88. <td colspan="" align="center" valign="top">
  89. <input type="image" name="img" src="[img]" width=""
  90. height="" border="">
  91. </td>
  92. </tr>
  93. </table>
  94. </td>
  95. </tr>
  96. </table>
  97. </form>
  98. </body>
  99. </html>

这段代码中有趣的部分是标签,即[缩放\选择]。当mapserv看到这样的标记时,它将评估是否选择了值(“1”)。如果选中,则MapServ会将此选项标记为“已选中”。再次,转到示例2.1并“查看”代码。“recenter”选项应该是“selected”(这样当我们再次提交表单时,“zoom”的值将是“1”)。
最后一个标签是“[img]”标签。正如您将注意到的,它是表单输入对象的一部分。“[img]”将替换为mapserv生成的映像的完整路径和名称。
一旦mapserver替换了所有标记,它将向浏览器发送一个合适的HTML表单。用户将再次能够进行更改。

MapServer教程2的更多相关文章

  1. MapServer教程

    https://mapserver.org/ MapServer是一个开放源代码平台,用于将空间数据和交互式地图应用程序发布到Web.由OSGEO批准的MapServer项目指导委员会(PSC)负责管 ...

  2. MapServer教程3

    Compiling on Unix Compiling on Win32 PHP MapScript Installation .NET MapScript Compilation IIS Setup ...

  3. 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( ...

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 用Python处理字幕文件

    始 下了部老电影,找到了相关的中英文字幕,奇怪的是,英文字幕能正常现实,中文字幕却不可以,我一度以为是Linux下播放器编码的问题,但是怎么更改设置都无效,而我以前在看其他电影时,中文字幕是正常的.所 ...

  2. git的忽略文件语法规范

    忽略文件语法规范 空行或是以 # 开头的行即注释行将被忽略. 可以在前面添加正斜杠 / 忽略当前路径文件,但不包括子目录的同名文件. 可以在后面添加正斜杠 / 来忽略文件夹. 可以使用 ! 来否定忽略 ...

  3. 在layui中,新的页面怎么获取另一个页面传过来的数据,并可以对数据进行判断,layui中的后台分页(table)。

    例如:打开一个新页面的同时,传数据. layer.open({ type: 2, title: '新增项目', shadeClose: false, shade: [0.3], maxmin: tru ...

  4. lambda表达式(2)

    转:http://www.cnblogs.com/kingmoon/archive/2011/05/03/2035696.html "Lambda表达式"是一个匿名函数,是一种高效 ...

  5. windows 使用nginx

    windows 安装nginx 进入此地址进行下载 http://nginx.org/en/download.html 解压到相关目录 启动 start nginx 关闭 nginx -s stop ...

  6. WOJ#3882 旅行问题(POI2004)

    描述 John打算驾驶一辆汽车周游一个环形公路.公路上总共有n车站,每站都有若干升汽油(有的站可能油量为零),每升油可以让汽车行驶一千米.John必须从某个车站出发,一直按顺时针(或逆时针)方向走遍所 ...

  7. 「Vue.js」Vue-Router + Webpack 路由懒加载实现

    一.前言 当打包构建应用时,Javascript 包会变得非常大,影响页面加载.如果我们能把不同路由对应的组件分割成不同的代码块,然后当路由被访问的时候才加载对应组件,这样就更加高效了.结合 Vue ...

  8. #10017 传送带(SCOI 2010)(三分套三分)

    [题目描述] 在一个 2 维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段 AB 和线段 CD.lxhgww 在 AB上的移动速度为 P ,在 CD 上的移动速度为 Q,在平 ...

  9. SCUT - 142 - 第n个素数

    https://scut.online/p/142 但是洲阁筛打表还是超时了,打的表不够长吧,在51nod上面要跑5s.要是快10倍得要密1000倍,根本打不出来(时间意义). 暴力check要找的质 ...

  10. 5105 pa3 Distributed File System based on Quorum Protocol

    1 Design document 1.1 System overview We implemented a distributed file system using a quorum based ...