Thanks for the great work! I have an error that is making no sense to me.
cropping a raster with a geojson:
geoms = {
'geometry': {
'type': 'Polygon',
'coordinates':
[[[15.303386083270999, -4.373279567953402], [15.303475916729, -4.373279567953402],
[15.303475916729, -4.373186432046598], [15.303386083270999, -4.373186432046598]]]
}
}
with rasterio.open(base_raster) as src:
out_image, out_transform = mask(src, geoms, crop=True)
however features.py returns an error:
geom = geometry.get('geometry') or geometry
AttributeError: 'str' object has no attribute 'get'
but attribute `geometry' is there!
Windows 10
'1.0a12'
@lorenzori geoms should be a list instead of a dict: https://github.com/mapbox/rasterio/blob/master/rasterio/mask.py#L124
I see now that our description in the docstring is a little confusing, as we say this on the next line:
GeoJSON-like dict representation of polygons that will be used to
create the mask.
However, what we mean is that each item in the list is a GeoJSON-like dict.
This should work:
geoms = ['geometry': {
'type': 'Polygon',
'coordinates':
[[[15.303386083270999, -4.373279567953402], [15.303475916729, -4.373279567953402],
[15.303475916729, -4.373186432046598], [15.303386083270999, -4.373186432046598]]]
}
]
Sorry about the confusion @lorenzori. I've updated docstrings to help out.
Got it, thanks for the support! just for future reference, this example works:
geoms = [{'type': 'Polygon', 'coordinates': [
[(15.173283, -4.293467), (15.372248, -4.283885),
(15.168365, -4.479364), (15.448367, -4.506647)]]}]
@lorenzori thanks for that note. This also worked for me when other solutions have not.
Most helpful comment
Sorry about the confusion @lorenzori. I've updated docstrings to help out.