Add method to replicate https://cogeotiff.github.io/rio-tiler/advanced/feature/
See original GitHub issueReading a file for a specific feature seems a bit more natural than using a bbox for some users
We have a way of doing this using cutline
from rio_tiler.io import COGReader
from rio_tiler.utils import create_cutline
from rasterio.features import bounds as featureBounds
feat = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-52.6025390625, 73.86761239709705],
[-52.6025390625, 73.59679245247814],
[-51.591796875, 73.60299628304274],
[-51.591796875, 73.90420357134279],
[-52.4267578125, 74.0437225981325],
[-52.6025390625, 73.86761239709705]
]
]
}
}
# Get BBOX of the polygon
bbox = featureBounds(feat)
# Use COGReader to open and read the dataset
with COGReader("my_tif.tif") as cog:
# Create WTT Cutline
cutline = create_cutline(cog.dataset, feat, geometry_crs="epsg:4326")
# Read part of the data (bbox) and use the cutline to mask the data
data, mask = cog.part(bbox, vrt_options={'cutline': cutline})
but it will be nicer if we could directly pass the feature to a method (or to the part()
method)
from rio_tiler.io import COGReader
feat = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-52.6025390625, 73.86761239709705],
[-52.6025390625, 73.59679245247814],
[-51.591796875, 73.60299628304274],
[-51.591796875, 73.90420357134279],
[-52.4267578125, 74.0437225981325],
[-52.6025390625, 73.86761239709705]
]
]
}
}
with COGReader("my_tif.tif") as cog:
data, mask = cog.part(None, feature=feat)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
About geo-replication - GitHub Enterprise Server 3.5 Docs
The replicas function as a point of presence terminating all SSL connections. Traffic between hosts is sent through an encrypted VPN connection, similar...
Read more >Adding methods to another package's R6 class: how ... - GitHub
R6 has a nifty feature where you can add new members to an existing class via set(). You can even do this to...
Read more >Add ability to set afterLoad static methods on Controllers #579
When a controller is registered, the afterLoad static method, if present, will be called It gets passed the application instance and the identifier...
Read more >pelotom/use-methods: A simpler way to useReducers - GitHub
This library exports a single React Hook, useMethods , which has all the power of useReducer but none of the ceremony that comes...
Read more >Adding methods to prototypes of Element, Node, etc. #1503
For any class (like Element ) where I want to add a new prototype method, ... The Object.create , as I understand it,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I feel like it might be better to define a separate method for this, instead of overloading
part
. Maybecog.feature
or somethingYeah I guess you’re right