diff --git a/gaia/geo/gdal_functions.py b/gaia/geo/gdal_functions.py index 5f0a1f1..3cced2c 100644 --- a/gaia/geo/gdal_functions.py +++ b/gaia/geo/gdal_functions.py @@ -448,7 +448,7 @@ def gdal_zonalstats(zones, raster): return list(gen_zonalstats(zones, raster)) -def gdal_bbox(raster_input): +def rasterio_bbox(raster_input): """ This function will return bounding box information for a raster layer. @@ -457,13 +457,9 @@ def gdal_bbox(raster_input): :return: list of coordinates in (xmin, ymin, xmax, ymax) format """ - raster = get_dataset(raster_input) - geotransform = raster.GetGeoTransform() - xmax = geotransform[0] + (raster.RasterXSize * geotransform[1]) - ymin = geotransform[3] + (raster.RasterYSize * geotransform[5]) - xmin = geotransform[0] - ymax = geotransform[3] - return [xmin, ymin, xmax, ymax] + footprint = rasterio_footprint(raster_input) + shape = shapely.geometry.Polygon(footprint) + return list(shape.bounds) def rasterio_footprint(raster_input): diff --git a/gaia/geo/geo_inputs.py b/gaia/geo/geo_inputs.py index c84736f..0fdb135 100644 --- a/gaia/geo/geo_inputs.py +++ b/gaia/geo/geo_inputs.py @@ -37,7 +37,7 @@ from gaia.inputs import GaiaIO, FileIO, UnsupportedFormatException from gaia.filters import filter_pandas, filter_postgis from gaia.geo.gdal_functions import gdal_reproject -from gaia.geo.gdal_functions import gdal_bbox, rasterio_footprint +from gaia.geo.gdal_functions import rasterio_bbox, rasterio_footprint class VectorMixin(object): @@ -257,7 +257,7 @@ def read(self, as_numpy_array=False, as_single_band=True, def get_bbox(self): """Return bounding box of the dataset""" - return gdal_bbox(self.uri) + return rasterio_bbox(self.uri) def get_footprint(self): """Return footpring of the dataset""" diff --git a/tests/cases/test_processors.py b/tests/cases/test_processors.py index 7114240..d4f9ff3 100644 --- a/tests/cases/test_processors.py +++ b/tests/cases/test_processors.py @@ -268,7 +268,8 @@ def test_raster_bbox(self): 'LC81070352015218LGN00_B5.TIF')) bbox = raster_io.get_bbox() - self.assertEquals(bbox, [307485.0, 3870285.0, 540015.0, 4107015.0]) + self.assertEquals(bbox, [307366.7298195886, 3869968.931078481, + 539974.1151507461, 4107482.3190209507]) def test_raster_footprint(self): raster_io = RasterFileIO(