Skip to content

Commit 209045c

Browse files
authored
Warn on missing CRS (#395)
Closes #371
1 parent b701793 commit 209045c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lonboard/_geoarrow/ops/reproject.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from concurrent.futures import ThreadPoolExecutor
66
from functools import lru_cache, partial
77
from typing import Callable, Optional, Tuple, Union
8+
from warnings import warn
89

910
import numpy as np
1011
import pyarrow as pa
@@ -18,6 +19,13 @@
1819
TransformerFromCRS = lru_cache(Transformer.from_crs)
1920

2021

22+
def no_crs_warning():
23+
warn(
24+
"No CRS exists on data. "
25+
"If no data is shown on the map, double check that your CRS is WGS84."
26+
)
27+
28+
2129
def reproject_table(
2230
table: pa.Table,
2331
*,
@@ -44,6 +52,7 @@ def reproject_table(
4452

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

4958
new_field, new_column = reproject_column(
@@ -70,6 +79,7 @@ def reproject_column(
7079
extension_type_name = field.metadata[b"ARROW:extension:name"]
7180
crs_str = get_field_crs(field)
7281
if crs_str is None:
82+
no_crs_warning()
7383
return field, column
7484

7585
existing_crs = CRS(crs_str)

tests/test_layer.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from pyogrio.raw import read_arrow
88
from traitlets import TraitError
99

10-
from lonboard import BitmapLayer, Map, ScatterplotLayer, SolidPolygonLayer
10+
from lonboard import BitmapLayer, Map, ScatterplotLayer, SolidPolygonLayer, viz
11+
from lonboard._geoarrow.geopandas_interop import geopandas_to_geoarrow
1112
from lonboard.layer_extension import DataFilterExtension
1213

1314

@@ -93,6 +94,27 @@ def test_layer_wkb_geoarrow_wrong_geom_type():
9394
_layer = ScatterplotLayer(table=table)
9495

9596

97+
def test_warning_no_crs_shapely():
98+
points = shapely.points([0, 1, 2], [2, 3, 4])
99+
with pytest.warns(match="No CRS exists on data"):
100+
_ = viz(points)
101+
102+
103+
def test_warning_no_crs_geopandas():
104+
points = shapely.points([0, 1, 2], [2, 3, 4])
105+
gdf = gpd.GeoDataFrame(geometry=points)
106+
with pytest.warns(match="No CRS exists on data"):
107+
_ = viz(gdf)
108+
109+
110+
def test_warning_no_crs_arrow():
111+
points = shapely.points([0, 1, 2], [2, 3, 4])
112+
gdf = gpd.GeoDataFrame(geometry=points)
113+
table = geopandas_to_geoarrow(gdf)
114+
with pytest.warns(match="No CRS exists on data"):
115+
_ = viz(table)
116+
117+
96118
# Test layer types
97119
def test_bitmap_layer():
98120
layer = BitmapLayer(

0 commit comments

Comments
 (0)