Skip to content

Commit

Permalink
Fuel Grid PMTiles (#4144)
Browse files Browse the repository at this point in the history
- Simple script for quickly regenerating fuel grid pmtiles locally when we get a new fuel grid
- Closes SFMS: Fuel Layer Raster translated into a PMTile #4125
  • Loading branch information
brettedw authored Nov 28, 2024
1 parent 06d8512 commit 22ed517
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions api/app/utils/generate_fuel_grid_pmtiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from tempfile import TemporaryDirectory

from app import config
from app.utils.pmtiles import tippecanoe_wrapper, write_geojson
from app.utils.polygonize import polygonize_in_memory
from app.utils.s3 import set_s3_gdal_config


def generate_fuel_pmtiles(fuel_grid_path: str, output_path: str):
"""
Simple function for local use to regenerate fuel grid pmtiles annually when the new fuel grid raster
is received from BCWS Geospatial. Typically stored in s3: {bucket}/psu/pmtiles/fuel
"""
set_s3_gdal_config()
with polygonize_in_memory(fuel_grid_path, "fuel", "fuel") as layer, TemporaryDirectory() as temp_dir:
temp_geojson = write_geojson(layer, temp_dir)

tippecanoe_wrapper(temp_geojson, output_path, min_zoom=4, max_zoom=12)


def main():
bucket = config.get("OBJECT_STORE_BUCKET")
fuel_grid = f"/vsis3/{bucket}/sfms/static/fbp2024.tif" # input fuel grid stored in s3
output_path = "/output/to/fbp2024.pmtiles" # local output

generate_fuel_pmtiles(fuel_grid, output_path)


if __name__ == "__main__":
main()

0 comments on commit 22ed517

Please sign in to comment.