Skip to content

Commit

Permalink
Add argument to CLI search to use vector file (geojson) as filter
Browse files Browse the repository at this point in the history
  • Loading branch information
adehecq committed Sep 19, 2024
1 parent aa34a44 commit c28f553
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ def test_spatial_filter_geojson(self):
],
}
sfg = filt.SpatialFilterGeoJSON(shape)
assert sfg["filterType"] == "geoJson"
assert isinstance(sfg["geoJson"], filt.GeoJson)
assert sfg["filterType"] == "geojson"
assert isinstance(sfg["geojson"], filt.GeoJson)

def test_spatial_filter_from_file(self):
"Test the SpatialFilterGeoJSON.from_file method"
Expand All @@ -300,8 +300,8 @@ def test_spatial_filter_from_file(self):
with TemporaryDirectory() as tmp_dir:
gdf.to_file(os.path.join(tmp_dir, "shape.geojson"), driver="GeoJSON")
sfg = filt.SpatialFilterGeoJSON.from_file(os.path.join(tmp_dir, "shape.geojson"))
assert sfg["filterType"] == "geoJson"
assert isinstance(sfg["geoJson"], filt.GeoJson)
assert sfg["filterType"] == "geojson"
assert isinstance(sfg["geojson"], filt.GeoJson)

def test_spatial_filter_mbr(self):
"Test the SpatialFilterMbr class"
Expand Down
9 changes: 8 additions & 1 deletion usgsxplore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def cli() -> None:
nargs=4,
help="Bounding box (xmin, ymin, xmax, ymax).",
)
@click.option(
"-g",
"--geojson",
type=click.Path(file_okay=True),
help="GeoJSON file to use for spatial filter",
)
@click.option("-c", "--clouds", type=click.INT, help="Max. cloud cover (1-100).")
@click.option(
"-i",
Expand All @@ -156,6 +162,7 @@ def search(
output: str | None,
location: tuple[float, float] | None,
bbox: tuple[float, float, float, float] | None,
geojson: str | None,
clouds: int | None,
interval_date: tuple[str, str] | None,
filter: str | None, # pylint: disable=redefined-builtin
Expand All @@ -167,7 +174,7 @@ def search(
"""
api = API(username, password=password, token=token)
scene_filter = SceneFilter.from_args(
location=location, bbox=bbox, max_cloud_cover=clouds, date_interval=interval_date, meta_filter=filter
location=location, bbox=bbox, g_file=geojson, max_cloud_cover=clouds, date_interval=interval_date, meta_filter=filter
)

try:
Expand Down
4 changes: 2 additions & 2 deletions usgsxplore/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def __init__(self, shape: dict):
:param shape: Input shape as a geojson-like dict.
"""
self["filterType"] = "geoJson"
self["geoJson"] = GeoJson(shape)
self["filterType"] = "geojson"
self["geojson"] = GeoJson(shape)

@classmethod
def from_file(cls, file_path: str):
Expand Down

0 comments on commit c28f553

Please sign in to comment.