ogr2ogr
Convert geospatial data between formats
TLDR
Convert a Shapefile into a GeoPackage
Reduce a GeoJSON to features matching a condition
Change coordinate reference system of a GeoPackage from EPSG:4326 to EPSG:3857
Convert a CSV file into a GeoPackage, specifying the names of the coordinate columns and assigning a coordinate reference system
Load a GeoPackage into a PostGIS database
Clip layers of a GeoPackage file to the given bounding box
SYNOPSIS
ogr2ogr [options] output_datasource input_datasource [layers...]
PARAMETERS
-f format_name
Output file format name (e.g., 'ESRI Shapefile', 'GeoJSON', 'PostgreSQL').
-s_srs srs_def
Source spatial reference system (SRS) definition (e.g., 'EPSG:4326', 'WGS84').
-t_srs srs_def
Target spatial reference system (SRS) definition.
-overwrite
Delete the output datasource and recreate it if it already exists.
-append
Append to an existing layer instead of creating a new one.
-update
Open existing output datasource in update mode. Can be combined with -append.
-sql sql_statement
Execute an SQL statement against the input datasource to select features.
-where expression
Attribute query to select features from the input layer.
-select field1,field2,...
Comma-separated list of fields to copy from the input layer.
-nln new_layer_name
Assign a new name to the output layer.
-nlt geometry_type
Define the output geometry type (e.g., 'PROMOTE_TO_MULTI', 'POINT', 'LINESTRING', 'POLYGON').
-spat xmin ymin xmax ymax
Spatial query extents to filter features.
-skipfailures
Continue with translation even if some features could not be written.
-progress
Display progress of the translation process.
-co NAME=VALUE
Creation option for the output format/driver (e.g., 'GEOMETRY_NAME=geom').
DESCRIPTION
ogr2ogr is a powerful command-line tool, part of the GDAL/OGR library, designed for converting simple features data between various vector data formats. It can read virtually any vector format supported by GDAL/OGR drivers (like Shapefile, GeoJSON, PostGIS, KML, CSV) and write to another.
Beyond simple format conversion, ogr2ogr offers extensive capabilities including coordinate system reprojection, spatial and attribute filtering (e.g., SQL WHERE clauses, spatial extents), reordering fields, selecting specific layers or features, and modifying geometry types. It's an essential utility for GIS professionals and developers working with geospatial vector data, enabling complex data transformations and interoperability between different systems and applications. Its flexibility makes it a cornerstone for automating geospatial workflows.
CAVEATS
ogr2ogr relies heavily on the capabilities of the installed GDAL/OGR drivers. Some drivers may have specific limitations regarding data types, schema evolution, or performance. Reprojection accuracy depends on the quality of the source and target SRS definitions and transformations. Large datasets can consume significant memory and disk space, potentially requiring optimized strategies or streaming capabilities.
GDAL/OGR DRIVERS
ogr2ogr's versatility stems from its support for a wide array of GDAL/OGR drivers. Each driver provides read/write capabilities for a specific vector data format (e.g., Shapefile, GeoJSON, PostGIS, GML). Users specify the desired output format using the -f option. The availability and capabilities of these drivers depend on how GDAL/OGR was compiled and what external libraries are linked.
SPATIAL REFERENCE SYSTEMS (SRS)
A core function of ogr2ogr is the ability to transform data between different Spatial Reference Systems (SRS), commonly known as coordinate systems or projections. This is achieved using the -s_srs (source SRS) and -t_srs (target SRS) options. SRS definitions can be provided in various formats, including EPSG codes (e.g., 'EPSG:4326' for WGS 84), PROJ.4 strings, or WKT (Well-Known Text) strings. Accurate SRS definition is crucial for correct spatial operations.
HISTORY
ogr2ogr is a key component of the GDAL/OGR project, an open-source geospatial data translation library developed primarily by Frank Warmerdam. GDAL (Geospatial Data Abstraction Library) handles raster data, while OGR (OpenGIS Simple Features Reference Implementation) handles vector data. ogr2ogr emerged as the primary tool for vector data transformation, building on the OGR library's extensive support for various formats and spatial operations. Its development began in the late 1990s, and it has since become an industry standard for geospatial data interoperability, continuously evolving with new drivers and features.
SEE ALSO
ogrinfo(1), gdalinfo(1), gdalsrsinfo(1), gdal_translate(1)