def to_geotiff(self, export): """ Writes geotiffs to disk. Parameters ---------- export : str Select a raster to write to geotiff. Choose from: 'directions' - network burned into a raster with link directions from 0 (upstream) to 1 (downstream)) 'skeleton' - skeletonized mask 'distance' - distance-transformed mask """ valid_exports = ['directions', 'distance', 'skeleton'] if export not in valid_exports: print('Cannot write {}. Choose from {}.'.format( export, valid_exports)) return if export == 'directions': outpath = self.paths['linkdirs'] io.write_linkdirs_geotiff(self.links, self.gdobj, outpath) else: if export == 'distance': raster = self.Idist outpath = self.paths['Idist'] dtype = gdal.GDT_Float32 color_table = None options = None nbands = 1 elif export == 'skeleton': raster = self.Iskel outpath = self.paths['Iskel'] dtype = gdal.GDT_Byte color_table = io.colortable('skel') options = ['COMPRESS=LZW'] nbands = 1 io.write_geotiff(raster, self.gt, self.wkt, outpath, dtype=dtype, options=options, color_table=color_table, nbands=nbands) print('Geotiff written to {}.'.format(outpath))
def test_binary(self): """Test binary colormap.""" color_table = iu.colortable('binary') assert np.all(color_table.GetColorEntry(0) == (0, 0, 0, 0)) assert np.all(color_table.GetColorEntry(1) == (255, 255, 255, 100))
def test_GSW(self): """Test GSW.""" color_table = iu.colortable('GSW') assert np.all(color_table.GetColorEntry(0) == (0, 0, 0, 0)) assert np.all(color_table.GetColorEntry(1) == (0, 0, 0, 0)) assert np.all(color_table.GetColorEntry(2) == (176, 224, 230, 100))
def test_tile(self): """Test tile.""" color_table = iu.colortable('tile') assert np.all(color_table.GetColorEntry(0) == (0, 0, 0, 0)) assert np.all(color_table.GetColorEntry(1) == (0, 0, 255, 100))
def test_mask(self): """Test mask.""" color_table = iu.colortable('mask') assert np.all(color_table.GetColorEntry(0) == (0, 0, 0, 0)) assert np.all(color_table.GetColorEntry(1) == (0, 128, 0, 100))