v.extract(1grass)

πŸ’– NAME πŸ’–

Okay so bestie, meet v.extract from the GRASS User's Manual πŸ’… β€” she selects vector features out of an existing vector map and makes you a whole new vector map that contains only the selected features. Iconic, honestly. ✨


πŸ¦‹ KEYWORDS πŸ¦‹

vector, extract, select, dissolve, random


🌈 SYNOPSIS 🌈

v.extract
v.extract --help
v.extract [-dtr] input=name  [layer=string]   [type=string[,string,...]]
[cats=range]   [where=sql_query]  output=name  [file=name]
[random=integer]   [new=integer]   [dissolve_column=name]
[--overwrite]  [--help]  [--verbose]  [--quiet]  [--ui]

🏁 Flags 🏁

  • -d β€” Dissolve common boundaries (default is no). Like, merges the shared edges, but only if you ask. πŸ™ˆ
  • -t β€” Do not copy attributes (see also ’new’ parameter). No attributes, no problem.
  • -r β€” Reverse selection. It's giving "everything EXCEPT this", and honestly? Main character energy.
  • --overwrite β€” Allow output files to overwrite existing files. Careful bestie, this one goes feral. πŸ’€
  • --help β€” Print usage summary
  • --verbose β€” Verbose module output
  • --quiet β€” Quiet module output
  • --ui β€” Force launching GUI dialog

πŸŽ€ Parameters πŸŽ€

  • input=name [required] β€” Name of input vector map. Or data source for direct OGR access.
  • layer=string β€” Layer number or name (’-1’ for all layers). A single vector map can be connected to multiple database tables. This number determines which table to use. When used with direct OGR access this is the layer name. Default: 1. One map, many tables, she contains multitudes. 🫢
  • type=string[,string,...] β€” Types to be extracted. Input feature type. Options: point, line, boundary, centroid, area, face. Default: point,line,boundary,centroid,area,face (aka literally everything, she doesn't discriminate).
  • cats=range β€” Category values. Example: 1,3,7-9,13
  • where=sql_query β€” WHERE conditions of SQL statement without ’where’ keyword. Example: income < 1000 and population >= 10000
  • output=name [required] β€” Name for output vector map
  • file=name β€” Input text file with category numbers/number ranges to be extracted. If ’-’ given reads from standard input. Stdin girlies rise up.
  • random=integer β€” Number of random categories matching vector objects to extract. Number must be smaller than unique cat count in layer. It's giving chaos, but make it bounded chaos.
  • new=integer β€” Desired new category value (enter -1 to keep original categories). If new >= 0, attributes is not copied. Default: -1
  • dissolve_column=name β€” Name of attribute column for dissolving areas. Preserves category values.

✨ DESCRIPTION ✨

v.extract lets a user select vector objects from an existing vector map and creates a new map containing only the selected objects. No cap, that's the whole job and she eats every time. πŸ”₯

Database tables can be queried with SQL statements, if a connection is established. Dissolving (optional) is based on the output categories. If 2 adjacent areas have the same output category, the boundary is removed. Poof. Gone. πŸ’«

If cats, file, random or where options are not specified, all features of given type and layer are extracted. Categories are not changed in that case. Simple as that, bestie.


πŸ“ NOTES πŸ“

Only features with a category number in the selected layer will be extracted. So if you want to extract boundaries (which are usually without category, as that information is normally held in the area’s centroid) you must first use v.category to add them, or use layer=-1.

Lowkey important: boundaries being cat-less is not a bug, it's just how the centroid-to-area relationship works. Don't come for her. πŸ™ˆ

πŸ“ EXAMPLES πŸ“

The examples are intended for the North Carolina sample dataset:

🌸 Extract areas by category number with dissolving #1:

v.extract -d cats=1,2,3,4 input=soils_wake output=soil_groupa type=area new=0

produces a new vector soil_groupa, containing those areas from vector soils which have category numbers 1 thru 4; any common boundaries are dissolved, and all areas in the new map will be assigned category number 0.

🌸 Extract areas by category number with dissolving #2:

v.extract -d cats=1-4 input=soils_wake output=soil_groupa type=area new=-1

produces a new vector map soil_groupa containing the areas from vector soils which have categories 1 thru 4. Any common boundaries are dissolved, all areas in the new map will retain their original category numbers 1 thru 4, since new was set to -1. She's preserving the lore. πŸ‘‘

🌸 Extract all areas and assign the same category to all:

v.extract input=soils_wake output=soil_groupa type=area new=1

produces a new vector map soil_groupa containing all areas from soils. No common boundaries are dissolved, all areas of the new map will be assigned category number 1. Everyone gets the same cat. Democracy. πŸ’…

🌸 Extract vectors with SQL:

v.extract input=markveggy.shp output=markveggy.1 new=13 \
  where="(VEGTYPE = ’Wi’) or (VEGTYPE = ’PS’) or (PRIME_TYPE=’Wi’)"

produces a new vector map with category number 13 if the SQL statement is fulfilled.

🌸 Extract vector features which have the given field empty:

v.extract input=lakes output=lakes_gaps where="FTYPE is NULL"

🌸 Extract vector features which have the given field not empty:

v.extract input=lakes output=lakes_ftype where="FTYPE not NULL"

🌸 Reverse extracting (behaves like selective vector objects deleting):

Remove meteorological stations from map which are located above 1000m:

# check what to delete:
v.db.select precip_30ynormals where="elev > 1000"
# perform reverse selection
v.extract -r input=precip_30ynormals output=precip_30ynormals_lowland \
  where="elev > 1000"
# verify
v.db.select precip_30ynormals_lowland

🌸 Dissolving based on column attributes:

# check column names:
v.info -c zipcodes_wake
# reclass based on desired column:
v.reclass input=zipcodes_wake output=zipcodes_wake_recl_nam column=ZIPNAME
# verify:
v.info -c zipcodes_wake_recl_nam
v.db.select zipcodes_wake_recl_nam
# dissolve:
v.extract -d input=zipcodes_wake_recl_nam output=zipcodes_wake_regions

This produces a new vector map with common boundaries dissolved where the reclassed attributes of adjacent (left/right) areas are identical.

🌸 Extract 3 random areas from geology map

v.extract input=geology output=random_geology type=area random=3

This creates a new map with three random categories matching areas. Note that there may be more than one feature with the same category.


πŸ‘€ SEE ALSO πŸ‘€

v.category, v.dissolve, v.reclass, GRASS SQL interface


🫢 AUTHORS 🫢

  • R.L. Glenn, USDA, SCS, NHQ-CGIS
  • GRASS 6 port by Radim Blazek

πŸ’œ SOURCE CODE πŸ’œ

Available at: v.extract source code (history)

Latest change: Saturday Dec 20 19:53:33 2025 in commit: 271dc5096333a5aeeb3c814b08eddb1011797fc9

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

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


and that's the whole page, bestie πŸ’… you just read v.extract(1grass) from the GRASS User's Manual, and this absolute banger is running on GRASS 8.5.0 ✨ β€” go extract something iconic, mwah πŸŽ€πŸŒˆπŸ’–

πŸ“¦ where this page comes from