ogr2ogr is the swiss army knife in the world of geospatial analysis and data processing. It's main purpose is to convert geospatial data to different dataformats without the need of Geographic Information Systems such as QGIS or ArcPro. It also allows us to do various operations during this process. We can reproject our data; clip it; make a sub selection of data or attributes; intersect it; change column names and much more.
Clone the repository to experiment with the data used in the commands below.
For an in depth walkthrough vist my blogpost on ogr2ogr
ogr2ogr -f 'GPKG' project_extent.gpkg project_extent_wgs.shp
ogr2ogrbasically tells the computer: get ready, I want to use ogr2ogr.-f 'GPKG'specify the format to which we want to convert our shapefile.project_extent.gpkgis the output file.project_extent_wgs.shpis our input file.
ogr2ogr -f 'GPKG' project_extent_rdnew.gpkg project_extent_wgs.shp -t_srs EPSG:28992
ogr2ogr -f 'GPKG' clipped/clip_buildings.gpkg buildings.gpkg -clipsrc project_extent_rdnew.gpkg -progress
ogr2ogrtell computer you are about to use ogr2ogr.-f'GPKG' specify the output format.clipped/clip_buildings.gpkgspecify output file and destination. In our case we wish to save result in a subfolderclipped/.buildings.gpkgis our input file.-clipsrcthe clip operations we wish to apply using another file.project_extent_rdnew.gpkgthe file containing the clip features. In our case our reprojected neighborhood.-progressand show us a progress bar.