r.profile(1grass)
π¦ r.profile(1grass) β GRASS User's Manual π¦
okay bestie, sit down, grab a snack, because this is genuinely one of the cutest little raster tools in GRASS and i need you to understand it the way i do π
β¨ NAME β¨
r.profile β it outputs the raster map layer values that are lying on user-defined line(s). yes that's the whole vibe. you draw a line, it tells you what's underneath. iconic.
πΈ KEYWORDS πΈ
raster, profile, transect
π SYNOPSIS π
r.profile
r.profile --help
r.profile [-gc] input=name [output=name]
[coordinates=east,north[,east,north,...]] [file=name]
[resolution=float] [null_value=string] [units=string] format=name
[color_format=name] [separator=character] [--overwrite] [--help]
[--verbose] [--quiet] [--ui]
π Flags π
-gβ puts the easting and northing in the first two columns of a four column output. so you get four columns instead of two. main character upgrade fr.-cβ outputs color values for each and every profile point (the format is controlled by thecolor_formatoption; default is'triplet'for plain output, and'hex'for JSON). so pretty π--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 raster map. you literally have to give it this one, no skipping βoutput=nameβ name of file for output (useoutput=-for stdout). default:-coordinates=east,north[,east,north,...]β profile coordinate pairs. your waypoints, your little trail π«file=nameβ name of input file containing coordinate pairs. use this instead of the'coordinates'option. and if you set it to"-", it reads from stdin πresolution=floatβ resolution along profile (default = current region resolution)null_value=stringβ string representing NULL value. default:*units=stringβ units. if units are not specified, current project units are used, and meters are used by default in geographic (latlon) projects. options:meters,kilometers,feet,milesformat=name[required] β output format. options:plain,csv,json. default:plainplain: human readable text outputcsv: CSV (Comma Separated Values)json: JSON (JavaScript Object Notation)
color_format=nameβ color format, like, the color format for output values π options:rgb,hex,hsv,tripletrgb: output color in RGB formathex: output color in HEX formathsv: output color in HSV format (experimental)triplet: output color in colon-separated RGB format
separator=characterβ field separator. special characters:pipe,comma,space,tab,newline. default:comma
π DESCRIPTION π
So this program outputs two or four column (with -g) data to stdout or to an ASCII file. The default two column output consists of cumulative profile length and raster value. The optional four column output consists of easting, northing, cumulative profile length, and raster value. Profile end or "turning" points can be set manually with the coordinates argument. The profile resolution, or distance between profile points, is obtained from the current region resolution, or can be manually set with the resolution argument. no cap, that's the whole system πββοΈ
The coordinates parameter can be set to comma separated geographic coordinates for profile line endpoints. Alternatively the coordinate pairs can be piped from the text file specified by file option, or if set to "-", from stdin. In these cases the coordinate pairs should be given one comma separated pair per line. easy peasy.
The resolution parameter sets the distance between each profile point (resolution). The resolution must be provided in GRASS database units (i.e. decimal degrees for Lat Long databases and meters for UTM). By default r.profile uses the resolution of the current GRASS region. π
The null parameter can optionally be set to change the character string representing null values.
π OUTPUT FORMAT π
The multi column output from r.profile is intended for easy use in other programs. The output can be piped (|) directly into other programs or saved to a file for later use. Output with geographic coordinates (-g) is compatible with v.in.ascii and can be piped directly into this program. look at this little handoff, obsessed π₯Ή
r.profile -g input=elevation coordinates=... | v.in.ascii output=elevation_profile separator=space
The 2 column output is compatible with most plotting programs.
The optional RGB output provides the associated GRASS colour value for each profile point. π¨
Option units enables to set units of the profile length output. If the units are not specified, current coordinate reference system's units will be used. In case of geographic CRS (latitude/longitude), meters are used as default unit. Finally, the output from r.info can be output in JSON by passing the format=json option.
π₯ NOTES π₯
The profile resolution is measured exactly from the supplied end or "turning" point along the profile. The end of a profile segment will be an exact multiple of the profile resolution and will therefore not always match the end point coordinates entered for the segmanet.
To extract the numbers in scripts, following parameters can be used:
r.profile input=dgm12.5 coordinates=3570631,5763556 2>/dev/null
This filters out everything except the numbers. chef's kiss, that 2>/dev/null is doing so much work π
β EXAMPLES β
πΈ Extraction of values along profile defined by coordinates (variant 1) πΈ
Extract a profile with coordinates (waypoints) provided on the command line (North Carolina data set):
g.region raster=elevation -p
r.profile -g input=elevation output=profile_points.csv \
coordinates=641712,226095,641546,224138,641546,222048,641049,221186
This will extract a profile along the track defined by the three coordinate pairs. The output file "profile_points.csv" contains east,north,distance,value (here: elevation). β¨
π¦ Extraction of values along profile defined by coordinates (variant 2) π¦
Coordinate pairs can also be "piped" into r.profile (variant 2a):
r.profile elevation resolution=1000 file=- << EOF
641712,226095
641546,224138
641546,222048
641049,221186
EOF
Coordinate pairs can also be "piped" into r.profile (variant 2b):
echo "641712,226095
641546,224138
641546,222048
641049,221186" > coors.txt
cat coors.txt | r.profile elevation resolution=1000 file=-
The output is printed into the terminal (unless the output parameter is used) and looks as follows:
Using resolution: 1000 [meters]
Output columns:
Along track dist. [meters], Elevation
Approx. transect length: 1964.027749 [meters]
0.000000 84.661507
1000.000000 98.179062
Approx. transect length: 2090.000000 [meters]
1964.027749 83.638138
2964.027749 89.141029
3964.027749 78.497757
Approx. transect length: 995.014070 [meters]
4054.027749 73.988029
π JSON Output π
r.profile -g input=elevation coordinates=641712,226095,641546,224138,641546,222048,641049,221186 -c format=json resolution=1000
The output looks as follows:
[
{
"easting": 641712,
"northing": 226095,
"distance": 0,
"elevation": 84.661506652832031,
"red": 113,
"green": 255,
"blue": 0
},
{
"easting": 641627.47980925441,
"northing": 225098.57823319823,
"distance": 1000.0000000000125,
"elevation": 98.179061889648438,
"red": 255,
"green": 241,
"blue": 0
},
{
"easting": 641546,
"northing": 224138,
"distance": 1964.0277492948007,
"elevation": 83.638137817382812,
"red": 100,
"green": 255,
"blue": 0
},
{
"easting": 641546,
"northing": 223138,
"distance": 2964.0277492948007,
"elevation": 89.141029357910156,
"red": 169,
"green": 255,
"blue": 0
},
{
"easting": 641546,
"northing": 222138,
"distance": 3964.0277492948007,
"elevation": 78.497756958007812,
"red": 35,
"green": 255,
"blue": 0
},
{
"easting": 641546,
"northing": 222048,
"distance": 4054.0277492948007,
"elevation": 73.988029479980469,
"red": 0,
"green": 249,
"blue": 17
}
]
π§ Using JSON output with Python for plotting data π§
The JSON output makes for ease of integration with popular python data science libraries. For instance, here is an example of creating a scatterplot of distance vs elevation with color coding.
import grass.script as gs
import pandas as pd
import matplotlib.pyplot as plt
# Run r.profile command
elevation = gs.read_command(
"r.profile",
input="elevation",
coordinates="641712,226095,641546,224138,641546,222048,641049,221186",
format="json",
flags="gc"
)
# Load the JSON data into a dataframe
df = pd.read_json(elevation)
# Convert the RGB color values to hex format for matplotlib
df["color"] = df.apply(lambda x: "#{:02x}{:02x}{:02x}".format(int(x["red"]), int(x["green"]), int(x["blue"])), axis=1)
# Create the scatter plot
plt.figure(figsize=(10, 6))
plt.scatter(df[βdistanceβ], df[βelevationβ], c=df[βcolorβ], marker=βoβ)
plt.title(βProfile of Distance vs. Elevation with Color Codingβ)
plt.xlabel(βDistance (meters)β)
plt.ylabel(βElevationβ)
plt.grid(True)
plt.show()
π SEE ALSO π
v.in.ascii, r.what, r.transect, wxGUI profile tool
π AUTHOR π
Bob Covill
π SOURCE CODE π
Available at: r.profile source code (history)
Latest change: Thursday Oct 02 14:39:13 2025 in commit: 1850489bf42c72d8dcfe2e4db1738441b4a7dc43
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
okay that's the whole page bestie, you're officially a r.profile girlie now π
this came to you from the GRASS 8.5.0 Reference Manual, Β© 2003-2026 GRASS Development Team, and yeah the footer literally just says GRASS 8.5.0 and r.profile(1grass) again β no new info, just vibes. go plot something pretty π¦β¨
π¦ 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