예제 #1
0
from pathlib import Path

from analysis.lib.raster import add_overviews

src_dir = Path("data/inputs")
blueprint_filename = src_dir / "se_blueprint2021.tif"

add_overviews(blueprint_filename)
예제 #2
0
table = read_dataframe(
    src_dir / "NaturesNetwork_conservdesign_180625.tif.vat.dbf",
    columns=["Value", "Priority", "Descrpt"],
    read_geometry=False,
)
table = table.loc[table.Value > 0].copy()
table.Priority = table.Priority.astype("uint8")
table["category"] = table.Descrpt.str[0].astype("uint8")

remap_table = table[["Value", "Priority"]].values.astype("uint8")
priority_data = remap(data, remap_table, nodata=nodata)

write_raster(outfilename, priority_data, transform, DATA_CRS, nodata=nodata)

print("Adding overviews and masks...")
add_overviews(outfilename)

create_lowres_mask(
    outfilename,
    str(outfilename).replace(".tif", "_mask.tif"),
    factor=MASK_FACTOR,
    ignore_zero=False,
)

### Process indicators

# Extract cores from the categories
table["aquatic_cores"] = table.Descrpt.str.contains("Aquatic")
table["terrestrial_cores"] = table.Descrpt.str.contains("Terrestrial")
table["imperiled_cores"] = table.Descrpt.str.contains("Imperiled")
예제 #3
0
import rasterio
import geopandas as gp
import pygeos as pg

from analysis.constants import DATA_CRS
from analysis.lib.raster import add_overviews

data_dir = Path("data/inputs")
src_dir = data_dir / "threats/slr"

boxes = []
for filename in (src_dir).glob("*.tif"):
    with rasterio.open(filename) as src:
        boxes.append(pg.box(*src.bounds))

# union them together into a single polygon
bnd = pg.union_all(boxes)

df = gp.GeoDataFrame({"geometry": [bnd], "index": [0]}, crs=DATA_CRS)
df.to_feather(src_dir / "slr_bounds.feather")

# For debugging
# write_dataframe(df, "/tmp/slr_bounds.gpkg", driver="GPKG")

# Create overviews for each individual file in the VRT
# Note: these have varying resolution, but this creates lower resolutions for each
print("Adding overviews to SLR files...")
for filename in src_dir.glob("*.tif"):
    print(f"Processing {filename}...")
    add_overviews(filename)