-1

I need to use the GeoJSON file and TIFF images to produce masks. Is there a Python program that takes GeoJSON file and TIFF image as input and produces masks?

3

You can use rasterio.mask method:

import fiona
import rasterio
import rasterio.mask

with fiona.open("file.geojson", "r") as geojson:
   features = [feature["geometry"] for feature in geojson]

with rasterio.open("file.tiff") as src:
   out_image, out_transform = rasterio.mask.mask(src, features, crop=True)
   out_meta = src.meta
| improve this answer | |
  • Thank you very much! It runs, but I cannot see the output. How can I display the mask and save it as a tiff image? Appreciate your help! – Rohullah Najibi Oct 30 at 14:11
  • 1
    You can write instead of just read the file and plot it using matplotlib. If you think my answer has solved your question, please mark it as solved to help other users. – ramiroaznar Oct 30 at 14:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.