Skip to content

Commit

Permalink
Allow non-compliant geoarrow CRS metadata (#369)
Browse files Browse the repository at this point in the history
Lonboard currently throws an exception on the input data from the latest
main of geoarrow-rs because it exposes metadata of the type `{"crs":
null, "edges": null}`, and we were trying to construct `CRS(None)`.
  • Loading branch information
kylebarron authored Feb 14, 2024
1 parent 438eb3b commit 250f9f9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lonboard/_geoarrow/ops/reproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,21 @@ def reproject_column(
max_workers: The maximum number of threads to use. Defaults to None.
"""
extension_type_name = field.metadata[b"ARROW:extension:name"]
extension_metadata = json.loads(field.metadata[b"ARROW:extension:metadata"])
extension_metadata_value = field.metadata[b"ARROW:extension:metadata"]

# Note: According to the spec, if the metadata key exists, its value should never be
# `null` or an empty dict, but we still check for those to be safe
if not extension_metadata_value:
return field, column

extension_metadata = json.loads(extension_metadata_value)
crs_str = extension_metadata["crs"]

# Note: According to the spec, the CRS key should never be set to `null`, but we
# still check for it to be safe (and geoarrow-rs currently creates invalid metadata)
if crs_str is None:
return field, column

existing_crs = CRS(crs_str)

if existing_crs == to_crs:
Expand Down

0 comments on commit 250f9f9

Please sign in to comment.