Skip to content

Conversation

@ischneider
Copy link
Member

  • optional arg in filter creation
  • add support in CLI filter command
  • remove some superfluous respx.mock annotations

I considered adding this for the other CLI commands but this would have required significant reworking how geometry is handled, as we currently pass it along as a top-level item in the request and relation is only supported in a filter.

While it would be conceivable to unpack a user's filters and merge in a geometry filter, this felt beyond the scope of the issue.

In other words, with this MR, the only way to use relation via the CLI is to use planet data filter --geom=... --geom-relation=within | planet data search psscene --filter=-

Related Issue(s):

Closes #1204

Proposed Changes:

For inclusion in changelog (if applicable):

  1. Add relation support for geometry filter in data

PR Checklist:

  • This PR is as small and focused as possible
  • If this PR includes proposed changes for inclusion in the changelog, the title of this PR summarizes those changes and is ready for inclusion in the Changelog.
  • I have updated docstrings for function changes and docs in the 'docs' folder for user interface / behavior changes
  • This PR does not break any examples or I have updated them

- optional arg in filter creation
- add support in CLI filter command
- remove some superfluous respx.mock annotations

see #1204
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for specifying geometry relation types (intersects, contains, within, disjoint) when filtering data searches by geometry. Previously, only the default "intersects" relation was supported implicitly.

  • Added optional relation parameter to geometry_filter() function with validation
  • Added --geom-relation CLI option to the planet data filter command
  • Removed superfluous @respx.mock decorators from tests that don't require HTTP mocking

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
planet/data_filter.py Added optional relation parameter to geometry_filter() function with validation logic to ensure only valid relation types are accepted
planet/cli/data.py Added --geom-relation CLI option and removed the geom_to_filter callback function, now calling geometry_filter() directly in the filter command
tests/integration/test_data_cli.py Added test for geometry relation feature and removed unnecessary @respx.mock decorators from tests that don't make HTTP requests
Comments suppressed due to low confidence (1)

planet/data_filter.py:225

  • The docstring should clarify that the relation parameter is optional and provide more context. Consider updating line 225 to: "The GeometryFilter can be used to search for items with a footprint geometry that has the specified spatial relationship (intersects, contains, within, or disjoint) with the specified geometry. The default relationship is intersects."
    The GeometryFilter can be used to search for items with a footprint
    geometry which intersects with the specified geometry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

permission = data_filter.permission_filter() if permission else None
std_quality = data_filter.std_quality_filter() if std_quality else None

geometry = data_filter.geometry_filter(geom, geom_relation)
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The geometry_filter function is called unconditionally, but it will fail when geom is None (which happens when --geom is not specified). The removed geom_to_filter callback previously handled this by only calling geometry_filter when geom was not None. This should be changed to: geometry = data_filter.geometry_filter(geom, geom_relation) if geom else None

Suggested change
geometry = data_filter.geometry_filter(geom, geom_relation)
geometry = data_filter.geometry_filter(geom, geom_relation) if geom else None

Copilot uses AI. Check for mistakes.
Comment on lines +175 to +177
help="""Optional geometry search refinement, defaults to intersects.
May also be contains, within, or disjoint.""",
)
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text contains redundant information. It states "defaults to intersects" and then repeats "May also be contains, within, or disjoint" which doesn't include intersects in the list. The help text should clarify that intersects is one of the four options and is the default, for example: "Geometry search relation. Options are intersects (default), contains, within, or disjoint."

Suggested change
help="""Optional geometry search refinement, defaults to intersects.
May also be contains, within, or disjoint.""",
)
help="""Geometry search relation. Options are intersects (default), contains, within, or disjoint.""",
)

Copilot uses AI. Check for mistakes.


def geometry_filter(geom: dict) -> dict:
def geometry_filter(geom: dict, relation: str = None) -> dict:
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation should indicate that relation is Optional. Change relation: str = None to relation: Optional[str] = None to properly express that this parameter can be None.

Suggested change
def geometry_filter(geom: dict, relation: str = None) -> dict:
def geometry_filter(geom: dict, relation: Optional[str] = None) -> dict:

Copilot uses AI. Check for mistakes.
Comment on lines +293 to +301
def test_data_filter_geom_relation(request, invoke):
geom = request.getfixturevalue("geom_geojson")
geom_str = json.dumps(geom)
result = invoke(["filter", f'--geom={geom_str}', '--geom-relation=disjoint'])
assert result.exit_code == 0

and_filter = json.loads(result.output)
assert and_filter["config"][0]["relation"] == "disjoint"

Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case to verify the behavior when --geom-relation is specified without --geom. This should ideally be handled gracefully (either ignored or produce a clear error message).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add geometry relation optional arg to data_filter.geometry_filter

2 participants