Skip to content

Commit

Permalink
Use the footprint to compute the bounding box with shapely
Browse files Browse the repository at this point in the history
  • Loading branch information
Doruk Ozturk committed Jan 12, 2018
1 parent 50b7c00 commit 1712ee6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
12 changes: 4 additions & 8 deletions gaia/geo/gdal_functions.py
Expand Up @@ -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.
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions gaia/geo/geo_inputs.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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"""
Expand Down
3 changes: 2 additions & 1 deletion tests/cases/test_processors.py
Expand Up @@ -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(
Expand Down

0 comments on commit 1712ee6

Please sign in to comment.