r.to.vect1grass
Converts a raster map into a vector map.
Usage
r.to.vect
r.to.vect --help
r.to.vect [-svzbt]
input=name
output=name
type=string
[column=name]
[--overwrite]
[--help]
[--verbose]
[--quiet]
[--ui]
Keywords
raster, conversion, geometry, vectorization
Overview
r.to.vect scans the named input raster map layer, extracts points, lines or area edge features from it, converts data to GRASS vector format.
Point conversion
The r.to.vect program extracts data from a GRASS raster map layer and stores output in a new GRASS vector file.
Line conversion
r.to.vect assumes that the input map has been thinned using r.thin.
r.to.vect extracts vectors (aka, "arcs") from a raster map. These arcs may represent linear features (like roads or streams), or may represent area edge features (like political boundaries, or soil mapping units).
r.thin and r.to.vect may create excessive nodes at every junction, and may create small spurs or "dangling lines" during the thinning and vectorization process. These excessive nodes and spurs may be removed using v.clean.
Area conversion
r.to.vect first traces the perimeter of each unique area in the raster map layer and creates vector data to represent it. The cell category values for the raster map layer will be used to create attribute information for the resultant vector area edge data.
A true vector tracing of the area edges might appear blocky, since the vectors outline the edges of raster data that are stored in rectangular cells. To produce a better-looking vector map, r.to.vect smoothes the corners of the vector data as they are being extracted. At each change in direction (i.e., each corner), the two midpoints of the corner cell (half the cell’s height and width) are taken, and the line segment connecting them is used to outline this corner in the resultant vector map. (The cell’s cornermost node is ignored.) Because vectors are smoothed by this program, the resulting vector map will not be "true" to the raster map from which it was created. The user should check the resolution of the geographic region (and the original data) to estimate the possible error introduced by smoothing.
r.to.vect extracts only area edges from the named raster input file. If the raster map contains other data (i.e., line edges, or point data) the output may be wrong.
Examples
The examples are based on the North Carolina sample dataset:
Conversion of raster points to vector points:
Random sampling of points:
g.region raster=elevation -p# random sampling of points (note that r.random also writes vector points)r.random elevation raster_output=elevrand1000 n=1000r.to.vect input=elevrand1000 output=elevrand1000 type=point# univariate statistics of sample pointsv.univar elevrand1000 column=value type=point# compare to univariate statistics on original full raster mapr.univar elevation
Conversion of raster lines to vector lines:
Vectorization of streams in watershed basins map:
g.region raster=elevation -pr.watershed elev=elevation stream=elev.streams thresh=50000r.to.vect -s input=elev.streams output=elev_streams type=line# drop "label" column which is superfluous in this examplev.db.dropcolumn map=elev_streams column=labelv.db.renamecolumn map=elev_streams column=value,basin_id# report length per basin IDv.report map=elev_streams option=length units=meters sort=asc
Conversion of raster polygons to vector polygons:
Vectorization of simplified landuse class map:
g.region raster=landclass96 -p# we smooth corners of area featuresr.to.vect -s input=landclass96 output=my_landclass96 type=areav.colors my_landclass96 color=random
Known issues
For type=line the input raster map MUST be thinned by r.thin; if not, r.to.vect may crash.
Source code
Available at: r.to.vect source code (history)
Accessed: Monday Feb 24 17:50:56 2025
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
© 2003-2025 GRASS Development Team, GRASS GIS 8.4.1 Reference Manual
Releases
10 releases since Debian 4.0 (Etch); the text changed 9 times.