TransWikia.com

Cropping TIFF images based on GeoJSON bounding boxes in Python

Geographic Information Systems Asked by Rohullah Najibi on August 4, 2020

I have a GeoJSON file that has bounding boxes (squares), and I also have many TIFF images. I want to crop the TIFF images exactly to bounding boxes provided by the GeoJSON file. While doing this, I want to preserve the coordinates of the TIFF images that is shown in QGIS. I searched a lot, but I could not find useful information about it.

One Answer

As @user30184 has mentioned, gdalwarp can perform exactly what you are looking for and can be called from the command line with the appropriate operations flags.

If you are working from python (as has been tagged) and all your data is in the proper coordinate systems, you might find the rasterio and fiona command line tools a bit simpler to handle. The operation that you are looking for is called clip

After installing both of those libraries, I would follow closely the example that the rasterio documentation shows. Something along the lines of...

rio clip input.tif output.tif --bounds $(fio info my_geojson.json --bounds)

...for each input.tif (using a loop or manually entering each if you aren't comfortable with shell scripting) would give you the desired outcome.

Answered by Trevor J. Smith on August 4, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP