Skip to content

db.in.ogr

Imports attribute tables in various formats.

db.in.ogr input=name [gdal_config=string] [gdal_doo=string] [db_table=name] [output=name] [key=string] [encoding=string] [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

db.in.ogr input=name

grass.script.run_command("db.in.ogr", input, gdal_config=None, gdal_doo=None, db_table=None, output=None, key=None, encoding=None, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("db.in.ogr", input="name")

Parameters

input=name [required]
    Table file to be imported or DB connection string
gdal_config=string
    GDAL configuration options
    Comma-separated list of key=value pairs
gdal_doo=string
    GDAL dataset open options
    Comma-separated list of key=value pairs
db_table=name
    Name of table from given DB to be imported
output=name
    Name for output table
key=string
    Name for auto-generated unique key column
encoding=string
    Encoding value for attribute data
--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
    Table file to be imported or DB connection string
    Used as: input, file, name
gdal_config : str, optional
    GDAL configuration options
    Comma-separated list of key=value pairs
gdal_doo : str, optional
    GDAL dataset open options
    Comma-separated list of key=value pairs
db_table : str, optional
    Name of table from given DB to be imported
    Used as: name
output : str, optional
    Name for output table
    Used as: output, dbtable, name
key : str, optional
    Name for auto-generated unique key column
encoding : str, optional
    Encoding value for attribute data
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.in.ogr imports attribute tables in various formats as supported by the OGR library on the local system (DBF, CSV, PostgreSQL, SQLite, MySQL, ODBC, etc.). Optionally a unique key (ID) column can be added to the table.

EXAMPLES

Import CSV file

Limited type recognition can be done for Integer, Real, String, Date, Time and DateTime columns through a descriptive file with same name as the CSV file, but .csvt extension (see details about the .csvt extension).

# NOTE: create koeppen_gridcode.csvt first for automated type recognition
db.in.ogr input=koeppen_gridcode.csv output=koeppen_gridcode gdal_doo="AUTODETECT_TYPE=YES"
db.describe koeppen_gridcode -c
db.select table=koeppen_gridcode

Import DBF table

Import of a DBF table with additional unique key column (e.g., needed for v.in.db).

db.in.ogr input=/path/to/mydata.dbf output=census_raleigh key=myid
db.describe -c census_raleigh

Import of a SQLite table

db.in.ogr input=/path/to/sqlite.db db_table=census_raleigh output=census_raleigh

Import of a PostgreSQL table

# HINT: if the database contains spatial tables, but you want to import a non-spatial
table, set the environmental variable PG_LIST_ALL_TABLES to YES before importing

db.in.ogr input="PG:host=localhost dbname=ecad user=neteler" \
          db_table=ecad_verona_tmean output=ecad_verona_tmean
db.select table=ecad_verona_tmean
db.describe -c ecad_verona_tmean

Import XLS file

To force reading headers, define environmental variable OGR_XLS_HEADERS='FORCE'. Parameter db_table refers to the list within XLS file.

export OGR_XLS_HEADERS='FORCE'
db.in.ogr input=address.xls db_table=address_data

SEE ALSO

db.select, v.in.ogr, v.in.db

GRASS SQL interface

AUTHOR

Markus Neteler

SOURCE CODE

Available at: db.in.ogr source code (history)
Latest change: Tuesday May 20 22:51:55 2025 in commit 6f8ee15