Commit e2a126ff authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

added keyword to GeoArray.show_map() to make figure zoomable

io.raster.GeoArray.GeoArray:
- show_map() added keyword to make figure zoomable

- updated __version__
parent 3e805bb6
...@@ -15,7 +15,7 @@ __all__=[#'compatibility', ...@@ -15,7 +15,7 @@ __all__=[#'compatibility',
'similarity', 'similarity',
'GeoArray'] 'GeoArray']
__version__ = '20170315_01' __version__ = '20170316_01'
__author__='Daniel Scheffler' __author__='Daniel Scheffler'
# Validate GDAL version # Validate GDAL version
......
...@@ -804,7 +804,7 @@ class GeoArray(object): ...@@ -804,7 +804,7 @@ class GeoArray(object):
os.makedirs(os.path.dirname(out_path)) os.makedirs(os.path.dirname(out_path))
if self.is_inmem: if self.is_inmem:
ds = get_GDAL_ds_inmem(self.arr,self.geotransform, self.projection, self.nodata) # expects rows,columns,bands ds = get_GDAL_ds_inmem(self.arr,self.geotransform, self.projection, self.nodata) # expects rows,columns,bands
# set metadata # set metadata
if not self.metadata.empty: if not self.metadata.empty:
...@@ -819,7 +819,7 @@ class GeoArray(object): ...@@ -819,7 +819,7 @@ class GeoArray(object):
#out_arr = self.arr if self.ndim == 2 else np.swapaxes(np.swapaxes(self.arr, 0, 2), 1, 2) # rows, columns, bands => bands, rows, columns #out_arr = self.arr if self.ndim == 2 else np.swapaxes(np.swapaxes(self.arr, 0, 2), 1, 2) # rows, columns, bands => bands, rows, columns
#gdalnumeric.SaveArray(out_arr, out_path, format=fmt, prototype=ds) # expects bands,rows,columns #gdalnumeric.SaveArray(out_arr, out_path, format=fmt, prototype=ds) # expects bands,rows,columns
ds = None ds = None
else: else:
src_ds = gdal.Open(self.filePath) src_ds = gdal.Open(self.filePath)
...@@ -951,7 +951,7 @@ class GeoArray(object): ...@@ -951,7 +951,7 @@ class GeoArray(object):
def show_map(self, xlim=None, ylim=None, band=0, boundsMap=None, boundsMapPrj=None, figsize=None, def show_map(self, xlim=None, ylim=None, band=0, boundsMap=None, boundsMapPrj=None, figsize=None,
interpolation='none', cmap=None, nodataVal=None, res_factor=None, return_map=False): interpolation='none', cmap=None, nodataVal=None, res_factor=None, return_map=False, zoomable=False):
""" """
:param xlim: :param xlim:
...@@ -965,9 +965,20 @@ class GeoArray(object): ...@@ -965,9 +965,20 @@ class GeoArray(object):
:param nodataVal: :param nodataVal:
:param res_factor: :param res_factor:
:param return_map: :param return_map:
:param zoomable: <bool> enable or disable zooming via mpld3
:return: :return:
""" """
from mpl_toolkits.basemap import Basemap from mpl_toolkits.basemap import Basemap
try:
import mpld3
if zoomable:
mpld3.enable_notebook()
else:
mpld3.disable_notebook()
except:
if zoomable:
zoomable = False
warnings.warn('mpld3 is not available. Zooming disabled.')
assert self.geotransform and tuple(self.geotransform) != (0,1,0,0,0,-1),\ assert self.geotransform and tuple(self.geotransform) != (0,1,0,0,0,-1),\
'A valid geotransform is needed for a map visualization. Got %s.' %self.geotransform 'A valid geotransform is needed for a map visualization. Got %s.' %self.geotransform
...@@ -1010,7 +1021,10 @@ class GeoArray(object): ...@@ -1010,7 +1021,10 @@ class GeoArray(object):
palette.set_under('0') palette.set_under('0')
# add image to map (y-axis must be inverted for basemap) # add image to map (y-axis must be inverted for basemap)
m.imshow(np.flipud(image2plot), palette, interpolation=interpolation, vmin=vmin, vmax=vmax) if zoomable:
m.imshow(image2plot, palette, interpolation=interpolation, vmin=vmin, vmax=vmax)
else:
m.imshow(np.flipud(image2plot), palette, interpolation=interpolation, vmin=vmin, vmax=vmax)
# add coordinate grid lines # add coordinate grid lines
parallels = np.arange(-90, 90., 0.25) parallels = np.arange(-90, 90., 0.25)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment