Skip to content

Commit

Permalink
Polygons id field must be integer or float
Browse files Browse the repository at this point in the history
  • Loading branch information
vikineema committed Dec 4, 2023
1 parent abba8d8 commit 02c810b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion deafrica_conflux/cli/rasterize_polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from odc.dscache.tools.tiling import parse_gridspec_with_name
from odc.geo.geobox import GeoBox
from odc.geo.xr import wrap_xr
from pandas.api.types import is_float_dtype, is_integer_dtype

from deafrica_conflux.cli.logs import logging_setup
from deafrica_conflux.filter_polygons import get_intersecting_polygons
Expand Down Expand Up @@ -41,7 +42,7 @@
"--use-id",
type=str,
default="WB_ID",
help="Optional. Unique key id polygons vector file.",
help="Unique key id in polygons vector file. Must contain either integers or floats.",
)
@click.option("output-directory", type=str, help="Directory to write the tiled polygon rasters to.")
@click.option(
Expand Down Expand Up @@ -130,6 +131,9 @@ def rasterise_polyongs(
# Check the id column is unique.
id_field = guess_id_field(input_gdf=polygons_gdf, use_id=use_id)

# Column must contain either integers or float values.
assert is_integer_dtype(polygons_gdf[id_field]) or is_float_dtype(polygons_gdf[id_field])

_log.info("Filtering out tiles that do not intersect with any polygon...")
filtered_tiles_gdf = get_intersecting_polygons(
region=polygons_gdf, polygons_gdf=tiles_gdf, use_id="tile_ids"
Expand Down

0 comments on commit 02c810b

Please sign in to comment.