This repository provides a set of scripts to process GeoTiFF (mosaics) from drones images.
Dependencies
Python 3.12.1, Geopandas and GDAL
Clone repository and create Virtual Environment:
git https://github.com/Harmonize-Brazil/mosaic_utils.git
cd mosaic_utils
python -m venv venv
source venv/bin/activate
pip3 install --upgrade pip setuptools wheel
Using a Makefile, run this command at the terminal:
make
Or make step-by-step typing these commands below:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install -y g++ && sudo apt-get install -y libgdal-dev gdal-bin python3-gdal
sudo apt-get install build-essential ##This one solves some bugs sometimes
pip3 install "numpy<2.0"
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip3 install GDAL==`gdal-config --version`
python -c "from osgeo import gdal; print(gdal.__version__)"
Problems with GDAL import, please see these related issues and solutions!
Tip
For Windows
users, make sure you have created a virtual environment and have activated it before starting the next steps:
- Download a .whl file for the GDAL library, and install using that file. Select the desired version here.
- The command to install is pip install <path_to_whl_file>.
Source:
https://medium.com/@spatsel.cci/using-gdal-with-python-pip-and-windows-10-618d773d8926
Alternative:
Install dependencies and requirements:
pip3 install geopandas
Run crop_mosaic.py
to crop a raster file based on the convex hull of the negative buffer from the mapped area:
python crop_mosaic.py --mosaic_image /home/user/Desktop/HARMONIZE-Br_Project/src/FieldWorkCampaigns/Mocajuba2023/EscolaOficina_20231107/Mosaic/EscolaOficina_7nov-orthophoto.tif --threshold_area 0.005
The Region of Interest (ROI) is delimited by a polygon resulting from vectorizing the valid pixel values of the raster, after that, the algorithm creates a negative buffer
based on threshold_area
that is a percentage of area mapped in meters. Finally, create a cropped raster using the convex hull of the negative buffer, which aims to
create the final cropped mosaic without the serrated edges.
Or --help
for further information about script options:
python crop_mosaic.py --help