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]
PARAMETERS
-f
Select an output format name. Use -formats on command line to see the list of available formats.
-append
Append to existing layer instead of creating a new one.
-update
Open existing output datasource in update mode rather than trying to create a new one.
-overwrite
Overwrite existing output datasource.
-nln
Define output layer name.
-select
List of fields to copy from input layer.
-where
Attribute query (WHERE clause).
-sql
SQL statement to execute.
-t_srs
Target spatial reference. srs_def may be any of the usual GDAL/OGR forms.
-s_srs
Source spatial reference. srs_def may be any of the usual GDAL/OGR forms.
The output datasource name.
The input datasource name.
[layer [layers...]]
The name of the layer(s) to copy from the input datasource.
DESCRIPTION
ogr2ogr is a command-line utility for converting vector data between various formats. It's a powerful tool for data translation, re-projection, and simple feature manipulation. It leverages the OGR Simple Features Library, which supports reading and writing a wide array of vector data formats, including Shapefiles, GeoJSON, PostGIS, and many more.
ogr2ogr can perform format-to-format translations, subsetting based on spatial or attribute queries, re-projecting to different coordinate reference systems, and even simple geometry modifications. The utility is commonly used in GIS workflows for data migration, standardization, and preparation for analysis or visualization.
It's a core component of the GDAL/OGR library, providing a versatile and scriptable way to manage vector data. The tool can be used with spatial databases and remote data resources, and is able to translate data from and to such resources by using the VSI Virtual File System API.
Many options exist that facilitate data manipulation, for example, it can modify the output dataset structure or the feature geometry and attributes during conversion.
CAVEATS
Complex SQL queries or feature manipulation may require significant processing time and resources. Pay attention to the output format limitations and data type conversions that may occur during the process. Overwriting existing files without proper backups may result in data loss.
SPATIAL FILTERING
ogr2ogr allows you to filter features based on their spatial relationship to a defined geometry using the -spat option. This can significantly reduce the size of the output dataset by only including features within a specific area of interest. The '-clipsrc' option can be used in order to spatially filter features.
MEMORY MANAGEMENT
For very large datasets, consider adjusting GDAL's memory cache size using the GDAL_CACHEMAX environment variable to optimize performance and avoid out-of-memory errors. Also consider using tiled output formats like GeoPackage to handle large datasets more efficiently.
HISTORY
ogr2ogr is a core component of the GDAL/OGR library, initially released in the late 1990s. Developed as a powerful tool for translating between different geospatial vector data formats, its development was driven by the need to standardize and share spatial information across diverse software and platforms. It evolved as more formats were supported by the library, becoming the industry standard tool for such purposes.