forked from developmentseed/lonboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_layer.py
137 lines (101 loc) · 4.29 KB
/
test_layer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import geodatasets
import geopandas as gpd
import numpy as np
import pyarrow as pa
import pytest
import shapely
from pyogrio.raw import read_arrow
from traitlets import TraitError
from lonboard import (
BitmapLayer,
Map,
PointCloudLayer,
ScatterplotLayer,
SolidPolygonLayer,
viz,
)
from lonboard._geoarrow.geopandas_interop import geopandas_to_geoarrow
from lonboard.layer_extension import DataFilterExtension
def test_accessor_length_validation():
"""Accessor length must match table length"""
points = shapely.points([1, 2], [3, 4])
gdf = gpd.GeoDataFrame(geometry=points)
with pytest.raises(TraitError, match="same length as table"):
_layer = ScatterplotLayer.from_geopandas(gdf, get_radius=np.array([1]))
with pytest.raises(TraitError, match="same length as table"):
_layer = ScatterplotLayer.from_geopandas(gdf, get_radius=np.array([1, 2, 3]))
_layer = ScatterplotLayer.from_geopandas(gdf, get_radius=np.array([1, 2]))
def test_accessor_length_validation_extension():
"""Accessor length must match table length"""
points = shapely.points([1, 2], [3, 4])
gdf = gpd.GeoDataFrame(geometry=points)
extension = DataFilterExtension()
with pytest.raises(TraitError, match="same length as table"):
_layer = ScatterplotLayer.from_geopandas(
gdf, extensions=[extension], get_filter_value=np.array([1])
)
with pytest.raises(TraitError, match="same length as table"):
_layer = ScatterplotLayer.from_geopandas(
gdf, extensions=[extension], get_filter_value=np.array([1, 2, 3])
)
_layer = ScatterplotLayer.from_geopandas(
gdf, extensions=[extension], get_radius=np.array([1, 2])
)
def test_layer_fails_with_unexpected_argument():
points = shapely.points([1, 2], [3, 4])
gdf = gpd.GeoDataFrame(geometry=points)
with pytest.raises(TypeError, match="Unexpected keyword argument"):
_layer = ScatterplotLayer.from_geopandas(gdf, unknown_keyword="foo")
def test_layer_outside_4326_range():
# Table outside of epsg:4326 range
points = shapely.points([1000000, 2000000], [3000000, 4000000])
gdf = gpd.GeoDataFrame(geometry=points)
with pytest.raises(ValueError, match="outside of WGS84 bounds"):
_layer = ScatterplotLayer.from_geopandas(gdf)
def test_layer_from_geoarrow_pyarrow():
ga = pytest.importorskip("geoarrow.pyarrow")
points = gpd.GeoSeries(shapely.points([1, 2], [3, 4]))
# convert to geoarrow.pyarrow Table (currently requires to ensure interleaved
# coordinates manually)
points = ga.with_coord_type(ga.as_geoarrow(points), ga.CoordType.INTERLEAVED)
table = pa.table({"geometry": points})
_layer = ScatterplotLayer(table=table)
def test_layer_wkb_geoarrow():
path = geodatasets.get_path("naturalearth.land")
meta, table = read_arrow(path)
_layer = SolidPolygonLayer(table=table)
def test_layer_wkb_geoarrow_wrong_geom_type():
path = geodatasets.get_path("naturalearth.land")
meta, table = read_arrow(path)
# Use regex as set will have unknown ordering between multipoint and point
with pytest.raises(
TraitError,
match=r"Expected one of geoarrow\..*point, geoarrow\..*point geometry types",
):
_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(
image="https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf-districts.png",
bounds=[-122.5190, 37.7045, -122.355, 37.829],
)
_m = Map(layer)
def test_point_cloud_layer():
points = shapely.points([0, 1], [2, 3], [4, 5])
gdf = gpd.GeoDataFrame(geometry=points)
_layer = PointCloudLayer.from_geopandas(gdf)