shorelines, _ = rasterize(shorelines_path, affine=affine, shape=shape)
shorelines = np.logical_not(shorelines).astype(int)

lakes, _ = rasterize(lakes_path, affine=affine, shape=shape)
rivers, _ = rasterize(rivers_path, affine=affine, shape=shape)

water = shorelines + lakes + rivers

water_output_raster_path = "water_binary.tif"

export_raster(water, affine, water_output_raster_path)

# -----------------------------------------------------------------------------

# import rasterio
# water_src = rasterio.open(water_output_raster_path)
# water = water_src.read()[0]
# affine = water_src.affine

distance_output_raster_path = "water_distance.tif"


def raster_conditional(rarray):
    return (rarray == 1)


dist = build_distance_array(water,
                            affine=affine,
                            output=distance_output_raster_path,
                            conditional=raster_conditional)
Exemplo n.º 2
0
pixel_size = 0.01

rasterized_features_path = "{0}/data/{1}_binary.tif".format(base, out_name)

shp = fiona.open(shp_path, "r")
rv_array, affine = rasterize(shp,
                             pixel_size=pixel_size,
                             bounds=shp.bounds,
                             output=rasterized_features_path)

# export_raster(rv_array, affine, rasterized_features_path)

# print rv_array
print rv_array.shape
print affine

# -----------------------------------------------------------------------------

distance_raster_path = "{0}/data/{1}_distance.tif".format(base, out_name)


def raster_conditional(rarray):
    return (rarray == 1)


build_distance_array(rv_array,
                     affine=affine,
                     output=distance_raster_path,
                     conditional=raster_conditional)