Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent and non-standard CRS handling for geometry arguments in DataCube #671

Open
soxofaan opened this issue Nov 27, 2024 · 4 comments

Comments

@soxofaan
Copy link
Member

stumbled on this while working on #104:

if crs:
# TODO: don't warn when the crs is Lon-Lat like EPSG:4326?
warnings.warn(f"Geometry with non-Lon-Lat CRS {crs!r} is only supported by specific back-ends.")
# TODO #204 alternative for non-standard CRS in GeoJSON object?
epsg_code = normalize_crs(crs)
if epsg_code is not None:
# proj did recognize the CRS
crs_name = f"EPSG:{epsg_code}"
else:
# proj did not recognise this CRS
warnings.warn(f"non-Lon-Lat CRS {crs!r} is not known to the proj library and might not be supported.")
crs_name = crs
geometry["crs"] = {"type": "name", "properties": {"name": crs_name}}
return geometry

e.g. public facing from cube.aggregate_spatial(..., crs=...) and cube.mask_polygon(..., srs=...)

This CRS handling has some problems:

  • it's an ad-hoc, non-standard feature not present in official processes
  • it's inconsistent: sometimes it will apply (when geometry is client-side GeoJSON), sometimes it won't (e.g. back-end side vector cube)
  • it will ignore crs info already present in GeoJSON and will blindly overwrite it

I think we should get rid of this

@soxofaan
Copy link
Member Author

soxofaan commented Nov 27, 2024

@soxofaan
Copy link
Member Author

As far as I understand the threads above, the "crs" support mentioned above was originally targeted to the use case where the geometry is provided as shapely object (which has no explicit CRS info), which has to be converted to GeoJSON to be embedded in the process graph. Over time, a lot more geometry value types for geometries were added (e.g UDP parameters, vector cubes, load_url, ...), where it's impossible to attach that CRS to, so we now have a very inconsistent CRS handling situation.

@soxofaan
Copy link
Member Author

proposed solution:

  • stop supporting crs/srs arguments directly in aggregate_spatial, ... (because it's impossible to do it consistently). Instead throw exception pointing to proper way to do it (e.g. docs).
  • provide convenience function to support the conversion need from shapely to GeoJSON with custom CRS

So use cases that wanted to use shapely geometries with custom crs the old way:

cube = cube.aggregate_spatial(
    geometries=shapely_geometry,
    crs="EPSG:123456",
    ...
)

would have to change to something like

cube = cube.aggregate_spatial(
    geometries=shapely_to_geojson(shapely_geometry,  crs="EPSG:123456"),
    ...
)

@jdries
Copy link
Collaborator

jdries commented Nov 27, 2024

I would:

  • make sure that shapely geometry remains supported
  • add shapely geometry support to load_collection as well, the absence there is the most annoying inconsistency for me
  • improve documentation of crs keyword to state that it's actually deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants