How to Set a Projection in MapServer
MapServer defines coordinate reference systems using PROJ.4 parameters inside a PROJECTION block in the mapfile.
Method 1: Using an EPSG Code
The simplest approach is to reference the EPSG code directly:
Mapfile
MAP
PROJECTION
"init=epsg:5255"
END
WEB
METADATA
"wms_srs" "EPSG:5255"
END
END
LAYER
PROJECTION
"init=epsg:5255"
END
...
END
END Method 2: Using PROJ.4 Parameters
If the EPSG code is not recognized, specify the PROJ.4 parameters explicitly:
Mapfile
PROJECTION
"+proj=tmerc"
"+lat_0=0"
"+lon_0=33"
"+k=1"
"+x_0=500000"
"+y_0=0"
"+ellps=GRS80"
"+towgs84=0,0,0,0,0,0,0"
"+units=m"
"+no_defs"
END Search for any EPSG code on the home page and copy the definition from the MapServer tab.
MAP vs LAYER Projections
- MAP PROJECTION: Defines the output projection (the CRS the map is displayed in).
- LAYER PROJECTION: Defines the source data projection.
- MapServer automatically reprojects layers from their native CRS to the MAP projection.
WMS Projections
When serving WMS, declare supported projections in the metadata:
Mapfile
WEB
METADATA
"wms_srs" "EPSG:4326 EPSG:3857 EPSG:5255"
END
END Notes
- Each PROJ.4 parameter must be on its own line and enclosed in double quotes.
- MapServer uses the PROJ library — ensure PROJ is installed on your system.
- EPSG files are typically located in
/usr/share/proj/.