GRASS logo

NAME - Converts (rasterize) a vector map into a raster map.


vector, conversion, raster, rasterization

SYNOPSIS --help [-d] input=name [layer=string] [type=string[,string,...]] [cats=range] [where=sql_query] output=name use=string [attribute_column=name] [rgb_column=name] [label_column=name] [value=float] [memory=memory in MB] [--overwrite] [--help] [--verbose] [--quiet] [--ui]


Create densified lines (default: thin lines)
All cells touched by the line will be set, not only those on the render path
Allow output files to overwrite existing files
Print usage summary
Verbose module output
Quiet module output
Force launching GUI dialog


input=name [required]
Name of input vector map
Or data source for direct OGR access
Layer number or name
Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
Default: 1
Input feature type
Options: point, line, boundary, centroid, area
Default: point,line,area
Category values
Example: 1,3,7-9,13
WHERE conditions of SQL statement without 'where' keyword
Example: income < 1000 and population >= 10000
output=name [required]
Name for output raster map
use=string [required]
Source of raster values
Options: attr, cat, val, z, dir
attr: read values from attribute table
cat: use category values
val: use value specified by value option
z: use z coordinate (points or contours only)
dir: line direction in degrees CCW from east (lines only)
Name of column for 'attr' parameter (data type must be numeric)
Name of color definition column (with RRR:GGG:BBB entries)
Name of column used as raster category labels
Raster value (for use=val)
Default: 1
memory=memory in MB
Maximum memory to be used (in MB)
Cache size for raster rows
Default: 300

Table of contents

DESCRIPTION transforms GRASS vector map layers into GRASS raster map layer format. Optionally, attributes can be converted to raster category labels.


In order to avoid unexpected results, the type of vector features should always be specified. The default is to convert all vector features, but if only e.g. areas should be converted use type=area rather than type=point,line,area. will only affect data in areas lying inside the boundaries of the current geographic region. A grid cell belongs to the area where the grid cell center falls into.

Before running, the user should therefore ensure that the current geographic region is correctly set and that the region resolution is at the desired level.

Either the column parameter or the value parameter must be specified. The use option may be specified alone when using the dir option.

use options are:

The column parameter uses an existing column from the vector map database table as the category value in the output raster map. Existing table columns can be shown by using db.describe.

An empty raster map layer will be created if the vector map layer has not been assigned category/attribute labels (e.g., through use of v.category option=add).


Line directions are given in degrees counterclockwise from east.

Raster category labels are supported for all of use= except use=z.

The -d flag applies only to lines and boundaries, the default is to set only those cells on the render path (thin line).

Boundaries (usually without categories) can be rasterized with type=boundary layer=-1 use=val


Convert a vector map and use column SPEED from attribute table

db.describe -c table=vect_map

Column 1: CAT
Column 2: SPEED
Column 3: WIDTH input=vect_map output=raster_map attribute_column=SPEED type=line

Calculate stream directions from a river vector map (Spearfish) input=streams output=streamsdir use=dir

Calculate slope along path

Using slope and aspect maps, compute slope along a bus route (use full NC sample dataset):
g.region raster=elevation -p
r.slope.aspect elevation=elevation slope=slope aspect=aspect

# compute direction of the bus route input=busroute11 type=line output=busroute11_dir use=dir

# extract steepest slope values and transform them into slope along path
r.mapcalc "route_slope = if(busroute11, slope)"
r.mapcalc "route_slope_dir = abs(atan(tan(slope) * cos(aspect - busroute11_dir)))"
Slope along path
Slope in degrees along bus route

Convert a vector polygon map to raster including descriptive labels

In this example, the ZIP code vector map is rasterized (North Carolina sample dataset):
# rasterize ZIP codes at 50m raster resolution
g.region vector=zipcodes_wake res=50 -ap
# vector to raster conversion, with category labels input=zipcodes_wake output=myzipcodes use=attr attribute_column="ZIPNUM" label_column="NAME"

Convert vector points to raster with raster cell binning

In this example, the number of schools per raster cell are counted (North Carolina sample dataset):
g.copy vector=schools_wake,myschools_wake

# set computation region for raster binning
g.region vector=myschools_wake res=5000 -p -a

# add new column for counting
v.db.addcolumn myschools_wake column="value integer"
v.db.update myschools_wake column=value value=1

# verify attributes myschools_wake column=cat,value
v.out.ascii input=myschools_wake output=- column=value

# export and import on the fly, use 4th column (value) as input
v.out.ascii input=myschools_wake output=- column=value | input=- \
            z=4 output=schools_wake_aggreg method=sum

d.mon wx0
d.rast schools_wake_aggreg
d.vect schools_wake
d.grid 5000
Number of schools per raster cell
Number of schools per raster cell


db.describe, v.category


Original code: Michael Shapiro, U.S. Army Construction Engineering Research Laboratory
GRASS 6.0 updates: Radim Blazek, ITC-irst, Trento, Italy
Stream directions: Jaro Hofierka and Helena Mitasova
GRASS 6.3 code cleanup and label support: Brad Douglas


Available at: source code (history)

Latest change: Monday Feb 27 13:45:25 2023 in commit: a82501dc85294207e8e58437c3ec7f1056465ed4

Main index | Vector index | Topics index | Keywords index | Graphical index | Full index

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