This map is clearly a region from the one shown earlier, but it doesn't look the same. This map uses another map projection.
In the projection definition part of the Mapfile, the projection is processed by the Proj.4 library through parameters. For more information about the PROJ.4 library, visit https://proj4.org/ .
The following is the Mapfile source file mfa6.map
used in this example:
01 MAP
02 IMAGETYPE "PNG24"
03 EXTENT -20042150 -7515806 20104978 7515807
04 SIZE 350 260
05 SHAPEPATH "/gdata"
06 SYMBOLSET "../symbols/symbols35.sym"
07 FONTSET "../fonts/fonts.list"
08 PROJECTION
09 "init=epsg:3857"
10 END
11 LAYER
12 NAME "topo"
13 DATA "land_shallow_topo_8192.tif"
14 STATUS OFF
15 TYPE RASTER
16 PROJECTION
17 "init=epsg:4326"
18 END
19 END
20 END
The changes in the documents are as follows:
2 | IMAGETYPE "PNG24" | 2 | IMAGETYPE "PNG24" | ||
n | 3 | EXTENT -180 -90 180 90 | n | 3 | EXTENT -20042150 -7515806 20104978 7515807 |
4 | SIZE 600 300 | 4 | SIZE 350 260 | ||
5 | SHAPEPATH "/gdata" | 5 | SHAPEPATH "/gdata" | ||
n | 6 | IMAGECOLOR 255 255 255 | n | 6 | SYMBOLSET "../symbols/symbols35.sym" |
7 | FONTSET "../fonts/fonts.list" | 7 | FONTSET "../fonts/fonts.list" | ||
n | 8 | SYMBOLSET "../symbols/symbols35.sym" | n | 8 | PROJECTION |
9 | "init=epsg:3857" | ||||
10 | END | ||||
9 | LAYER | 11 | LAYER | ||
13 | TYPE RASTER | 15 | TYPE RASTER | ||
t | 14 | PROCESSING "BANDS=1,2,3" | t | 16 | PROJECTION |
15 | OFFSITE 71 74 65 | 17 | "init=epsg:4326" | ||
16 | END | ||||
17 | LAYER | ||||
18 | NAME "states_line" | ||||
19 | DATA "wcountry.shp" | ||||
20 | STATUS OFF | ||||
21 | TYPE LINE | ||||
22 | CLASS | ||||
23 | NAME "State Boundary" | ||||
24 | STYLE | ||||
25 | SYMBOL "line5" | ||||
26 | COLOR 255 255 0 | ||||
27 | SIZE 1 | ||||
28 | END | ||||
29 | END | 18 | END |
The first thing you will notice is that the MapFile is the original EXTENT
replaced by the new range value, which doesn't look like longitude and latitude. In addition, a projection object PROJECTION
was added, and a PROJECTION
definition was added to LAYER
.
Take a look at the parameters of the new spatial extent:
EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514
Projection can be defined in MAP objects, as well as in LAYER objects. Projections can be defined in MAP objects (only once, but multiple can be defined) This defined projection is the output projection of the map, and MapServer will use this projection to render the map result. The projection defined in the LAYER
object is the input projection, that is, the projection of the data corresponding to the layer object. The definition of the projection in the layer object can be different from that in the map object, and MapServer will do the projection transformation and reproject to the output projection. If there is no projection information in the LAYER
object, MapServer will assume that the input and output projections are the same.
In a Mapfile, the PROJECTION
object is not required. But if you want to support the OGC interoperability specification (WMS/WFS/WCS), it still needs to be clearly defined in the Mapfile.
Defined only once in the map object, this definition becomes your output projection - MapServer will render your map in this projection. You can also define input projections using projection object layer objects. It is possible to project on different layers - MapServer reprojects them to your output projection. If no objects within the projection layer are defined, MapServer assumes that the input projection is the same as the output projection. This is not the desired object unless you create a map file that supports an OGC Interoperable Web Services Specification (WMS/WFS/WCS).
MapServer's projections are defined in two ways. The traditional way is to define it through the Proj.4 parameter, such as the Lambert Azimuthal Equal-Area projection of the continental United States defined below.
This is the output projection definition:
PROJECTION
"proj=laea"
"ellps=clrk66"
"lat_0=45"
"lon_0=-100"
END
Another way is to use EPSG codes. These codes are standard projection codes (or spatial reference identifiers) as defined by the European Petroleum Survey Group (EPSG).
Defined by the following EPSG code in MapServer, the following EPSG:2163
also means (Lambert Azimuthal Equal-Area), the effect is the same:
PROJECTION
"init=epsg:2163"
END
If you want to learn more about EPSG code, take a look at /usr/ROJ/PSG
or C:/PROJ/NAD/EPSG
(/ms4w/proj/nad
MS4W). Also, check out the EPSG website http://www.epsg.org .
The projected coordinates can be calculated using QGIS or some other GIS package, or you can use PROJ.4's cs2cs tool. The following commands are raw range values that can be used to reproject:
cs2cs +proj=latlong +datum=WGS84 +to +proj=laea +ellps=clrk66 +lat_0=45 +lon_0=-100
After typing the command, enter the southwest coordinate pair (lower left coordinate), separated by a space: -97.54 1.619778
The result returned by the cs2cs
utility is:
208398.01 -372335.44 0.000
Next, type the northeast coordinate pair (upper-right coordinate), also separated by a space: -82.122902 49.38562
, returns the following values:
1285308.08 632638.93 0.000
cs2cs
returns a ternary value. The third value, 0.000, can be ignored and is meant to represent altitude (which we don't use).
Now, the extent of the map under this projection can be defined in the Mapfile:
EXTENT 208398.01 -372335.44 1285308.08 632638.93
Note that the definition here is not the same as what is actually used in Mapfile. When re-projecting, the map defined using the range of the data may not be what you expected. By considering "buffering" the range, the range can be extended a few kilometers up and down, left and right (this varies according to the projection and the specific application). How much expansion is needed can be assisted by desktop GIS software such as QGIS, which may be more convenient.
If you need to know more about map projection, take a look at some of the links below: