v.in.ogr(1grass)
π¦ v.in.ogr β straight from the GRASS User's Manual (v.in.ogr(1grass)) π¦
okay bestie, sit down, hydrate, because this one is a whole journey and I am obsessed with it π
β¨ NAME β¨
v.in.ogr β imports vector data into a GRASS vector map using the OGR library. that's it, that's the whole personality. π
π·οΈ KEYWORDS π·οΈ
vector, import, OGR, topology, geometry, snapping, create project β iykyk π
π SYNOPSIS π
v.in.ogr
v.in.ogr --help
v.in.ogr [-flc2tojrewi] input=string [gdal_config=string]
[gdal_doo=string] [layer=string[,string,...]] [output=name]
[spatial=xmin,ymin,xmax,ymax[,xmin,ymin,xmax,ymax,...]]
[where=sql_query] [min_area=float] [type=string[,string,...]]
[snap=float] [project=name] [columns=name[,name,...]]
[encoding=string] [key=string] [geometry=name] [--overwrite]
[--help] [--verbose] [--quiet] [--ui]
π© Flags π©
-fβ list every OGR format your system supports and dip out. slay, that's it, that's the run π-lβ list the available OGR layers in the data source and exit. peek before you leap π-cβ do not clean polygons. the manpage literally says (not recommended) so likeβ¦ proceed with caution bestie π-2β force 2D output even if the input is 3D. genuinely useful when the input is 3D but every single z coordinate is identical. we love a flattening moment β¨-tβ do not create an attribute table. no table, no drama π-oβ override the projection check and just use the current project's CRS. this assumes the dataset has the same coordinate reference system (CRS) as the current project π«Ά-jβ do the projection check and only the projection check, then exit. vibe check, no import π-rβ limit the import to the current region πΈ-eβ extend the region extents based on the new dataset. also updates the default region if you're in thePERMANENTmapset π-wβ change column names to lowercase characters. lowercase era fr fr π¦-iβ create the project specified by theprojectparameter and exit. does not import the vector data. construction only, no housewarming π--overwriteβ allow output files to overwrite existing files π--helpβ print usage summary--verboseβ verbose module output--quietβ quiet module output--uiβ force launching the GUI dialog π
π Parameters π
input=string[required] β name of the OGR datasource to be imported. Examples:- ESRI Shapefile: directory containing shapefiles
- MapInfo File: directory containing mapinfo files
gdal_config=stringβ GDAL configuration options. comma-separated list ofkey=valuepairs βgdal_doo=stringβ GDAL dataset open options. comma-separated list ofkey=valuepairs βlayer=string[,string,...]β OGR layer name. if you don't give it, all available layers get imported. Examples:- ESRI Shapefile: shapefile name
- MapInfo File: mapinfo file name
output=nameβ name for the output vector map πspatial=xmin,ymin,xmax,ymax[,xmin,ymin,xmax,ymax,...]β import a subregion only. Format:xmin,ymin,xmax,ymaxβ usually W,S,E,N πΈwhere=sql_queryβ WHERE conditions of an SQL statement, nowherekeyword needed. Example:income < 1000 and population >= 10000π§min_area=floatβ minimum size of area to be imported (square meters). smaller areas and islands are ignored. should be greater thansnap^2. Default:0.0001πtype=string[,string,...]β optionally change the default input type. Options:point,line,boundary,centroidDefault:point: import area centroids as pointsline: import area boundaries as linesboundary: import lines as area boundariescentroid: import points as centroids
snap=floatβ snapping threshold for boundaries (map units).'-1'for no snap. Default:-1π―project=nameβ name for the new project (location) to create ποΈcolumns=name[,name,...]β list of column names to use instead of the original names. the first one gets used for the category column πencoding=stringβ encoding value for attribute data. overrides the encoding interpretation β super handy when importing an ESRI Shapefile πkey=stringβ name of the column used for categories. if you don't give one, categories get generated as unique values and stashed in thecatcolumn πgeometry=nameβ name of the geometry column. if you don't give one, all geometry columns from the input are used π¦
π DESCRIPTION π
v.in.ogr imports vector data from files and database connections supported by the OGR library) into the current project (previously called location) and mapset. yes there's a stray parenthesis in the original, we're keeping it, no cap π
if the layer parameter isn't given, all available OGR layers get imported as separate GRASS layers into one GRASS vector map. and if you hand it several OGR layer names, all of those layers get imported as separate GRASS layers into one GRASS vector map too. same energy, different layer count β¨
the optional spatial parameter defines the spatial query extents. it lets you restrict the region to a spatial subset while importing. every vector feature that falls completely or partially inside that rectangle subregion gets imported. the -r current region flag is identical, except it uses the current region settings as the spatial bounds (go peek at g.region) πΈ
π Supported Vector Formats π
v.in.ogr uses the OGR library, which supports a whole menu of vector data formats, including ESRI Shapefile, Mapinfo File, UK .NTF, SDTS, TIGER, IHO S-57 (ENC), DGN, GML, GPX, AVCBin, REC, Memory, OGDI, and PostgreSQL β all depending on your local OGR installation. for the details, go look at the OGR format overview. the -f flag prints a list of the vector formats your system's OGR (Simple Features Library) supports. the OGR (Simple Features Library) is part of the GDAL library, so GDAL needs to be installed to use v.in.ogr β no GDAL, no party π
the list of actually supported formats can be printed with the -f flag. periodt π
π§Ή Topology cleaning π§Ή
topology cleaning on areas happens automatically, but bestieβ¦ it can fail in special cases. when that happens, a snap threshold value gets estimated from the imported vector data and printed out at the end. then you can import the vector data again with that suggested snap threshold value, which gets incremented by powers of 10 β and you keep going until either an estimated upper limit for the threshold value is reached, or the topology cleaning on areas actually succeeds. sometimes manual cleaning is required, or the areas are truly overlapping, e.g. buffers created with non-topological software π«
the min_area threshold value is specified as area size in map units, except for latitude-longitude projects, where it's specified solely in square meters π
the snap threshold value is used to snap boundary vertices to each other when the distance in map units between two vertices is not larger than the threshold. snapping is disabled by default, with -1. see also the v.clean manual π§Ό
π« Overlapping polygons π«
when you import overlapping polygons, those overlapping parts become new areas with multiple categories β one unique category for each original polygon. so an original polygon gets converted into multiple areas that all share the same category. those multiple areas will therefore also link to the same entry in the attribute table π
a single category value can thus refer to multiple non-overlapping areas which together represent the original polygon overlapping with another polygon. and you can recover the original polygon by using v.extract with the desired category value, or a where statement, plus the -d flag to dissolve common boundaries. iconic recovery arc π
ποΈ Project Creation ποΈ
v.in.ogr attempts to preserve coordinate reference system (CRS) information when importing datasets β that's if the source format includes such information, and if the OGR driver supports it. if the CRS of the source dataset does not match the CRS of the current project, v.in.ogr will report an error message:
"Coordinate reference system of dataset does not appear to match current project"
if you wish to ignore the difference between the coordinate system of the source data and the current project, you may pass the -o flag to override the CRS check. live your truth π
if you wish to import the data with the full CRS definition, v.in.ogr can automatically create a new project based on the CRS and extents of the file being read. you do this by passing the name to be used for the new project via the project parameter. once the command finishes, a new project will have been created (with only a PERMANENT mapset), and the vector map will have been imported with the indicated output name into the PERMANENT mapset. brand new project, brand new era β¨
an interesting wrapper command around v.in.ogr is v.import, which reprojects (if needed) the vector dataset during import to the CRS of the current project π
β¨ NOTES β¨
okay besties this is the part where we get into the actual deets π
π Table column names: supported characters π
so like, the characters that are allowed in table column names? they're limited by the SQL standard, no cap. what's supported is literally:
[A-Za-z][A-Za-z0-9_]*
which means SQL does NOT support . (dots), - (minus), or # (hash) in table column names π
ββοΈ also a table name has to start with a character, not a number. periodt.
v.in.ogr converts ., - and # to _ (underscore) during import. the -w flag changes capital column names to lowercase characters as a convenience for SQL usage (lowercase column names mean you don't have to quote them if the attribute table lives in a SQL DBMS like PostgreSQL). the columns parameter is what you use to define new column names during import.
the DBF database specification limits column names to 10 characters. so if the default DB is set to DBF and your input data has longer column/field names, they will get truncated π and if that truncation results in multiple columns with the same name, then v.in.ogr will produce an error. in that case you either have to modify the input data or use v.in.ogr's columns parameter to rename columns to something unique. (hint: copy and modify the list given with the error message π«Ά). alternatively, change the local DB with db.connect.
π¦ File encoding π¦
when importing ESRI Shapefiles the OGR library tries to read the LDID/codepage setting from the .dbf file and use it to translate string fields to UTF-8. LDID "87 / 0x57" is treated as ISO8859_1, which lowkey may not be appropriate for many languages π unfortunately it's not clear what other values may be appropriate (see example below). to change encoding the user can set up the SHAPE_ENCODING environmental variable or simply define the encoding value using the encoding parameter.
the value for encoding also affects text recoding when importing DXF files. for other formats the encoding value has no effect.
π§ Defining the key column π§
the key option specifies the column name used for feature categories. this column must be integer. if not specified, categories numbers are generated starting with 1 and stored in the column named "cat".
π Supports of multiple geometry columns π
starting with GDAL 1.11 the library supports multiple geometry columns in OGR. by default v.in.ogr reads all geometry columns from the given layer. the user can choose the desired geometry column with the geometry option, see example below π
β Latitude-longitude data: Vector postprocessing after import β
for vector data like a grid, horizontal lines need to be broken at their intersections with vertical lines (v.clean ... tool=break).
π EXAMPLES π
the command imports various vector formats, okay let's GO:
πΈ SHAPE files πΈ
v.in.ogr input=/home/user/shape_data/test_shape.shp output=grass_map
alternate method:
v.in.ogr input=/home/user/shape_data layer=test_shape output=grass_map
define encoding value for attribute data (in this example we expect attribute data in Windows-1250 encoding; ie. in Central/Eastern European languages that use Latin script, Microsoft Windows encoding).
v.in.ogr input=/home/user/shape_data/test_shape.shp output=grass_map encoding=cp1250
π MapInfo files π
v.in.ogr input=./ layer=mapinfo_test output=grass_map
π¦ Arc Coverage π¦
we import the Arcs and Label points, and the module takes care to build areas π«Ά
v.in.ogr input=gemeinden layer=LAB,ARC type=centroid,boundary output=mymap
π E00 file π
see also v.in.e00.
first we have to convert the E00 file to an Arc Coverage with 'avcimport' (AVCE00 tools, use e00conv first in case that avcimport fails):
avcimport e00file coverage
v.in.ogr input=coverage layer=LAB,ARC type=centroid,boundary output=mymap
β¨ SDTS files β¨
you have to select the CATD file.
v.in.ogr input=CITXCATD.DDF output=cities
π― TIGER files π―
v.in.ogr input=input/2000/56015/ layer=CompleteChain,PIP output=t56015_all \
type=boundary,centroid snap=-1
πΊοΈ PostGIS tables πΊοΈ
import polygons as areas:
v.in.ogr input="PG:host=localhost dbname=postgis user=postgres" layer=polymap \
output=polygons type=boundary,centroid
if the table containing the polygons are in a specific schema, you can use:
v.in.ogr input="PG:host=localhost dbname=postgis user=postgres" \
layer=myschema.polymap \
output=polygons type=boundary,centroid
generally, v.in.ogr just follows the format-specific syntax defined by the OGR library π
π OpenStreetMap (OSM) π
OSM data are available in .osm (XML based) and .pbf (optimized binary) formats. the .pbf format is recommended because file sizes are smaller. the OSM driver will categorize features into 5 layers:
points:"node"features that have significant tags attached.lines:"way"features that are recognized as non-area.multilinestrings:"relation"features that form a multilinestring (type = 'multilinestring'ortype = 'route').multipolygons:"relation"features that form a multipolygon (type = 'multipolygon'ortype = 'boundary'), and"way"features that are recognized as area.other_relations:"relation"features that do not belong to any of the above layers.
it is recommended to import one layer at a time, and to select features with the where option, e.g. to import roads, use
v.in.ogr where="highway >< ''"
i.e. the OSM tag highway must be set.
when importing administrative boundaries from OSM, it is important to not only select administrative boundaries, but also the admin level to be imported (valid range is 1 - 11), e.g. with
v.in.ogr where="boundary = 'administrative' and admin_level = '1'"
the OSM topological model differs from the GRASS topological model π OSM topologically correct connections of lines can be on all vertices of a line. during import, lines are automatically split at those vertices where an OSM connection to another line exists.
import of OSM data requires a configuration file, defined with the OSM_CONFIG_FILE configuration option. in the data folder of the GDAL distribution, you can find a osmconf.ini file that can be customized to fit your needs. see OSM map features for keys and their values. you should set "other_tags=no" to avoid problems with import or querying the imported vector. once a OSM_CONFIG_FILE has been created, OSM data can be imported with e.g.
export OSM_CONFIG_FILE=/path/to/osmconf.ini
v.in.ogr input=name.pbf layer=lines output=osm_data
π₯ Oracle Spatial π₯
note that you have to set the environment-variables ORACLE_BASE, ORACLE_SID, ORACLE_HOME and TNS_ADMIN accordingly.
v.in.ogr input=OCI:username/password@database_instance output=grasslayer layer=roads_oci
π Multiple geometry columns π
this example shows how to work with data which contain multiple geometry per feature. the number of geometry columns per feature can be checked by v.external together with -t flag.
v.external -t input=20141130_ST_UKSH.xml.gz
...
Okresy,point,1,DefinicniBod
Okresy,multipolygon,1,OriginalniHranice
Okresy,multipolygon,1,GeneralizovaneHranice
...
in our example layer "Okresy" has three geometry columns: "DefinicniBod", "OriginalniHranice" and "GeneralizovanaHranice". by default v.in.ogr reads data from all three geometry columns. the user can specify the desired geometry column by geometry option, in this case the module will read geometry only from the specified geometry column. in the example below, the output vector map will contain only geometry saved in "OriginalniHranice" geometry column.
v.in.ogr input=20141130_ST_UKSH.xml.gz layer=Okresy geometry=OriginalniHranice
β οΈ WARNINGS β οΈ
if a message like
WARNING: Area size 1.3e-06, area not imported
appears, the min_area may be adjusted to a smaller value so that all areas are imported. otherwise tiny areas are filtered out during import (useful to polish digitization errors or non-topological data).
if a message like
Try to import again, snapping with at least 1e-008: 'snap=1e-008'
appears, then the map to be imported contains topological errors π the message suggests a value for the snap parameter to be tried. for more details, see above in Topology Cleaning.
π ERROR MESSAGES π
π SQL syntax errors π
depending on the currently selected SQL driver, error messages such as follows may arise:
DBMI-SQLite driver error:
Error in sqlite3_prepare():
near "ORDER": syntax error
or:
DBMI-DBF driver error:
SQL parser error:
syntax error, unexpected DESC, expecting NAME processing 'DESC
this indicates that a column name in the input dataset corresponds to a reserved SQL word (here: 'ORDER' and 'DESC' respectively). a different column name has to be used in this case. the columns parameter can be used to assign different column names on the fly in order to avoid using reserved SQL words. for a list of SQL reserved words for SQLite (the default driver), see here.
π Projection errors π
Coordinate reference system of dataset does not appear to match the current project.
here you need to create or use a project whose CRS matches that of the vector data you wish to import. try using project parameter to create a new project based upon the CRS information in the file. if desired, you can then reproject it to another project with v.proj.
π«Ά REFERENCES π«Ά
- OGR vector library
- OGR vector library C API documentation
π SEE ALSO π
db.connect, v.clean, v.extract, v.build.polylines, v.edit, v.external, v.import, v.in.db, v.in.e00, v.out.ogr
GRASS Wiki page: Import of Global datasets
π AUTHORS π
original author: Radim Blazek, ITC-irst, Trento, Italy location and spatial extent support by Markus Neteler and Paul Kelly various improvements by Markus Metz multiple geometry columns support by Martin Landa, OSGeoREL, Czech Technical University in Prague, Czech Republic
π SOURCE CODE π
available at: v.in.ogr source code (history)
latest change: Friday Jan 02 21:25:59 2026 in commit: 83362df5af36c1e7d95fad93dff0a57b4dfde476
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 a wrap bestie π this whole thing is GRASS 8.5.0 and it's the v.in.ogr(1grass) page β go import something cute, ilysm, 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