1

This question refers to the doc of rasterio: https://rasterio.readthedocs.io/en/latest/topics/masking-by-shapefile.html

I used the given code on the website.

out_meta.update({"driver": "GTiff",
                 "height": out_image.shape[1],
                 "width": out_image.shape[2],
                 "transform": out_transform})

with rasterio.open("RGB.byte.masked.tif", "w", **out_meta) as dest:
    dest.write(out_image)

How do they create the RGB.byte.masked.tif file ?

1 Answer 1

1

The line below opens "RGB.byte.masked.tif" for writing (note the "w" argument). It creates the file if it does not exist and completely overwrites it if it does exist.

with rasterio.open("RGB.byte.masked.tif", "w", **out_meta) as dest:
2
  • Thanks! My shapefile has the coordinates: [[(0.0, 0.0),(0.0, 100.0),(100.0, 100.0),(100.0, 0.0),(0.0, 0.0)]] but the RGB.byte.masked.tif file at the end is the same as the RGB.byte.tif file at the beginning. I thought it would be a new file with the bounds equal to the shapefile ? Commented Oct 2, 2021 at 9:30
  • Yes, it should. But the coordinates (0.0, 0.0),(0.0, 100.0),etc... look wrong.
    – user2856
    Commented Oct 2, 2021 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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