Skip to content

Improve fit_geometry ergonomics for ee.Geometry inputs #310

@jdbcode

Description

@jdbcode

Problem
xee.helpers.fit_geometry currently expects a shapely geometry input. When users pass an ee.Geometry, the failure path is confusing and does not clearly indicate the expected conversion.

Current behavior

  • fit_geometry assumes shapely-compatible geometry input.
  • Passing an Earth Engine geometry (for example ee.Geometry) leads to downstream errors that are not actionable.

User pain
This mismatch comes up repeatedly when users and agents move between Earth Engine-native and shapely-based workflows. The object boundary is easy to cross accidentally, and current errors increase debugging time.

Conversion that works today
shapely.geometry.shape(ee_geom.getInfo())

Proposed solutions

  1. Add guarded auto-conversion in fit_geometry for ee-like inputs.
  • Detect ee-like objects via duck typing, for example presence of getInfo.
  • Attempt narrow conversion with shapely.geometry.shape(obj.getInfo()).
  • On failure, raise a clear TypeError with explicit guidance.
  1. If auto-conversion is not accepted, improve error messaging.
  • Raise a clear TypeError that includes the exact conversion snippet:
    shapely.geometry.shape(ee_geom.getInfo()).
  1. Add docs coverage.
  • Add explicit examples and guidance in quickstart, open_dataset docs, and FAQ.

Non-goals and risk notes

  • Do not add a hard Earth Engine dependency in helpers.
  • Do not use broad exception swallowing that hides real geometry issues.
  • Keep behavior predictable for non-EE inputs.

Acceptance criteria

  • Shapely input continues to work unchanged.
  • ee-like input either auto-converts successfully or fails with a clear TypeError containing conversion guidance.
  • Error message explicitly states expected type and includes conversion snippet.
  • Documentation includes at least one end-to-end EE to shapely conversion example.
  • Changelog notes the ergonomics improvement.

Test ideas

  • Unit test for existing shapely path.
  • Unit test for ee-like mock object with valid getInfo payload.
  • Unit test for ee-like object with invalid getInfo payload, asserting clear TypeError.
  • Unit test for unrelated input type asserting precise TypeError.
  • Docs example validation to prevent drift.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions