def get_raster(filename, band_index, minimum=0, maximum=65535): """ Get a single band image. Possible errors: * File doesn't exist * Band doesn't exist """ fpath = os.path.join(DATA_DIR, filename) if not os.path.exists(fpath): return jsonify({'error': 'File does not exist'}) with rasterio.drivers(): with rasterio.open(fpath) as src: if not band_index in map(lambda x: x + 1, range(7)): return jsonify({'error': 'Band index out of range'}) band = src.read_band(band_index) zoom = 600.0 / band.shape[1] band = ndimage.interpolation.zoom(band, zoom) output = scale_image(band, float(minimum), float(maximum)) return send_file(output, mimetype='image/png')
def get_color(filepath, minimum, maximum): """ Get a color image. """ fpath = os.path.join(DATA_DIR, filepath) if not os.path.exists(fpath): return jsonify({'error': 'File does not exist'}) with rasterio.drivers(): with rasterio.open(fpath) as src: def get_band(index): band = src.read_band(index) zoom = 600.0 / band.shape[1] return ndimage.interpolation.zoom(band, zoom) count = src.meta["count"] bands = map(get_band, get_color_bands(count)) arr = np.dstack(bands) minimum, maximum = arr.min(), arr.max() output = scale_image(arr, float(minimum), float(maximum)) return send_file(output, mimetype='image/png')
def get_raster_test(fpath, band_index, minimum, maximum): """ Testing new function that reads a raster from memory. """ print "GET RASTER TEST" if BANDS is None: return jsonify({'error': 'Image is not in memory'}) if band_index == 0: if BANDS.shape[2] == 3: arr = BANDS[:, :, 0:3] else: arr = BANDS[:, :, 2::-1] else: arr = BANDS[:, :, band_index - 1] minimum, maximum = arr.min(), arr.max() output = scale_image(arr, float(minimum), float(maximum)) return send_file(output, mimetype='image/png')
def get_color_composite(filepath, r, g, b): fpath = os.path.join(DATA_DIR, filepath) if not os.path.exists(fpath): return jsonify({'error': 'File does not exist'}) with rasterio.drivers(): with rasterio.open(fpath) as src: zoom = IMG_WIDTH / src.meta["width"] def get_band(index): band = src.read_band(index) return ndimage.interpolation.zoom(band, zoom) arr = np.dstack( map(get_band, [r, g, b]) ) minimum, maximum = arr.min(), arr.max() output = scale_image(arr, float(minimum), float(maximum)) return send_file(output, mimetype='image/png')