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.
The lines parameter takes a vector map and profiles each of its
lines separately, with the vertices of a line as its turning points.
Every profile starts at distance zero and the category of the line is
added as the first output column (cat in CSV and JSON output),
so that the profiles can be told apart. Lines can be selected by category
with cats or by attributes with where, both referring to
layer. Points, centroids and boundaries in the vector map are ignored.
A feature made of several lines, such as a road split at junctions, gives
one profile per line; join the lines first with v.build.polylines
to get a single continuous profile.
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.
r.profile -g input=elevation coordinates=... | v.in.ascii output=elevation_profile separator=space
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.
To extract the numbers in scripts, following parameters can be used:
r.profile input=dgm12.5 coordinates=3570631,5763556 2>/dev/null
g.region raster=elevation -p
r.profile -g input=elevation output=profile_points.csv \
coordinates=641712,226095,641546,224138,641546,222048,641049,221186
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=-
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
g.region raster=elevation -p r.profile input=elevation lines=roads cats=21903 resolution=100 format=csv
cat,distance,value 21903,0.000000,89.999725 21903,16.519123,89.482239 21903,27.771102,88.642357 ... 21903,790.810589,109.396729 21903,890.810589,110.812485 21903,906.702315,111.440796 ...
v.extract input=roads cats=21903 output=road v.transects input=road output=transects transect_spacing=500 dleft=100 dright=100 r.profile input=elevation lines=transects resolution=20 format=csv
cat,distance,value 1,0.000000,97.808243 1,20.000000,97.098083 1,40.000000,96.140938 ... 4,180.000000,123.778564 4,200.000000,124.010223
r.profile -g input=elevation coordinates=641712,226095,641546,224138,641546,222048,641049,221186 -c format=json resolution=1000
[
{
"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
}
]
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()
Available at: r.profile source code (history)
Latest change: Tuesday Nov 03 23:27:01 2026 in commit: 1efc42be2bfef669c1afc2407cbeaee1250fb6c3
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
© 2003-2026 GRASS Development Team, GRASS 8.6.0dev Reference Manual