Skip to content

db.out.ogr

Exports attribute tables into various formats.

db.out.ogr input=name output=name [layer=string] format=string [table=name] [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

db.out.ogr input=name output=name format=CSV

grass.script.run_command("db.out.ogr", input, output, layer="1", format="CSV", table=None, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("db.out.ogr", input="name", output="name", format="CSV")

Parameters

input=name [required]
    GRASS table name
    Or data source for direct OGR access
output=name [required]
    Output table file name or DB connection string
layer=string
    Layer number or name
    Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
    Default: 1
format=string [required]
    Table format
    Allowed values: CSV, DBF, GML, MySQL, PostgreSQL, SQLite
    Default: CSV
table=name
    Name for output table (default: input name)
--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
    GRASS table name
    Or data source for direct OGR access
    Used as: input, vector, name
output : str, required
    Output table file name or DB connection string
    Used as: output, file, name
layer : str, optional
    Layer number or name
    Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
    Used as: input, layer
    Default: 1
format : str, required
    Table format
    Allowed values: CSV, DBF, GML, MySQL, PostgreSQL, SQLite
    Default: CSV
table : str, optional
    Name for output table (default: input name)
    Used as: name
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

db.out.ogr exports GRASS GIS attribute tables into various formats as supported by the OGR driver on the local system (CSV, DBF, PostgreSQL, SQLite, MySQL, ODBC, etc.).

The output parameter is used to define the output file name (if the path is not defined, the module will attempt to write to the current directory). In case of a database connection as output, the connection string has to be specified.

The layer parameter is needed if the attribute table to be exported is linked as non-default layer to a vector map.

EXAMPLES

Export of GRASS GIS attribute table to a CSV table file (default format)

db.out.ogr input=precip_30ynormals output=precip_30ynormals.csv

Export of a GRASS GIS attribute table to a DBF table

db.out.ogr input=precip_30ynormals output=precip_30ynormals.dbf format=DBF

Export of GRASS GIS attribute table into a PostgreSQL table

db.out.ogr input=precip_30ynormals \
           output="PG:host=localhost dbname=meteo user=neteler" \
           format=PostgreSQL
# verify
echo "SELECT * FROM precip_30ynormals" | psql meteo

SEE ALSO

db.tables

GRASS SQL interface

AUTHORS

Markus Neteler
Converted to Python by Glynn Clements

SOURCE CODE

Available at: db.out.ogr source code (history)
Latest change: Friday Feb 07 19:16:09 2025 in commit a82a39f