MapServer6.4.1教程学习--定义投影和范围(1-6)

示例1.6定义投影和范围

(http://www.mapserver.org/tutorial/example1-6.html#example1-6)


哇哦,发生什么了?

你刚体验了重投影。当你在mapfile文件中定义了PROJECTION对象,MapServer会把图层和投影信息传给Proj.4库做投影。要了解更多关于Proj.4库的信息,请访问:http://proj.maptools.org/.

这个例子试图向你展示MapServer中关于投影方面支持的亮点。

下面是示例1.6mapfile

#The annotated map file (sort of)

#Created by Pericles S. Nacionales for the MapServer tutorial

#20050408

#

#MapServer map file uses the pound sign (#) to denote the start of a line

#comment--each line that needs to be commented has to be prepended with a"#".

#

#Map files begin with MAP keyword to signify the start of the map object.

#Well, the entire map file is THE map object. Enclosed between MAP and END

#at the very bottom of this map file, are keyword/value pairs and other

#objects.

MAP

  #IMAGETYPE      PNG24

  IMAGETYPE     PNG

  # EXTENT 199949.651166 -371954.7720841472121.6862 632767.19157

  EXTENT      201621.496941 -294488.2853331425518.020722 498254.511514 # LAEA

          #EXTENT         -97.5 41.619778 -82.122902 49.38562 #Geographic

  SIZE          400 300

  SHAPEPATH     "../data"

  SYMBOLSET     "../symbols/symbols35.sym"

  FONTSET       "../fonts/fonts.list"

 

  # The projection object is typically usedwithin the map and the layer

  # objects. You only define it once within themap object and this definition

  # becomes your output projection--MapServerwill render your maps in this

  # projection. You also use the projection object within the layer object to

  # define your input projection.  Your layers can be in different

  # projections--MapServer will reproject theminto your output projection.

  # If no projection is defined within thelayer object, MapServer assumes

  # your input projection is the same as youroutput projection.  This is not

  # a required object unless you're creating amap file that supports one of

  # the OGC interoperability web servicesspecifications (WMS/WFS/WCS).

  #

  # This is the output PROJECTION definition------

  PROJECTION

    # Projection parameters can be defined intwo ways...

    # This is the traditional Proj.4 definitionof Lambert Azimuthal Equal-Area

    # projection for the Continental U.S.

      "proj=laea"

      "ellps=clrk66"

      "lat_0=45"

      "lon_0=-100"

 

    # Alternatively, you can specify an EPSGcode.

    # This is the EPSG code for LambertAzimuthal Equal-Area

    # projection for the U.S.

    #

    # "init=epsg:2163"

  END # End of the output Projection definition---

 

  # Layer objects are defined beneath the mapobject.  You need at least one

  # layer defined in your map file before youcan display a map...  You can

  # define as many layers as you'd likealthough a limit is typically hard-coded

  # in map.h in the MapServer source.  The default limit is set at 100.  You'd

  # have to have a very specialized applicationto need more than 100 layers in

  # your application.

  #

  # Start of LAYER DEFINITIONS---------------------------------------------

  LAYER # States polygon layer begins here

    NAME        states

    DATA        states_ugl

    STATUS      OFF

    TYPE        POLYGON

 

    # Here's an example of the input projectiondefinition.

    # EPSG:4326 is code for geographic(latlong) projection

    # using the WGS84 datum.

    #

    # PROJECTION objects within the LAYERobject define the input

    # projection--this is the native projectionof your data.

    PROJECTION

      "init=epsg:4326"

    END

 

    # CLASSITEM defines the non-spatialattribute that you will be using to

    # separate a layer into classes.  This attribute will be in the DBF file

    # of your shapefile (it will be differentfor each data format).  In this

    # example the shapefile states_ugl has anassociated database

    # (states_ugl.dbf) that contains anattribute called "CLASS".  Youwill be

    # using two values in the CLASS attributeto separate the classes (also

    # called themes) used in this layer--landand water.  CLASSITEM is used in

    # association with the EXPRESSION parameterin the CLASS object.  See below.

    CLASSITEM   "CLASS"

 

    # The class object is defined within thelayer object.  You can define as

    # many classes as you need (well, there arelimits as with layers, but it's

    # senseless to define more than ten on a"normal" layer.  There are

    # situations, however, where you might haveto do it.)

    CLASS

      NAME 'States'

      EXPRESSION 'land'

 

      # There are styles in a class, just likethere are classes in a layer,

      # just like there are layers in amap.  You can define multiple styles in

      # a class just as you can define multipleclasses in a layer and multiple

      # layers in a map.

      STYLE

        COLOR      232 232 232

      END

    END

  END # States polygon layer ends here

 

  # In addition to vector data (shapefiles arevector data), MapServer supports

  # a host of raster formats.  In GIS world, one of the most common raster

  # formats is GeoTIFF, a TIFF image withgeospatial headers.  MapServer also

  # supports JPEG, PNG, GIF, and other commonformats.  Other raster formats

  # supported by MapServer include ESRIArc/Info grid, HDF and HDF-EOS, NetCDF,

  # Generic raster binaries, OGC Web MapService (WMS) layers, etc.  Pretty much

  # any raster format you can think of isprobably supported, thanks to the

  # impressive Geospatial Data AbstractionLibrary (GDAL, pronounced "GOODALL"

  # or GOODLE?).  More information on GDAL is available athttp://www.gdal.org.

  #

  # MapServer 4.x can read and displaybitmapped (like GIFs), RGB/A (true

  # color), and multispectral (images with morethan 3 bands, like raw LandSat

  # images) rasters.

  LAYER # MODIS raster layer begins here

    NAME        modis

    DATA        "raster/mod09a12003161_ugl_ll_8bit.tif"

    STATUS      OFF

    TYPE        RASTER

    PROCESSING  "BANDS=1,2,3"

    OFFSITE     71 74 65

 

    PROJECTION

      "init=epsg:4326"

    END

  END # MODIS raster layer ends here

 

  LAYER # States line layer begins here

    NAME        states

    DATA        states_ugl

    STATUS      OFF

    TYPE        LINE

 

    PROJECTION

      "init=epsg:4326"

    END

 

    CLASSITEM   "CLASS"

    CLASS

      NAME      'State Boundary'

      EXPRESSION 'land'

      STYLE

        SYMBOL    'line5'

        COLOR      64 64 64

        SIZE       1

      END

    END

  END # States line layer ends here

 

  LAYER # States label layer begins here

    NAME        states_label

    DATA        states_ugl

    STATUS      OFF

    TYPE        ANNOTATION

 

    PROJECTION

      "init=epsg:4326"

    END

 

    CLASSITEM   "CLASS"

 

    # Just like CLASSITEM, LABELITEM definesthe database attribute that you

    # will be using to draw labels.  In this case, the values of the attribute

    # "STATE" will be used to labelthe states polygons.

    LABELITEM   "STATE"

    CLASS

      EXPRESSION 'land'

      STYLE

        COLOR      -1 -1 -1

      END

 

      # There can be labels in a class, justlike there are classes in a layer,

      # just like there are layers in amap.  You can define multiple labels in

      # a class just as you can define multipleclasses in a layer and multiple

      # layers in a map.

      # MapServer has a very flexible labelingsystem.  With that flexibility

      # comes complexity, specially when usingtruetype fonts.  Please read

      # through the LABEL section of theMapServer map file documentation at

      # http://www.mapserver.org/mapfile formore information.

      LABEL

        COLOR 132 31 31

        SHADOWCOLOR 218 218 218

        SHADOWSIZE 2 2

        TYPE TRUETYPE

        FONT arial-bold

        SIZE 12

        ANTIALIAS TRUE

        POSITION CL

        PARTIALS FALSE

        MINDISTANCE 300

        BUFFER 4

      END # end of label

    END # end of class

  END # States label layer ends here

  # End of LAYER DEFINITIONS-------------------------------

 

END# All map files must come to an end just as all other things must come to..

 

首先你会注意到mapfile文件原先的EXTENT被注释掉了,新的EXTENT值看起来不像是经纬度值。另外,我们在每个图层内的靠近开始位置处添加了PROJECTION对象。

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

EXTENT  201621.496941 -294488.285333 1425518.020722498254.511514

我们提供给MapServer的范围参数必须和输出投影保持一致。既然Lambert Azimuthal Equal-Area投影是以米为单位,那么新的范围也以米为单位。你可以通过ArcView或其他GIS包来计算新的范围,你也可以用Proj.4工具来计算。下述命令可用来重新投影原来的范围。

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

当你敲完这条命令,以中间空格方式输入西南角坐标对(左下角坐标)后,

-97.541.619778

“CS2CS”工具会给出如下值:

208398.01       -372335.44 0.000

然后再以中间空间方式输入东北方向坐标对(右上角度坐标):

-82.12290249.38562

然后会返回如下值:

1285308.08      632638.93 0.000

你将会注意到”cs2cs”返回了三个值的集合,你可以忽略第三个0.000的值,这个值代表高程(这里我们不使用)。好了,现在我们可以将EXTENT设置为:

EXTENT208398.01 -372335.44 1285308.08 632638.93

但是你会说这和上面的范围不匹配。好吧,这是在重投影时候经常遇到的—地图中心并不是和你想像的一样。通过在左方向加几千米和右边加一些距离,你可以回避这个问题。或者你可以用图形GIS包来得到这个范围。这里有用ArcView获取EXTENT的指南。

MapServer有两种投影定义方式。第一种就是mapfile中的输出PROJECTION对象(第一个PROJECTION块)。这是给Proj.4库传递参数的传统方式。另一种就是使用EPSG代码。这些代码是欧洲石油测绘组(European Petroleum Survey Group, EPSG)定义的标准投影标识(或空间参考标识)。此例中的Lambert Azimuthal Equal-Area对应的代码是2163。如果你注释掉PROJECTION后面的四行,然后放开”init=epsg:2163”,将会传递同样信息给Proj.4库。如果你想了解关于EPSG代码的更多知识,可以看看“/usr/local/share/proj/epsg”或 “C:/proj/nad/epsg” (在 MS4W 位于“/ms4w/proj/nad”)。

此外,也可以看看EPSG官网: http://www.epsg.org.

如果你想更深入了解投影,可以看看下面的链接:

你也可以用”mapprojection”在网络上搜索获得更多信息。

 

PS:中文版权为asswclw所有,请尊重劳动成果,转载将注明出处。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值