v.to.rast(1grass)
β¨ NAME β¨
okay so bestie, welcome to the <rainbow>v.to.rast</rainbow> manual page π β this is the GRASS User's Manual entry, and it's the one that takes your vector map and rasterizes it. Like, it converts a vector map into a raster map. That's the whole vibe. π
π·οΈ KEYWORDS π·οΈ
vector, conversion, raster, rasterization
π SYNOPSIS π
v.to.rast
v.to.rast --help
v.to.rast [-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]
π© Flags π©
-dβ create densified lines (and the default here is thin lines, fyi). Every single cell that the line touches gets set, not just the ones sitting on the render path. so like, thick girl behavior π«Ά--overwriteβ lets output files overwrite existing files. use with care, it will simply replace things π--helpβ prints the usage summary--verboseβ verbose module output--quietβ quiet module output--uiβ forces the GUI dialog to launch
π§Έ Parameters π§Έ
input=name[required] β name of input vector map. Or, plot twist, it can be a data source for direct OGR access.layer=stringβ layer number or name. Vector features can have category values in different layers, and this number decides which layer we're using. When you're doing direct OGR access, this is the layer name instead. Default:1type=string[,string,...]β input feature type. Options:point,line,boundary,centroid,area. Default:point,line,areacats=rangeβ category values. Example:1,3,7-9,13where=sql_queryβ WHERE conditions of an SQL statement, without thewherekeyword. Example:income < 1000 and population >= 10000output=name[required] β name for output raster mapuse=string[required] β where the raster values come from. Options:attr: read values from attribute tablecat: use category valuesvalue: use the value specified by thevalueoptionz: use z coordinate (points or contours only)dir: line direction in degrees CCW from east (lines only)
attribute_column=nameβ name of the column for theattrparameter (and the data type has to be numeric, no cap)rgb_column=nameβ name of the color definition column (withRRR:GGG:BBBentries, slay)label_column=nameβ name of the column used as raster category labelsvalue=floatβ raster value (foruse=value). Default:1memory=memory in MBβ maximum memory to be used, in MB. It's the cache size for raster rows. Default:300
π« DESCRIPTION π«
v.to.rast transforms GRASS vector map layers into GRASS raster map layer format. And optionally? Attributes can be converted to raster category labels. so it's giving glow-up, honestly β¨
π₯ NOTES π₯
So to avoid any unexpected results (we hate a surprise π), the type of vector features should always be specified. The default is to convert all vector features, but if you only want, say, areas converted, use type=area rather than type=point,line,area. be specific bestie!!
v.to.rast will only affect data in areas lying inside the boundaries of the current geographic region. And a grid cell belongs to the area where the grid cell center falls into. that's the rule, periodt.
So before you run v.to.rast, you the user should therefore make sure the current geographic region is correctly set, and that the region resolution is at the desired level. vibe check your region first, fr fr.
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:
attr- read values from attribute table (default)cat- read values from categoryvalue- use value specified byvalueoptionz- use z coordinate (points or contours only)dir- line direction in degrees counterclockwise from east (lines only)
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). tragic, I know. π
Otherwise:
- Labeled areas and/or centroids will produce filled raster coverages with edges that straddle the original area boundary as long as the boundary is NOT labeled. (Use
v.category option=del type=boundaryto remove.) - Labeled lines and boundaries will produce lines of raster cells which touch the original vector line. This tends to be more aggressive than area-only conversions. π€
- Points and orphaned centroids will be converted into single cells on the resultant raster map.
Line directions are given in degrees counterclockwise from east.
Raster category labels are supported for all of use= except use=z. iykyk.
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
v.to.rast type=boundary layer=-1 use=value
π EXAMPLES π
Convert a vector map and use column SPEED from attribute table
db.describe -c table=vect_map
ncols:3
Column 1: CAT
Column 2: SPEED
Column 3: WIDTH
v.to.rast input=vect_map output=raster_map attribute_column=SPEED type=line
Calculate stream directions from a river vector map (Spearfish)
v.to.rast input=streams output=streamsdir use=dir
Calculate slope along path
Using slope and aspect maps, compute slope along a bus route (use the full NC sample dataset):
g.region raster=elevation -p
r.slope.aspect elevation=elevation slope=slope aspect=aspect
# compute direction of the bus route
v.to.rast 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 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
v.to.rast 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
v.db.select 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 | r.in.xyz 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 π
π SEE ALSO π
db.describe, v.category
π AUTHORS π
- 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
π¦ SOURCE CODE π¦
Available at: v.to.rast source code (history)
Latest change: Friday May 09 14:33:40 2025 in commit: b356c7e108fcbeca77474c8e83ebec8f1e7b3e4a
Main index | Vector index | Topics index | Keywords index | Graphical index | Full index
okay that's the whole thing bestie, we ATE π and now for the cute little sign-off: this was the GRASS 8.5.0 Reference Manual for v.to.rast(1grass), Β© 2003-2026 GRASS Development Team, and the source/version + date live right there at the bottom of the original page β so go rasterize something iconic, mwah πβ¨
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms