Skip to content

v.clean.ogr

Imports vector data into a GRASS vector map, cleans the data topologically, and exports them again using OGR library.

v.clean.ogr [-luf] input=string layer=string [where=sql_query] [encoding=string] [key=string] [geometry=name] [snap=float] [min_area=float] output=name format=string [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

v.clean.ogr input=string layer=string output=name format=GPKG

grass.script.run_command("v.clean.ogr", input, layer, where=None, encoding=None, key=None, geometry=None, snap=-1, min_area=0, output, format="GPKG", flags=None, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("v.clean.ogr", input="string", layer="string", output="name", format="GPKG")

Parameters

input=string [required]
    Name of OGR datasource to be imported
    Example: directory containing shapefiles
layer=string [required]
    OGR layer name.
    Examples: shapefile name without .shp
where=sql_query
    WHERE conditions of SQL statement without 'where' keyword
    Example: income < 1000 and population >= 10000
encoding=string
    Encoding value for attribute data
    Overrides encoding interpretation, useful when importing ESRI Shapefile
key=string
    Name of column used for categories
    If not given, categories are generated as unique values and stored in 'cat' column
geometry=name
    Name of geometry column
    If not given, all geometry columns from the input are used
snap=float
    Snapping threshold for boundaries (map units)
    '-1' for no snap
    Default: -1
min_area=float
    Minimum size of areas to be retained in output (square meters)
    Disabled with values <= 0
    Default: 0
output=name [required]
    Name of output OGR datasource
    Examples: filename for a GeoPackage, directory for shapefiles
format=string [required]
    Data format to write
    Default: GPKG
-l
    List available OGR layers in data source and exit
-u
    Open an existing output OGR datasource for update
-f
    List supported output formats and exit
--overwrite
    Allow output files to overwrite existing files
--help
    Print usage summary
--verbose
    Verbose module output
--quiet
    Quiet module output
--qq
    Very quiet module output
--ui
    Force launching GUI dialog

input : str, required
    Name of OGR datasource to be imported
    Example: directory containing shapefiles
    Used as: input, datasource
layer : str, required
    OGR layer name.
    Examples: shapefile name without .shp
    Used as: input, datasource_layer
where : str, optional
    WHERE conditions of SQL statement without 'where' keyword
    Example: income < 1000 and population >= 10000
    Used as: input, sql_query, sql_query
encoding : str, optional
    Encoding value for attribute data
    Overrides encoding interpretation, useful when importing ESRI Shapefile
key : str, optional
    Name of column used for categories
    If not given, categories are generated as unique values and stored in 'cat' column
geometry : str, optional
    Name of geometry column
    If not given, all geometry columns from the input are used
    Used as: input, dbcolumn, name
snap : float, optional
    Snapping threshold for boundaries (map units)
    '-1' for no snap
    Default: -1
min_area : float, optional
    Minimum size of areas to be retained in output (square meters)
    Disabled with values <= 0
    Default: 0
output : str, required
    Name of output OGR datasource
    Examples: filename for a GeoPackage, directory for shapefiles
    Used as: output, file, name
format : str, required
    Data format to write
    Default: GPKG
flags : str, optional
    Allowed values: l, u, f
    l
        List available OGR layers in data source and exit
    u
        Open an existing output OGR datasource for update
    f
        List supported output formats and exit
overwrite: bool, optional
    Allow output files to overwrite existing files
    Default: False
verbose: bool, optional
    Verbose module output
    Default: False
quiet: bool, optional
    Quiet module output
    Default: False
superquiet: bool, optional
    Very quiet module output
    Default: False

DESCRIPTION

v.clean.ogr cleans non-topological polygons in an OGR datasource by importing, cleaning, and exporting these polgons. This module should not be used with polygons that are correctly overlapping, e.g. buffers.

v.clean.ogr imports vector data from files and database connections supported by the OGR library into a temporary location. Only one input layer is imported.

Polygons in the input layer are automatically cleaned during impport. More thorough cleaning can be achieved by using the snap and min_area options.

The cleaned result is exported to the selected output datasource with "_clean" appended to the input layer name. Any overlaps are exported with "_overlaps" appended to the input layer name.

Supported Vector Formats

v.clean.ogr uses the OGR library which supports various vector data formats including GeoPackage, ESRI Shapefile, Mapinfo File, UK .NTF, SDTS, TIGER, IHO S-57 (ENC), DGN, GML, GPX, AVCBin, REC, Memory, OGDI, and PostgreSQL, depending on the local OGR installation. For details see the OGR web site. The OGR (Simple Features Library) is part of the GDAL library, hence GDAL needs to be installed to use v.clean.ogr.

The list of actually supported formats can be printed by -f flag.

NOTES

Topology cleaning

When importing polygons, non-topological polygons are converted to topological areas. If the input polygons contain errors (unexpected overlapping areas, small gaps between polygons, or warnings about being unable to calculate centroids), the import might need to be repeated using a snap value as suggested in the output messages.

The snap threshold defines the maximal distance from one to another vertex in map units (for latitude-longitude locations in degree). If there is no other vertex within snap distance, no snapping will be done. Note that a too large value can severely damage area topology, beyond repair.

Further cleaning can be achieved by removing small areas using the min_area option. Note that units are always squaremeters. Values for min_area should generally be small, a value of 0.5 can already clean up lots of artefacts.

EXAMPLE

Cleaning polygons in a Shapefile in the current directory research_area

v.clean.ogr input=research_area layer=research_area output=research_area \
            snap=1e-4 min_area=1 -u --overwrite

Two new Shapefile layers "research_area_clean" and "research_area_overlaps" may be created in the same directory.

SEE ALSO

v.in.ogr, v.clean, v.out.ogr

AUTHOR

Markus Metz

SOURCE CODE

Available at: v.clean.ogr source code (history)
Latest change: Thursday Feb 20 13:02:26 2025 in commit 53de819