def reproject(self, dest, dst_transform, dst_crs, dst_nodata, resampling, **kwargs): dst_poly = geometry.polygon_from_transform(dest.shape[1], dest.shape[0], dst_transform, dst_crs).to_crs(self.crs) src_poly = geometry.polygon_from_transform(self.shape[1], self.shape[0], self.transform, self.crs) bounds = dst_poly.intersection(src_poly) geobox = geometry.GeoBox.from_geopolygon( bounds, (self.transform.e, self.transform.a), crs=self.crs) tmp, _, tmp_transform = _read_decimated( ~self.transform * geobox.affine, self, geobox.shape) return rasterio.warp.reproject(tmp, dest, src_transform=self.transform * tmp_transform, src_crs=str(geobox.crs), src_nodata=self.nodata, dst_transform=dst_transform, dst_crs=str(dst_crs), dst_nodata=dst_nodata, resampling=resampling, **kwargs)
def grid2polygon(grid, crs): h, w = grid['shape'] transform = Affine(*grid['transform'][:6]) if isinstance(crs, str): crs = CRS(crs) return polygon_from_transform(w, h, transform, crs)
def grid2polygon(grid, crs): grid = _norm_grid(grid) h, w = grid.shape transform = grid.transform if isinstance(crs, str): crs = CRS(crs) return polygon_from_transform(w, h, transform, crs)
def gs_bounds(gs: GridSpec, tiles: Tuple[Tuple[int, int], Tuple[int, int]]) -> Geometry: """ Compute Polygon for a selection of tiles. :param gs: GridSpec :param tiles: (x_range, y_range) X,Y ranges are inclusive on the left and exclusive on the right, same as numpy slicing. """ ((x0, x1), (y0, y1)) = tiles if gs.resolution[0] < 0: gb = gs.tile_geobox((x0, y1 - 1)) else: gb = gs.tile_geobox((x0, y0)) nx = (x1 - x0) * gb.shape[1] ny = (y1 - y0) * gb.shape[0] return polygon_from_transform(nx, ny, gb.affine, gb.crs)