# Define projection and range

## View example

The map shown in front of this map is obviously an area, but it doesn't look the same. This map uses another map projection.

In projection definition part of Mapfile, projection is processed by the parameters through the Proj.4 library. For more information about the PROJ.4 library, visit https://proj4.org/. .

The following is the Mapfile source file `xmfa6.map`

used in this example:

01 MAP 02 IMAGETYPE "PNG24" 03 EXTENT -20042150 -20000000 20104978 20000000 04 SIZE 400 400 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 "states" 13 DATA "wcountry.shp" 14 STATUS OFF 15 TYPE POLYGON 16 PROJECTION 17 "init=epsg:4326" 18 END 19 CLASS 20 NAME "States" 21 EXPRESSION "land" 22 STYLE 23 COLOR 232 232 232 24 END 25 END 26 END 27 LAYER 28 NAME "modis" 29 DATA "land_shallow_topo_8192.tif" 30 STATUS OFF 31 TYPE RASTER 32 PROCESSING "BANDS=1,2,3" 33 PROJECTION 34 "init=epsg:4326" 35 END 36 END 37 LAYER 38 NAME "states" 39 DATA "wcountry.shp" 40 STATUS OFF 41 TYPE LINE 42 PROJECTION 43 "init=epsg:4326" 44 END 45 CLASS 46 NAME "State Boundary" 47 STYLE 48 SYMBOL "line5" 49 COLOR 255 255 0 50 SIZE 1 51 END 52 END 53 END 54 END

The file changes are as follows:

2 | IMAGETYPE "PNG24" | 2 | IMAGETYPE "PNG24" | ||

n | 3 | EXTENT -180 -90 180 90 | n | 3 | EXTENT -20042150 -20000000 20104978 20000000 |

4 | SIZE 600 300 | 4 | SIZE 400 400 | ||

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 | ||||

11 | LAYER | ||||

12 | NAME "states" | ||||

13 | DATA "wcountry.shp" | ||||

14 | STATUS OFF | ||||

15 | TYPE POLYGON | ||||

16 | PROJECTION | ||||

17 | "init=epsg:4326" | ||||

18 | END | ||||

19 | CLASS | ||||

20 | NAME "States" | ||||

21 | EXPRESSION "land" | ||||

22 | STYLE | ||||

23 | COLOR 232 232 232 | ||||

24 | END | ||||

25 | END | ||||

26 | END | ||||

9 | LAYER | 27 | LAYER | ||

14 | PROCESSING "BANDS=1,2,3" | 32 | PROCESSING "BANDS=1,2,3" | ||

n | 15 | OFFSITE 71 74 65 | n | 33 | PROJECTION |

34 | "init=epsg:4326" | ||||

35 | END | ||||

16 | END | 36 | END | ||

17 | LAYER | 37 | LAYER | ||

n | 18 | NAME "states_line" | n | 38 | NAME "states" |

19 | DATA "wcountry.shp" | 39 | DATA "wcountry.shp" | ||

21 | TYPE LINE | 41 | TYPE LINE | ||

t | t | 42 | PROJECTION | ||

43 | "init=epsg:4326" | ||||

44 | END | ||||

22 | CLASS | 45 | CLASS |

First notice that MapFile is the original `EXTENT`

is replaced with a new range value, which does not look like longitude or latitude.
In addition, a projection object `PROJECTION`

has been added, and the `PROJECTION`

definition has been added to `LAYER`

.

Take a look at the parameters of the new spatial range:

EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514

## Writing in Mapfile

You can define a projection in a MAP object, as well as in a LAYER object. A projection can be defined in a MAP object (defined only once, but multiple can be defined), and the projection of this definition is the output projection of the map, through which MapServer will render the map results. The projection defined in the LAYER object is an input projection, that is, a projection of the data corresponding to the Layer object. The definition of a projection in a Layer object can be different from that in a Map object, and the MapServer will be projected and re-projected into the output projection. If there is no projection information in the LAYER object, MapServer assumes that the input projection is consistent with the output projection.

In Mapfile, PROJECTION objects are not required. However, if you want to support the OGC Interoperability Specification (WMS/WFS/WCS), you still need to define it clearly in 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 use projection object layer objects to define input projections. You can project them in different layers, MapServer will reproject them to your output projection. If no objects within the projection layer are defined, MapServer assumes 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 service specification (WMS/WFS/WCS).

The projection of MapServer defines two ways. The traditional approach is defined by the Proj.4 parameter, such as the Lambert Azimuthal Equal-Area projection 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 the EPSG code. These codes are standard projection codes (or spatial reference identifiers) defined by the European Petroleum Research Organization (EPSG).
In the MapServer, the following EPSG code definition, the following `EPSG:2163`

also means (Lambert Azimuthal Equal-Area), the effect is the same:

PROJECTION "init=epsg:2163" END

If you want to know more about the EPSG code, check out `/usr/ROJ/PSG`

or `C:/PROJ/NAD/EPSG`

(`/ms4w/proj/nad`

MS4W).
In addition, check out the EPSG website
Http://www.epsg.org
.

## Calculating projected coordinates with cs2cs

You can use QGIS or some other GIS software package to calculate the projected coordinates, or you can use the cs2cs tool of PROJ.4. The following commands are the original 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 coordinates), 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 (the upper right corner coordinate), also separated by a space: ``-82.122902 49.38562`

, return the following values:

1285308.08 632638.93 0.000

`cs2cs`

returns the ternary value. The third value of 0.000 can be ignored, which means that the altitude is high (we don't use it).

Now you can define the extent of the map under this projection in the Mapfile:

EXTENT 208398.01 -372335.44 1285308.08 632638.93

Note that the definition here is different from what is actually used in the Mapfile. When reprojecting, the map results defined using the range of data may not be as expected. By considering the range of "buffering", the range is extended several kilometers above and below (depending on the projection and the specific application). How much extra expansion is needed can be assisted by desktop GIS software such as QGIS, which may be more convenient.

## Map Projection Online Document

If you need more information about map projection, check out some of the links below: