GRASS and MapServer

From GRASS-Wiki
Jump to navigation Jump to search

GRASS maps from mapfiles

MapServer needs a mapfile containing the information, how to create the maps. Examples of these can be found, so here you'll find GRASS specific information.

Raster Maps

A short example of a layer definition to access a GRASS raster:

LAYER
  NAME "Example"
  TYPE RASTER
  STATUS ON
  DATA "/path/to/grassdb/location/mapset/cellhd/example"
  CLASS NAME "Example" # You need to have a class definition in the layer
  END
END

Notes:

  • The rasters are limited to values from 0 to 255, the values over this are interpreted as 255. Rescale (r.rescale) your maps when necessary.
  • You really need to have a CLASS in your layer, otherwise no data will be shown. An empty class is quite fine to show the whole map.


See the Color tables wiki page for more on exporting raster color tables as SLD XML rules using the r.colors.out_sld addon script.

Vector Maps

A short example of a layer definition to access a GRASS vector:

LAYER
  NAME "Example"
  TYPE LINE
  STATUS ON
  CONNECTIONTYPE OGR
  CONNECTION "/path/to/grassdb/mapset/location/vector/example/head"
  DATA "1" # Layer number
  CLASS # You need to have a class definition; otherwise nothing is shown on the map
    NAME "Example"
    COLOR 155 155 0
  END
END

Notes:

  • You need to have GDAL with OGR and GRASS support for this to work. Note, that in this example the maps are first exported to shapefiles. This is no longer necessary, as the maps can be accessed directly with OGR.
  • Usually GRASS layers have no names and the layer number is used in DATA. However, it is possible that they do have names. This can happen for example when importing files with v.in.dxf, as the module keeps the dxf-file layer names and stores them into the GRASS vector. The layer names, if such there are, can be found in /path/to/grassdb/mapset/location/vector/vectorname/dbln, or with ogrinfo -ro /path/to/grassdb/mapset/location/vector/vectorname/dbln. Why this is so important is because if there are layer names defined, these layers cannot be accessed through the layer number with OGR. They have to be accessed through the layer name.

Examples and useful links