question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add method to replicate https://cogeotiff.github.io/rio-tiler/advanced/feature/

See original GitHub issue

Reading 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kylebarroncommented, Nov 23, 2020

I feel like it might be better to define a separate method for this, instead of overloading part. Maybe cog.feature or something

0reactions
kylebarroncommented, Nov 23, 2020

Yeah I guess you’re right

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found