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=None, verbose=None, quiet=None, superquiet=None)

Example:

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

grass.tools.Tools.db_out_ogr(input, output, layer="1", format="CSV", table=None, overwrite=None, verbose=None, quiet=None, superquiet=None)

Example:

tools = Tools()
tools.db_out_ogr(input="name", output="name", format="CSV")

This grass.tools API is experimental in version 8.5 and expected to be stable in version 8.6.

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: None
verbose : bool, optional
    Verbose module output
    Default: None
quiet : bool, optional
    Quiet module output
    Default: None
superquiet : bool, optional
    Very quiet module output
    Default: None

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: None
verbose : bool, optional
    Verbose module output
    Default: None
quiet : bool, optional
    Quiet module output
    Default: None
superquiet : bool, optional
    Very quiet module output
    Default: None

Returns:

result : grass.tools.support.ToolResult | None
If the tool produces text as standard output, a ToolResult object will be returned. Otherwise, None will be returned.

Raises:

grass.tools.ToolError: When the tool ended with an error.

DESCRIPTION

db.out.ogr exports GRASS 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 attribute table to a CSV table file (default format)

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

Export of a GRASS attribute table to a DBF table

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

Export of GRASS 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 Aug 08 09:39:19 2025 in commit ed72c71