Note: This document is for an older version of GRASS GIS that has been discontinued. You should upgrade, and read the current manual page.

GRASS logo

NAME

r.in.vect - Converts an external vector layer to a raster layer using gdal.Rasterize (the vector layer will be reprojected first if its CRS is different from the current mapset), and imports this raster layer.

KEYWORDS

vector, raster, import, convert

SYNOPSIS

r.in.vect
r.in.vect --help
r.in.vect [-vad] input=name [layer=string] output=name [attribute_column=string] [label_column=string] [value=integer] [memory=memory in MB] [--overwrite] [--help] [--verbose] [--quiet] [--ui]

Flags:

-v
Convert whole vector
Set this flag if the whole vector layer needs to be converted. By default, only the part overlapping with the computational region is converted.
-a
Match region's extent to vector bounding box
Set region extent to match that of the bounding box of the vector layer.
-d
Create densified lines (default: thin lines)
Pixels touched by lines or polygons will be included, not just those on the line render path, or whose center point is within the polygon.
--overwrite
Allow output files to overwrite existing files
--help
Print usage summary
--verbose
Verbose module output
--quiet
Quiet module output
--ui
Force launching GUI dialog

Parameters:

input=name [required]
Name of input file
layer=string
OGR layer name
OGR layer name, like tbe name of an shapefile or the name of a layer in a Geopackage (see v.in.ogr for examples)
output=name [required]
Name for output raster map
attribute_column=string
Name of attribute column that hold the values to be used as raster values (data type must be numeric)
label_column=string
Name of attribute column that hold the values to be used as raster labels
value=integer
Raster value (if attribute_column is left empty)
memory=memory in MB
Maximum memory to be used (in MB)
Cache size for raster rows
Default: 300

Table of contents

DESCRIPTION

r.in.vect transforms an external vector file (like GeoPackage) into a raster file and imports it into GRASS GIS. Optionally, attributes from the vector layer can be converted to raster category labels.

When users have a vector file that they want to convert to a raster map, they would normally import the vector map into GRASS GIS using, e.g., v.in.ogr, and subsequently convert the resulting vector into a raster map using v.to.rast. Because of the topological vector format of GRASS GIS, importing large complex vector maps can be slow. To speed up the process, r.in.vect converts the user-defined vector file to an intermediate geoTIF file (using gdal.rasterize) and imports it into GRASS GIS.

The objects in the vector map will be assigned an user-defined value using the value parameter. Alternatively, the user can use the attribute_column to specify the name of an existing column from the vector map's attribute table. The values in that column will be used as raster values in the output raster map.

Notes

By default, r.in.vect will only affect data in areas lying inside the boundaries of the current computational region. Before running the function, users should therefore ensure that the computational region is correctly set, and that the region's resolution is at the desired level. Alternatively, users can use the -v flag to set the exent of the raster layer to that of the vector layer. To ensure that the resulting raster map cleanly aligns with the computational region, the extent may be slightly larger than that of the vector layer.

If the coordinate reference system (CRS) of the vector file differs from that of the mapset in which users want to import the raster, the vector file will be first reprojected using ogr2ogr.

The label_column parameter can be used to assign raster category labels. Users should check if each unique value from the category column has one corresponding label in the label column. If there are categories with more than one label, the first from the label column will be used (and a warning will be printed).

With the -d flag, all pixels touched by lines or polygons will be updated, not just those on the line render path, or which center point is within the polygon. For lines, this is similar to setting the -d flag in v.to.rast.

Note that this will make a difference for complex and large vector layers. For simple and small vector layers, it is probably faster to import the vector layer first and converting it to a raster in GRASS.

EXAMPLE

The examples of r.in.vect use vector maps from the North Carolina sample data set.

Example 1

First, export a vector layer as a GeoPackage.
# Export the geology vector map as Geopackage
v.out.ogr input=geology@PERMANENT output=geology.gpkg format=GPKG

Import the geology.gpkg as raster. Raster cells overlapping with the vector features will be assigned a value of 1, and the other raster cells null. If you have RAM to spare, increase the memory to speed up the import.

# Set the region
g.region -a vector=geology res=500

# Import the GeoPackage
r.in.vect input=geology.gpkg \
output=geology_rast \
value=1 \
memory=2000
The geology vector file converted
to, and imported as raster in GRASS. Example 1
Figure 1: The geology vector file was converted to, and imported as a raster into GRASS GIS, using the default settings.

If the GeoPackage file (or any other data source) has multiple layers, users need to specify which layer to use with the layer parameter. Otherwise, the first layer will be selected.

Example 2

Import the geology.gpkg as raster. Specify the column holding the values to use as raster values and the column holding the labels for the raster values.
# Import the layer
r.in.vect input=geology.gpkg \
output=geology_rast2 \
attribute_column=GEOL250_ \
rat_column=GEO_NAME
memory=2000

# Assign random colors
r.colors map=geology_rast2 color=random
The geology vector file converted
to, and imported as raster in GRASS GIS. Example 2
Figure 2: The geology vector file converted to raster and imported into GRASS GIS using the values from the vector attribute column GEOL250_ as raster values.

Example 3

First, set the resolution to 1 meter. Next, export the busroute6 vector map as GeoPackage, and import it as a raster. Use the -v flag to ensure the extent of the raster matches that of the vector (by default, the bounding box of the raster map will match that of the current computational region).
# Set the resolution to 1 m
g.region -a res=1

# Export the busrout6 vector layer
v.out.ogr input=busroute6@PERMANENT \
type=line \
output=busroute6.gpkg \
format=GPKG

# Import it as raster layer, using the extent of the vector layer
r.in.vect -v input=busroute6.gpkg \
output=busroute6_1 \
value=1 \
memory=2000
The busroute6 vector file converted
to raster and imported into GRASS GIS. Example 3
Figure 3: The busroute6 vector file converted to raster and imported into GRASS GIS using the extent of the vector map.

Example 4

The same as above, but using the -d flag to create densified lines.
# Import vector as a raster map, using the extent of the vector
r.in.vect -v -d \
input=busroute6.gpkg \
output=busroute6_2 \
value=1 \
memory=2000
The busroute6 vector file converted
to raster and imported into GRASS GIS. Example 4
Figure 4: Rasterize the busroute 6 vector map using the -d flag to create densified lines by adding extra cells (shown in red). This avoids gaps or lines that consist of cells that are only diagonally connected.

SEE ALSO

v.to.rast,

AUTHORS

Paulo van Breugel (ecodiv.earth)
Applied Geo-information Sciences
HAS green academy, University of Applied Sciences

SOURCE CODE

Available at: r.in.vect source code (history)

Latest change: Tuesday Sep 24 09:12:24 2024 in commit: 18bf784b89bb36fa024c2f9eed835849b33e4a3c


Main index | Raster index | Topics index | Keywords index | Graphical index | Full index

© 2003-2024 GRASS Development Team, GRASS GIS 8.3.3dev Reference Manual