Skip to content

Commit

Permalink
Warn on missing CRS (#395)
Browse files Browse the repository at this point in the history
Closes #371
  • Loading branch information
kylebarron authored Feb 29, 2024
1 parent b701793 commit 209045c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lonboard/_geoarrow/ops/reproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from concurrent.futures import ThreadPoolExecutor
from functools import lru_cache, partial
from typing import Callable, Optional, Tuple, Union
from warnings import warn

import numpy as np
import pyarrow as pa
Expand All @@ -18,6 +19,13 @@
TransformerFromCRS = lru_cache(Transformer.from_crs)


def no_crs_warning():
warn(
"No CRS exists on data. "
"If no data is shown on the map, double check that your CRS is WGS84."
)


def reproject_table(
table: pa.Table,
*,
Expand All @@ -44,6 +52,7 @@ def reproject_table(

# geometry column exists in table but is not assigned a CRS
if b"ARROW:extension:metadata" not in geom_field.metadata:
no_crs_warning()
return table

new_field, new_column = reproject_column(
Expand All @@ -70,6 +79,7 @@ def reproject_column(
extension_type_name = field.metadata[b"ARROW:extension:name"]
crs_str = get_field_crs(field)
if crs_str is None:
no_crs_warning()
return field, column

existing_crs = CRS(crs_str)
Expand Down
24 changes: 23 additions & 1 deletion tests/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from pyogrio.raw import read_arrow
from traitlets import TraitError

from lonboard import BitmapLayer, Map, ScatterplotLayer, SolidPolygonLayer
from lonboard import BitmapLayer, Map, ScatterplotLayer, SolidPolygonLayer, viz
from lonboard._geoarrow.geopandas_interop import geopandas_to_geoarrow
from lonboard.layer_extension import DataFilterExtension


Expand Down Expand Up @@ -93,6 +94,27 @@ def test_layer_wkb_geoarrow_wrong_geom_type():
_layer = ScatterplotLayer(table=table)


def test_warning_no_crs_shapely():
points = shapely.points([0, 1, 2], [2, 3, 4])
with pytest.warns(match="No CRS exists on data"):
_ = viz(points)


def test_warning_no_crs_geopandas():
points = shapely.points([0, 1, 2], [2, 3, 4])
gdf = gpd.GeoDataFrame(geometry=points)
with pytest.warns(match="No CRS exists on data"):
_ = viz(gdf)


def test_warning_no_crs_arrow():
points = shapely.points([0, 1, 2], [2, 3, 4])
gdf = gpd.GeoDataFrame(geometry=points)
table = geopandas_to_geoarrow(gdf)
with pytest.warns(match="No CRS exists on data"):
_ = viz(table)


# Test layer types
def test_bitmap_layer():
layer = BitmapLayer(
Expand Down

0 comments on commit 209045c

Please sign in to comment.