YAML Support¶
YAML support was added in version 1.2.0 of Mappyfile. The YAML format is supported for both loading and dumping Mapfiles. YAML is a human-readable data serialization format that is commonly used for configuration files. It is often preferred over JSON for its readability and support for comments.
Python API Support:
CLI Support:
Python Example¶
import mappyfile
import mappyfile.yaml
d = mappyfile.open("./docs/examples/before.map")
output = mappyfile.dumps(d)
# Save to YAML
mappyfile.yaml.save(d, "output.yaml")
# Load back
d2 = mappyfile.yaml.open("output.yaml")
output2 = mappyfile.dumps(d2)
print(output == output2)
print(output2)
Example YAML¶
The following example shows how to export a Mapfile to YAML format using the command-line interface.
mappyfile yaml-export ./tests/mapfiles/itasca2.map ./docs/examples/itasca.yaml
The Mapfile used in this example is the “classic” MapServer Itasca map (itasca2.map from the tests folder),
and the output YAML file is saved to docs/examples/itasca.yaml and displayed below.
__type__: map
name: ITASCA
status: 'ON'
size:
- 600
- 600
projection:
- init=epsg:26915
extent:
- 388107.634400379
- 5203120.88405952
- 500896.339019834
- 5310243.30613897
units: METERS
shapepath: data
imagecolor:
- 255
- 255
- 255
imagetype: PNG
symbols:
- __type__: symbol
name: circle
type: ELLIPSE
points:
- - 1
- 1
filled: true
- __type__: symbol
name: star
type: VECTOR
filled: true
points:
- - 0
- 0.375
- - 0.35
- 0.375
- - 0.5
- 0
- - 0.65
- 0.375
- - 1
- 0.375
- - 0.75
- 0.625
- - 0.875
- 1
- - 0.5
- 0.75
- - 0.125
- 1
- - 0.25
- 0.625
outputformats:
- __type__: outputformat
name: geojson
driver: OGR/GEOJSON
mimetype: application/json
formatoption:
- FORM=SIMPLE
- STORAGE=memory
- __type__: outputformat
name: png
driver: AGG/PNG
mimetype: image/png
imagemode: RGB
extension: png
formatoption:
- GAMMA=0.75
transparent: 'ON'
web:
__type__: web
header: templates/header.html
template: itasca_basic.html
footer: templates/footer.html
minscaledenom: 1000
maxscaledenom: 1550000
imagepath: /var/www/html/tmp/
imageurl: /tmp/
metadata:
ows_title: MapServer Itasca Demo
ows_abstract: This is a MapServer demo application for Itasca County located in
north central Minnesota.
wms_accessconstraints: none
ows_enable_request: '*'
oga_html_template_directory: /usr/share/mapserver/ogcapi/templates/html-plain/
oga_onlineresource: http://localhost/cgi-bin/mapserv/itasca/ogcapi
ows_onlineresource: http://localhost/cgi-bin/mapserv?map=/usr/local/www/docs_maps/mapserver_demos/itasca/itasca.map&
wfs_srs: EPSG:26915 EPSG:3857 EPSG:4326
wfs_getfeature_formatlist: gml,geojson
wms_srs: EPSG:26915 EPSG:3857
__type__: metadata
reference:
__type__: reference
image: graphics/reference.png
extent:
- 393234.393701263
- 5205405.16440722
- 495769.579718949
- 5307959.02579127
size:
- 120
- 120
status: 'ON'
minboxsize: 5
maxboxsize: 100
color:
- 255
- 0
- 0
outlinecolor:
- 0
- 0
- 0
markersize: 8
marker: star
legend:
__type__: legend
keysize:
- 18
- 12
labels:
- __type__: label
type: BITMAP
size: MEDIUM
color:
- 0
- 0
- 89
status: 'ON'
scalebar:
__type__: scalebar
imagecolor:
- 0
- 0
- 0
labels:
- __type__: label
color:
- 255
- 255
- 255
size: TINY
style: 1
size:
- 100
- 2
color:
- 255
- 255
- 255
units: MILES
intervals: 1
transparent: 'ON'
status: 'ON'
layers:
- __type__: layer
name: drgs
type: RASTER
status: 'OFF'
offsite:
- 252
- 252
- 252
classes:
- __type__: class
name: Digital Raster Graphic
keyimage: graphics/drgs_keyimage.png
metadata:
ows_title: USGS 1:250,000 Digital Raster Graphic
ows_abstract: Hibbing and Bemidji quadrangles.
wms_srs: EPSG:26915
__type__: metadata
tileindex: drgidx
- __type__: layer
name: ctybdpy2
type: POLYGON
status: 'OFF'
data: ctybdpy2
template: ttt
requires: '![drgs]'
classitem: cty_name
classes:
- __type__: class
expression: Itasca
styles:
- __type__: style
outlinecolor:
- 128
- 128
- 128
color:
- 225
- 225
- 185
- __type__: class
expression: /./
styles:
- __type__: style
outlinecolor:
- 128
- 128
- 128
color:
- 255
- 255
- 255
metadata:
ows_title: County Boundary
ows_abstract: Itasca County boundary shapefile.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: mcd90py2
group: cities
type: POLYGON
data: mcd90py2
status: 'OFF'
classitem: city_name
classes:
- __type__: class
name: Cities & Towns
expression: /./
styles:
- __type__: style
color:
- 255
- 225
- 90
template: templates/mcd90py2.html
header: templates/mcd90py2_header.html
footer: templates/mcd90py2_footer.html
metadata:
ows_title: Minor Civil Divisions
ows_abstract: Minor civil divisions for Itasca County (boundaries only).
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: twprgpy3
type: POLYGON
data: twprgpy3
template: ttt
status: 'OFF'
classes:
- __type__: class
name: Townships
styles:
- __type__: style
symbol: circle
size: 2
outlinecolor:
- 181
- 181
- 145
metadata:
ows_title: Township Boundaries
ows_abstract: Pulic Land Survey (PLS) township boundaries for Itasca County.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: lakespy2
type: POLYGON
status: 'OFF'
data: lakespy2
projection:
- init=epsg:26915
classes:
- __type__: class
name: Lakes & Rivers
template: templates/lakespy2.html
styles:
- __type__: style
color:
- 49
- 117
- 185
header: templates/lakespy2_header.html
footer: templates/lakespy2_footer.html
tolerance: 3
metadata:
ows_title: Lakes and Rivers
ows_abstract: DLG lake and river polygons for Itasca County.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: dlgstln2
type: LINE
status: 'OFF'
data: dlgstln2
classes:
- __type__: class
name: Streams
template: templates/dlgstln2.html
styles:
- __type__: style
color:
- 49
- 117
- 185
header: templates/dlgstln2_header.html
footer: templates/dlgstln2_footer.html
tolerance: 5
metadata:
ows_title: Streams
ows_abstract: DLG streams for Itasca County.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: ctyrdln3
group: roads
maxscaledenom: 300000
status: 'OFF'
data: ctyrdln3
template: ttt
type: LINE
classes:
- __type__: class
styles:
- __type__: style
color:
- 0
- 0
- 0
projection:
- init=epsg:26915
metadata:
ows_title: County Roads
ows_abstract: County roads (lines only) derived from MNDOT roads layer.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: ctyrdln3_anno
group: roads
maxscaledenom: 300000
status: 'OFF'
data: ctyrdln3
template: ttt
type: LINE
labelitem: road_name
classes:
- __type__: class
labels:
- __type__: label
minfeaturesize: 40
mindistance: 150
position: CC
size: TINY
color:
- 0
- 0
- 0
styles:
- __type__: style
color:
- 255
- 255
- 255
symbol: symbols/ctyhwy.png
metadata:
ows_title: County Roads
ows_abstract: County roads (shields only) derived from MNDOT roads layer.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: majrdln3
group: roads
maxscaledenom: 600000
status: 'OFF'
data: majrdln3
template: ttt
type: LINE
classes:
- __type__: class
name: Roads
styles:
- __type__: style
color:
- 0
- 0
- 0
metadata:
ows_title: Highways
ows_abstract: Highways- state, US and interstate (lines only) derived from MNDOT
roads layer.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: majrdln3_anno
group: roads
maxscaledenom: 600000
status: 'OFF'
data: majrdln3
template: ttt
type: LINE
labelitem: road_num
classitem: road_class
classes:
- __type__: class
expression: '3'
labels:
- __type__: label
minfeaturesize: 50
mindistance: 150
position: CC
size: TINY
color:
- 0
- 0
- 0
styles:
- __type__: style
color:
- 0
- 0
- 0
symbol: symbols/sthwy.png
- __type__: class
expression: '2'
labels:
- __type__: label
minfeaturesize: 50
mindistance: 150
position: CC
size: TINY
color:
- 0
- 0
- 0
styles:
- __type__: style
color:
- 0
- 0
- 0
symbol: symbols/ushwy.png
- __type__: class
expression: '1'
labels:
- __type__: label
minfeaturesize: 50
mindistance: 150
position: CC
size: TINY
color:
- 255
- 255
- 255
styles:
- __type__: style
color:
- 0
- 0
- 0
symbol: symbols/interstate.png
metadata:
ows_title: Highways
ows_abstract: Highways- state, US and interstate (shields only) derived from MNDOT
roads layer.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: airports
type: POINT
data: airports
projection:
- init=epsg:26915
status: 'OFF'
classes:
- __type__: class
name: Airports
styles:
- __type__: style
color:
- 128
- 255
- 164
symbol: circle
size: 7
template: templates/airports.html
header: templates/airports_header.html
footer: templates/airports_footer.html
tolerance: 5
metadata:
ows_title: Airports
ows_abstract: Airport runways for Itasca County.
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
- __type__: layer
name: mcd90py2_anno
group: cities
template: ttt
type: POINT
data: mcd90py2
status: 'OFF'
labelitem: city_name
classitem: city_name
labelmaxscaledenom: 500000
classes:
- __type__: class
expression: /./
labels:
- __type__: label
color:
- 0
- 0
- 0
shadowcolor:
- 218
- 218
- 218
shadowsize:
- 2
- 2
type: BITMAP
size: MEDIUM
position: CC
partials: false
buffer: 2
metadata:
ows_title: Minor Civil Divisions
ows_abstract: Minor civil divisions for Itasca County (annotation only).
wms_srs: EPSG:26915
gml_include_items: all
gml_featureid: FID
gml_types: auto
__type__: metadata
#
# Start of map file
#
MAP
NAME ITASCA
STATUS ON
SIZE 600 600
PROJECTION
"init=epsg:26915"
END
EXTENT 388107.634400379 5203120.88405952 500896.339019834 5310243.30613897
UNITS METERS
SHAPEPATH "data"
IMAGECOLOR 255 255 255
IMAGETYPE PNG
#
# Start of symbol definitions (we're only using a few)
#
SYMBOL
NAME 'circle'
TYPE ELLIPSE
POINTS 1 1 END
FILLED TRUE
END
SYMBOL
NAME 'star'
TYPE VECTOR
FILLED TRUE
POINTS
0 .375
.35 .375
.5 0
.65 .375
1 .375
.75 .625
.875 1
.5 .75
.125 1
.25 .625
END
END
OUTPUTFORMAT
NAME "geojson"
DRIVER "OGR/GEOJSON"
MIMETYPE "application/json"
FORMATOPTION "FORM=SIMPLE"
FORMATOPTION "STORAGE=memory"
END
OUTPUTFORMAT
NAME "png"
DRIVER AGG/PNG
MIMETYPE "image/png"
IMAGEMODE RGB
EXTENSION "png"
FORMATOPTION "GAMMA=0.75"
TRANSPARENT ON
END
#
# Start of web interface definition (including WMS enabling metadata)
#
WEB
HEADER "templates/header.html"
TEMPLATE "itasca_basic.html" # this can be changed by the index.html web application
FOOTER "templates/footer.html"
MINSCALEDENOM 1000
MAXSCALEDENOM 1550000
# TOCHECK change the next two lines to match your setup
IMAGEPATH "/var/www/html/tmp/"
IMAGEURL "/tmp/"
METADATA
OWS_TITLE "MapServer Itasca Demo"
OWS_ABSTRACT "This is a MapServer demo application for Itasca County located in north central Minnesota."
WMS_ACCESSCONSTRAINTS "none"
OWS_ENABLE_REQUEST "*"
# TOCHECK change the next two lines to match your setup
OGA_HTML_TEMPLATE_DIRECTORY "/usr/share/mapserver/ogcapi/templates/html-plain/"
OGA_ONLINERESOURCE "http://localhost/cgi-bin/mapserv/itasca/ogcapi"
# TOCHECK change this value to match your setup
OWS_ONLINERESOURCE "http://localhost/cgi-bin/mapserv?map=/usr/local/www/docs_maps/mapserver_demos/itasca/itasca.map&"
WFS_SRS "EPSG:26915 EPSG:3857 EPSG:4326"
WFS_GETFEATURE_FORMATLIST "gml,geojson"
WMS_SRS "EPSG:26915 EPSG:3857"
END
END
#
# Start of reference map
#
REFERENCE
IMAGE graphics/reference.png
EXTENT 393234.393701263 5205405.16440722 495769.579718949 5307959.02579127
SIZE 120 120
STATUS ON
MINBOXSIZE 5
MAXBOXSIZE 100
COLOR 255 0 0
OUTLINECOLOR 0 0 0
MARKERSIZE 8
MARKER 'star'
END
#
# Start of legend
#
LEGEND
KEYSIZE 18 12
LABEL
TYPE BITMAP
SIZE MEDIUM
COLOR 0 0 89
END
STATUS ON
END
#
# Start of scalebar
#
SCALEBAR
IMAGECOLOR 0 0 0
LABEL
COLOR 255 255 255
SIZE TINY
END
STYLE 1
SIZE 100 2
COLOR 255 255 255
UNITS MILES
INTERVALS 1
TRANSPARENT ON
STATUS ON
END
#
# Start of layer definitions
#
LAYER
NAME drgs
TYPE RASTER
STATUS OFF
# OFFSITE 31
OFFSITE 252 252 252
CLASS
NAME 'Digital Raster Graphic'
KEYIMAGE graphics/drgs_keyimage.png
END
METADATA
OWS_TITLE "USGS 1:250,000 Digital Raster Graphic"
OWS_ABSTRACT "Hibbing and Bemidji quadrangles."
WMS_SRS "EPSG:26915"
END
TILEINDEX drgidx
END
LAYER
NAME ctybdpy2
TYPE POLYGON
STATUS OFF
DATA ctybdpy2
TEMPLATE "ttt"
# no need for a background IF the USGS quads are being drawn
REQUIRES "![drgs]"
CLASSITEM 'cty_name'
CLASS
EXPRESSION 'Itasca'
STYLE
OUTLINECOLOR 128 128 128
COLOR 225 225 185
END
END
CLASS # every other county in the state
EXPRESSION /./
STYLE
OUTLINECOLOR 128 128 128
COLOR 255 255 255
END
END
METADATA
OWS_TITLE "County Boundary"
OWS_ABSTRACT "Itasca County boundary shapefile."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END
LAYER
NAME mcd90py2
GROUP cities
TYPE POLYGON
DATA mcd90py2
STATUS OFF
CLASSITEM city_name
CLASS
NAME "Cities & Towns"
EXPRESSION /./
STYLE
COLOR 255 225 90
END
TEMPLATE "templates/mcd90py2.html"
END
HEADER "templates/mcd90py2_header.html"
FOOTER "templates/mcd90py2_footer.html"
METADATA
OWS_TITLE "Minor Civil Divisions"
OWS_ABSTRACT "Minor civil divisions for Itasca County (boundaries only)."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END
LAYER
NAME twprgpy3
TYPE POLYGON
DATA twprgpy3
TEMPLATE "ttt"
STATUS OFF
CLASS
NAME 'Townships'
STYLE
SYMBOL 'circle'
SIZE 2
OUTLINECOLOR 181 181 145
END
END
METADATA
OWS_TITLE "Township Boundaries"
OWS_ABSTRACT "Pulic Land Survey (PLS) township boundaries for Itasca County."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END
LAYER
NAME lakespy2
TYPE POLYGON
STATUS OFF
DATA lakespy2
PROJECTION
'init=epsg:26915'
END
CLASS
NAME 'Lakes & Rivers'
TEMPLATE "templates/lakespy2.html"
STYLE
COLOR 49 117 185
END
END
HEADER "templates/lakespy2_header.html"
FOOTER "templates/lakespy2_footer.html"
TOLERANCE 3
METADATA
OWS_TITLE "Lakes and Rivers"
OWS_ABSTRACT "DLG lake and river polygons for Itasca County."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END # lakes
LAYER
NAME dlgstln2
TYPE LINE
STATUS OFF
DATA dlgstln2
CLASS
NAME "Streams"
TEMPLATE "templates/dlgstln2.html"
STYLE
COLOR 49 117 185
END
END
HEADER "templates/dlgstln2_header.html"
FOOTER "templates/dlgstln2_footer.html"
TOLERANCE 5
METADATA
OWS_TITLE "Streams"
OWS_ABSTRACT "DLG streams for Itasca County."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END # streams
LAYER
NAME ctyrdln3
GROUP roads
MAXSCALEDENOM 300000
STATUS OFF
DATA ctyrdln3
TEMPLATE "ttt"
TYPE LINE
CLASS
STYLE
COLOR 0 0 0
END
END
PROJECTION
'init=epsg:26915'
END
METADATA
OWS_TITLE "County Roads"
OWS_ABSTRACT "County roads (lines only) derived from MNDOT roads layer."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END # county roads
LAYER
NAME ctyrdln3_anno
GROUP roads
MAXSCALEDENOM 300000
STATUS OFF
DATA ctyrdln3
TEMPLATE "ttt"
TYPE LINE
LABELITEM "road_name"
CLASS
LABEL
MINFEATURESIZE 40
MINDISTANCE 150
POSITION CC
SIZE TINY
COLOR 0 0 0
STYLE
COLOR 255 255 255
SYMBOL 'symbols/ctyhwy.png'
END
END
END
METADATA
OWS_TITLE "County Roads"
OWS_ABSTRACT "County roads (shields only) derived from MNDOT roads layer."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END # county road annotation
LAYER
NAME majrdln3
GROUP roads
MAXSCALEDENOM 600000
STATUS OFF
DATA majrdln3
TEMPLATE "ttt"
TYPE LINE
CLASS
NAME "Roads"
STYLE
COLOR 0 0 0
END
END
METADATA
OWS_TITLE "Highways"
OWS_ABSTRACT "Highways- state, US and interstate (lines only) derived from MNDOT roads layer."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END # highways
LAYER
NAME majrdln3_anno
GROUP roads
MAXSCALEDENOM 600000
STATUS OFF
DATA majrdln3
TEMPLATE "ttt"
TYPE LINE
LABELITEM "road_num"
CLASSITEM "road_class"
CLASS
EXPRESSION "3"
LABEL
MINFEATURESIZE 50
MINDISTANCE 150
POSITION CC
SIZE TINY
COLOR 0 0 0
STYLE
COLOR 0 0 0 # dummy color
SYMBOL 'symbols/sthwy.png'
END
END
END
CLASS
EXPRESSION "2"
LABEL
MINFEATURESIZE 50
MINDISTANCE 150
POSITION CC
SIZE TINY
COLOR 0 0 0
STYLE
COLOR 0 0 0 # dummy color
SYMBOL 'symbols/ushwy.png'
END
END
END
CLASS
EXPRESSION "1"
LABEL
MINFEATURESIZE 50
MINDISTANCE 150
POSITION CC
SIZE TINY
COLOR 255 255 255
STYLE
COLOR 0 0 0 # dummy color
SYMBOL 'symbols/interstate.png'
END
END
END
METADATA
OWS_TITLE "Highways"
OWS_ABSTRACT "Highways- state, US and interstate (shields only) derived from MNDOT roads layer."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END # highway annotation
LAYER
NAME airports
TYPE POINT
DATA airports
PROJECTION
'init=epsg:26915'
END
STATUS OFF
CLASS
NAME 'Airports'
STYLE
COLOR 128 255 164
SYMBOL 'circle'
SIZE 7
END
TEMPLATE "templates/airports.html"
END
HEADER "templates/airports_header.html"
FOOTER "templates/airports_footer.html"
TOLERANCE 5
METADATA
OWS_TITLE "Airports"
OWS_ABSTRACT "Airport runways for Itasca County."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END
LAYER
NAME mcd90py2_anno
GROUP cities
TEMPLATE "ttt"
TYPE POINT
DATA mcd90py2
STATUS OFF
LABELITEM "city_name"
CLASSITEM "city_name"
LABELMAXSCALEDENOM 500000
CLASS
EXPRESSION /./
LABEL
COLOR 0 0 0
SHADOWCOLOR 218 218 218
SHADOWSIZE 2 2
TYPE BITMAP
SIZE MEDIUM
POSITION CC
PARTIALS FALSE
BUFFER 2
END
END
METADATA
OWS_TITLE "Minor Civil Divisions"
OWS_ABSTRACT "Minor civil divisions for Itasca County (annotation only)."
WMS_SRS "EPSG:26915"
GML_INCLUDE_ITEMS "all"
GML_FEATUREID "FID"
GML_TYPES "auto"
END
END
END # Map File