tldr/pages/common/ogr2ogr.md

29 lines
1.2 KiB
Markdown
Raw Normal View History

2019-10-29 15:36:20 +00:00
# ogr2ogr
2022-03-19 18:16:51 +00:00
> Convert geospatial vector data between file formats.
2022-02-27 13:50:07 +00:00
> More information: <https://gdal.org/programs/ogr2ogr.html>.
2019-10-29 15:36:20 +00:00
- Convert a Shapefile into a GeoPackage:
`ogr2ogr -f GPKG {{path/to/output.gpkg}} {{path/to/input.shp}}`
2019-10-29 15:36:20 +00:00
2022-03-19 18:16:51 +00:00
- Reduce a GeoJSON to features matching a condition:
`ogr2ogr -where '{{myProperty > 42}}' -f {{GeoJSON}} {{path/to/output.geojson}} {{path/to/input.geojson}}`
2019-10-29 15:36:20 +00:00
- Change coordinate reference system of a GeoPackage from `EPSG:4326` to `EPSG:3857`:
`ogr2ogr -s_srs {{EPSG:4326}} -t_srs {{EPSG:3857}} -f GPKG {{path/to/output.gpkg}} {{path/to/input.gpkg}}`
2019-10-29 15:36:20 +00:00
- Convert a CSV file into a GeoPackage, specifying the names of the coordinate columns and assigning a coordinate reference system:
`ogr2ogr -f GPKG {{path/to/output.gpkg}} {{path/to/input.csv}} -oo X_POSSIBLE_NAMES={{longitude}} -oo Y_POSSIBLE_NAMES={{latitude}} -a_srs {{EPSG:4326}}`
2019-10-29 15:36:20 +00:00
- Load a GeoPackage into a PostGIS database:
`ogr2ogr -f PostgreSQL PG:dbname="{{database_name}}" {{path/to/input.gpkg}}`
2019-10-29 15:36:20 +00:00
- Clip layers of a GeoPackage file to the given bounding box:
`ogr2ogr -spat {{min_x}} {{min_y}} {{max_x}} {{max_y}} -f GPKG {{path/to/output.gpkg}} {{path/to/input.gpkg}}`