Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with assets of sat util #234

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions telluric/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from telluric import GeoRaster2


raster_types = [RASTER_TYPE]
raster_types = [RASTER_TYPE, "image/x.geotiff"]


def transform_properties(properties, schema):
Expand Down Expand Up @@ -305,11 +305,12 @@ def has_raster(self):
"""True if any of the assets is type 'raster'."""
return any(asset.get('type') == RASTER_TYPE for asset in self.assets.values())

def raster(self, name=None, **creteria):
def raster(self, name=None, validate_raster_type=True, **creteria):
"""Generates a GeoRaster2 object based on the asset name(key) or a creteria(protety name and value)."""
if name:
asset = self.assets[name]
if asset["type"] in raster_types:
asset_type = asset.get("type")
if asset_type in raster_types or not validate_raster_type:
__object = asset.get('__object')
if isinstance(__object, GeoRaster2):
return __object
Expand Down
7 changes: 5 additions & 2 deletions telluric/georaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2049,8 +2049,11 @@ def from_assets(cls, assets):
return None
elif len(assets) > 1:
return GeoMultiRaster.from_assets(assets)
raster = list(assets.values())[0]
return GeoRaster2.open(raster["href"], band_names=raster["bands"])
if isinstance(assets, dict):
raster = list(assets.values())[0]
elif isinstance(assets, list):
raster = assets[0]
return GeoRaster2.open(raster.get("href"), band_names=raster.get("bands") or raster.get("eo:bands"))


RasterChunk = namedtuple('RasterChunk', ["raster", "offsets"])
Expand Down
10 changes: 8 additions & 2 deletions telluric/vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,15 @@ def max_resolution():
xsize = raster.width * raster.affine.a / affine.a
ysize = raster.height * raster.affine.e / affine.e
dst_window = Window(xoff, yoff, xsize, ysize)
file_name = raster.source_file if relative_to_vrt else os.path.join(os.getcwd(), raster.source_file)
if relative_to_vrt:
file_name = raster.source_file
else:
if raster.source_file.startswith("http"):
file_name = "/vsicurl/%s" % raster.source_file
else:
file_name = raster.source_file if relative_to_vrt else os.path.join(os.getcwd(), raster.source_file)

vrt.add_band_simplesource(band_element, band_idx, raster.dtype, relative_to_vrt, file_name,
vrt.add_band_simplesource(band_element, i + 1, raster.dtype, relative_to_vrt, file_name,
raster.width, raster.height,
raster.block_shape(i)[1], raster.block_shape(i)[0],
src_window, dst_window)
Expand Down