v.segment(1grass)

πŸ’– v.segment β€” the GRASS User's Manual glow-up πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about v.segment from the GRASS User's Manual and it's genuinely so useful?? This little icon builds points and segments out of vector lines + positions, and honestly it ate.


✨ NAME ✨

v.segment β€” creates points/segments from input vector lines and positions. that's it, that's the whole job, and she does it flawlessly πŸ’…


🏷️ KEYWORDS 🏷️

vector, geometry, node, point, segment, vertex


🌈 SYNOPSIS 🌈

v.segment
v.segment --help
v.segment input=name  [layer=string]  output=name  [rules=name]
[--overwrite]  [--help]  [--verbose]  [--quiet]  [--ui]

πŸŽ€ Flags πŸŽ€

  • --overwrite β€” lets your output files just. overwrite existing files. no hesitation, no warning, main character behaviour.
  • --help β€” prints the usage summary, aka the little recap before the episode
  • --verbose β€” verbose module output, she's telling you EVERYTHING
  • --quiet β€” quiet module output, she's giving mysterious and silent πŸ¦‹
  • --ui β€” force launches the GUI dialog, for when you want the pretty clicky version

🌸 Parameters 🌸

  • input=name [required] β€” name of the input vector lines map. Or, if you're feeling adventurous, 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 determines which layer to use. When you're doing direct OGR access, this is the layer name instead. Default: 1
  • output=name [required] β€” name for the output vector map. your baby, your legacy πŸ‘‘
  • rules=name β€” name of the file containing the segment rules. Use '-' for standard input. (yes, a literal '-', she knows what she's doing)

πŸ’œ DESCRIPTION πŸ’œ

So v.segment generates segments or points from input lines, using positions it reads from a text file or from 'stdin'. It also does the cute bonus thing where it creates parallel lines or points in a given destination derived from the line. obsessed.

The format is:

P <point id>   <line cat> <offset> [<side offset>]
L <segment id> <line cat> <start offset> <end offset> [<side offset>]

The offsets can be percent values of the line length. And if the offsets are negative, they start from the end node of the line instead. Oh and -0 means the end of the line. not zero, not nothing β€” the END. iykyk.

The user could send to stdin something like:

P 1 356 24.56
P 2 495 12.31
P 3 500 -12.31
P 4 510 -20%
...

(pipe or redirect from file into the command, bestie 🫢)


πŸ¦‹ NOTES πŸ¦‹

A segment is only created for the first line found of the specified category. literally the first one. don't @ me.

Points are generated along the lines at the given distance(s) or percent(s) of the line length from the beginning β€” or from the end, if the offsets are negative β€” of the vector line.

The side offset is the orthogonal distance from the line. Positive side offsets go to the right side of the line going forward, negative ones go to the left (shoutout to d.vect with display=shape,dir, which shows you the direction of vector lines, thank you queen). And here's the thing: since the segment distance is measured along the original line, side-offset lines will be longer than the start-end segment distance for outside corners of curving lines, and shorter for inside corners. geometry is shady like that 😭

All offsets are measured in map units (peep "g.proj -p") or percents of the line length, if followed by a % character.

Wanna place a point in the middle of a line? Use a 50% offset, OR use the v.to.db module to find the line's length, then use half of that distance as the along-line offset. two paths, both slay.


🌟 EXAMPLES 🌟

These examples are based on the North Carolina sample dataset. iconic dataset, no notes.

Extraction of a line segment

Extract line segment from 400m to 5000m from beginning of line 1:

# extract lines from railroad map:
v.extract input=railroads output=myrr cats=1
# join segments into polyline and reassign category numbers
v.build.polylines myrr out=myrr_pol
v.category input=myrr_pol output=myrailroads option=add
# zoom to an area of interest
g.region vector=myrailroads -p
# show line, category, direction (to find the beginning)
d.mon wx0
d.vect map=myrailroads display=shape,cat,dir lsize=12
# extract line segment from 400m to 5000m from beginning of line 1
echo "L 1 1 400 5000" | v.segment input=myrailroads output=myrailroads_segl
d.erase
d.vect map=myrailroads
d.vect map=myrailroads_segl col=green width=2
# set node at 5000m from beginning of line 1
echo "P 1 1 5000" | v.segment input=myrailroads output=myrailroads_segp
d.vect map=myrailroads_segp icon=basic/circle color=red fcolor=red size=5

Extract line segment from 400m to 5000m from beginning of line 1

Parallel line segments

Creation of parallel, 1km long line segments along the first 8km of track, offset 500m to the left of the tracks:

v.segment input=myrailroads output=myrailroads_segl_side << EOF
L 1 1 1000 2000 -500
L 2 1 3000 4000 -500
L 3 1 5000 6000 -500
L 4 1 7000 8000 -500
EOF
d.erase
d.vect map=myrailroads display=shape,dir
d.vect -c map=myrailroads_segl_side width=2

Points equidistant along the tracks

Creation of a series of points, spaced every 2km along the tracks:

v.segment input=myrailroads output=myrailroads_pt2km << EOF
P 1 1 1000
P 2 1 3000
P 3 1 5000
P 4 1 7000
EOF
d.erase
d.vect map=myrailroads display=shape,dir
d.vect map=myrailroads_pt2km icon=basic/circle color=blue fcolor=blue size=5

A series of points, spaced every 2km along the tracks

Points equidistant along and offset the tracks

Creation of a series of points, spaced every 2km along the tracks, offset 500m to the right:

v.segment input=myrailroads output=myrailroads_pt2kmO500m << EOF
P 1 1 1000 500
P 2 1 3000 500
P 3 1 5000 500
P 4 1 7000 500
EOF
d.erase
d.vect map=myrailroads display=shape,dir
d.vect map=myrailroads_pt2kmO500m icon=basic/circle color=aqua fcolor=aqua size=5

A series of points, spaced every 2km along the tracks, offset 500m to the right

Points equidistant in percent along and offset the tracks

Creation of a series of points, spaced every 10% of the line's length along the tracks from the end of the line up to the middle point, offset 500m to the right:

v.segment input=myrailroads output=myrailroads_pt10pctO500m << EOF
P 1 1  -0% 500
P 2 1 -10% 500
P 3 1 -20% 500
P 4 1 -30% 500
P 5 1 -40% 500
P 6 1 -50% 500
EOF
d.erase
d.vect map=myrailroads display=shape,dir
d.vect map=myrailroads_pt10pctO500m icon=basic/circle color=red fcolor=black size=5

A series of points, spaced every 10% of the line's length along the tracks from the end of the line up to the middle point, offset 500m to the right


πŸ’€ KNOWN ISSUES πŸ’€

There is a problem with side-offset parallel line generation for inside corners. she's aware, she's working on it, we don't bully her πŸ™ˆ


πŸ‘€ SEE ALSO πŸ‘€

  • LRS tutorial (Linear Referencing System)
  • d.vect
  • v.build.polylines
  • v.lrs.segment
  • v.parallel
  • v.split
  • v.to.db
  • v.to.points

🫢 AUTHOR 🫢

Radim Blazek, ITC-Irst, Trento, Italy


πŸ”₯ SOURCE CODE πŸ”₯

Available at: v.segment source code (history)

Latest change: Thursday Sep 25 10:12:29 2025 in commit: 0833f2b40bea56ce019bc509f9feb4a9a3dc9f03

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

Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual


okay that's the whole page bestie πŸ’– that was GRASS 8.5.0 energy, the v.segment(1grass) page, latest change Thursday Sep 25 10:12:29 2025 β€” go build some segments, you absolute icon πŸ‘‘βœ¨πŸŒΈ

πŸ“¦ where this page comes from