Skip to content

Commit

Permalink
Add max_size to ploygonize command #72
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Dec 18, 2024
1 parent 74a8f16 commit d81587d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/ftw_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ def inference_run(input, model, out, resize_factor, gpu, patch_size, batch_size,
@click.option('--out', '-o', type=str, default=None, help="Output filename for the polygonized data. If not given defaults to the name of the input file with parquet extension. " + SUPPORTED_POLY_FORMATS_TXT)
@click.option('--simplify', type=float, default=15, show_default=True, help="Simplification factor to use when polygonizing in the unit of the CRS, e.g. meters for Sentinel-2 imagery in UTM. Set to 0 to disable simplification.")
@click.option('--min_size', type=float, default=500, show_default=True, help="Minimum area size in square meters to include in the output.")
@click.option('--max_size', type=float, default=1000000, show_default=True, help="Maximum area size in square meters to include in the output.")
@click.option('--overwrite', '-f', is_flag=True, help="Overwrite outputs if they exist.")
@click.option('--close_interiors', is_flag=True, help="Remove the interiors holes in the polygons.")
def inference_polygonize(input, out, simplify, min_size, overwrite, close_interiors):
def inference_polygonize(input, out, simplify, min_size, max_size, overwrite, close_interiors):
from ftw_cli.polygonize import polygonize
polygonize(input, out, simplify, min_size, overwrite, close_interiors)
polygonize(input, out, simplify, min_size, max_size, overwrite, close_interiors)

inference.add_command(inference_download)
inference.add_command(inference_polygonize)
Expand Down
4 changes: 2 additions & 2 deletions src/ftw_cli/polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .cfg import SUPPORTED_POLY_FORMATS_TXT


def polygonize(input, out, simplify, min_size, overwrite, close_interiors):
def polygonize(input, out, simplify, min_size, max_size, overwrite, close_interiors):
"""Polygonize the output from inference."""

print(f"Polygonizing input file: {input}")
Expand Down Expand Up @@ -103,7 +103,7 @@ def polygonize(input, out, simplify, min_size, overwrite, close_interiors):
perimeter = geom_proj_meters.length

# Only include geometries that meet the minimum size requirement
if area < min_size:
if area < min_size or area > max_size:
continue

rows.append({
Expand Down

0 comments on commit d81587d

Please sign in to comment.