def get_raster_extent(fp, return_type='poly'): """Get the boundary of the raster file. Parameters ---------- fp: str File path of the raster file. return_type: {'poly', 'plot', 'gdal'} If 'poly', return four corner coordinates. If plot, return (xmin, xmax, ymin, ymax). If 'gdal', return (xmin, ymin, xmax, ymax). Returns ------- extent: ndarray or tuple Depends on return_type. If 'poly', return four corner coordinates. If plot, return (xmin, xmax, ymin, ymax). If 'gdal', return (xmin, ymin, xmax, ymax). Examples -------- >>> import TronGisPy as tgp >>> from shapely.geometry import Polygon >>> raster_fp = tgp.get_testing_fp() >>> extent = tgp.get_raster_extent(raster_fp) >>> Polygon(extent).area 570976.9697303267 """ rows, cols, geo_transform = get_raster_info(fp, ['rows', 'cols', 'geo_transform']) return tgp.get_extent(rows, cols, geo_transform, return_type)
def extent_for_gdal(self): """(xmin, xmax, ymin, ymax) of the raster boundary.""" return tgp.get_extent(self.rows, self.cols, self.geo_transform, return_type='gdal')
def extent(self): """Coordinates of Four corner points' of the raster. """ return tgp.get_extent(self.rows, self.cols, self.geo_transform, return_type='poly')