Giter Site home page Giter Site logo

Comments (1)

cmarshak avatar cmarshak commented on July 22, 2024 1

So - I would definitely say this is a shortcoming of this library. That said, this result is currently a feature, not a bug, in that it's output is expected (by me), though it certainly could yield unexpected results for users, particularly if you are expecting a raster covering the requested extent, which many are! The issue in this case is that the bounds you requested fall outside of the what is available with glo-30.

Globally glo-30 tiles look like this:

image

For the requested area (zoomed in), the yellow lines are the glo-30 tiles available and the black is the area you selected:

image

The latter was generated using:

from dem_stitcher import get_overlapping_dem_tiles
from rasterio.crs import CRS
import matplotlib.pyplot as plt
from shapely.geometry import box
import geopandas as gpd

bounds = [176.678207, 50.908962, 179.697601, 52.754662]
df_tiles = get_overlapping_dem_tiles(bounds=bounds,
                                     dem_name='glo_30')
df_bbox = gpd.GeoDataFrame(geometry=[box(*bounds)], crs=CRS.from_epsg(4326))

fig, ax = plt.subplots()

df_bbox.exterior.plot(ax=ax, color='black')
df_tiles.exterior.plot(ax=ax, color='yellow')

ax.set_xlabel('Lon')
ax.set_ylabel('Lat')

So, the rounding is done because the origin and extent is selected on what's available via rasterio. It's based on window functionality (maybe inherited from gdal?): https://rasterio.readthedocs.io/en/stable/topics/windowed-rw.html.

Here is a hypothetical sample:

from shapely.geometry import box

bounds=[<BOUNDS>]
geo = box(*bounds)
with rasterio.open(<IMAGE_PATH>) as src:
    out_image, out_transform = rasterio.mask.mask(src, geo, crop=True)
    out_meta = src.meta

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

with rasterio.open("<OUT_PATH>", "w", **out_meta) as dest:
    dest.write(out_image) 

I don't have sample data - but basically origin will be shifted if the requested bounds are to the left of source image similar to your example.

Hope this makes sense. At some point, it might be helpful to change the origin depending on requested data and fill with nodata, but currently, left things without additional modification because it's easier (to avoid any resampling would have to figure out origin so that it contained extent and then write the appropriate tests).

Glad you spotted this and hope this can be used in the future to highlight this deficiency of this library.

from dem-stitcher.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.