Unit 06 - Data export

Data produced by GRASS tools (like r.mapcalc or i.vi in Unit 05 - Raster processing) is always stored in the current mapset.

There are two fundamental tools for exporting data from GRASS to exchange data formats:

  • r.out.gdal for exporting raster data (File ‣ Export raster map ‣ Common export formats)
  • v.out.ogr for exporting vector data (File ‣ Export vector map ‣ Common export formats)

These tools are based on well-known GDAL library for reading and writing raster and vector geospatial data formats. Thanks to this library GRASS is able to export data into various GIS formats, see supported raster and vector formats.

../_images/export-menu.png

Fig. 40 Export raster map in Layer Manager.

Important

Remember that raster export tools operate in a current computational region. So don’t forget to set desired computational region before exporting raster data. In this way, for example, you can easily export only subregion defining your area of interest.

../_images/raster-export.png

Fig. 41 Export NDVI raster into GeoTIFF format.

Try to load created raster in some GIS software like Esri ArcGIS or QGIS. Note that color table is not exported in the case of floating-point data. You need to set up suitable color interpretation in your software on your own.

../_images/qgis-ndvi-tif.png

Fig. 42 NDVI TIFF file loaded in QGIS.

Notes

  • Most of vector data formats (eg. Esri Shapefile, OCG GML or OGC GeoPackage) are based on simple feature model. It means that GRASS export tool converts topological primitives (lines, boundaries, centroids, areas, isles) into simple features (linestrings, polygons). Points have no topology, so no conversion is involved.
  • GRASS does not distinguish between single and multi parts (features and multifeatures). Attributes are simply linked to primitives (usually points, lines, or centroids) via so called “category”. More primitives can have the same category assigned, so the same attributes linked. This is a way how GRASS handles multiparts. By default v.out.ogr exports such primitives as single parts, ie. features. Multi parts (multifeatures) are written only when -m flag is given.
  • GRASS supports also one of few topological formats, PostGIS Topology, see v.out.postgis for details.
  • To increase interoperability with your Esri-based colleagues, GRASS data can be exported directly also to Esri File Geodatabase format. This requires GDAL with FileGDB support. But we highly recommend to use for data exchange open standards like OGC GeoPackage which Esri products can read. OGC GeoPackage is default output format in v.out.ogr since GRASS 7.4.

Interoperability with Esri ArcGIS

GRASS is able to read data stored in Esri Shapefile (SHP) or File Geodatabase (FileGDB) out of the box thanks to GDAL library. Note that in the case of FileGDB only vector data (feature classes) are supported, it’s not possible to read raster data from this format. Vector data can be written by GRASS to Esri FileGDB format only when GDAL is installed with proprietary-based FileGDB support.

In any case it is recommended to use modern OGC-based OGC GeoPackage format for exchanging data between various GIS packages. This format allows to store multiple raster or vector layers in one file (GeoPackage is based on file-based SQLite DB format). In the case of raster data also GeoTIFF format can be used.

Switch from GRASS native format to external formats

GRASS environment can be set to produce data directly in external data formats. It can be useful at the end of a workflow when final output data is produced. Writing output data directly to desired format saves one step, exporting data to target data formats by r.out.gdal or v.out.ogr. External format can be set by r.external.out for raster outputs or by v.external.out in the case of vector outputs.

Example for our workflow (map names shorten):

g.region vector=jena_boundary align=B04_10m
r.mask -i vector=MaskFeature
r.external.out directory=/home/user format=GTiff extension=tif
i.vi red=B04_10m output=ndvi nir=B08_10m

Produced data is stored directly (without any data conversion) in external format (GeoTIFF in this case). GRASS also creates automatically link to such data (similarly as r.external does), so produced data can be accessed as “normal” raster maps by GRASS for further computation.

Default raster format can be reverted to GRASS native format by r.external.out -r command.