File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,10 @@ def _from_geometry(
98
98
crs : Optional [Union [str , pyproj .CRS ]] = None ,
99
99
) -> Table :
100
100
other_col_names = [name for i , name in enumerate (rel .columns ) if i != geom_col_idx ]
101
- non_geo_table = Table .from_arrow (rel .select (* other_col_names ).arrow ())
101
+ if other_col_names :
102
+ non_geo_table = Table .from_arrow (rel .select (* other_col_names ).arrow ())
103
+ else :
104
+ non_geo_table = None
102
105
geom_col_name = rel .columns [geom_col_idx ]
103
106
104
107
# A poor-man's string interpolation check
@@ -142,7 +145,13 @@ def _from_geometry(
142
145
143
146
metadata = _make_geoarrow_field_metadata (EXTENSION_NAME .WKB , crs )
144
147
geom_field = geom_table .schema .field (0 ).with_metadata (metadata )
145
- return non_geo_table .append_column (geom_field , geom_table .column (0 ))
148
+ if non_geo_table is not None :
149
+ return non_geo_table .append_column (geom_field , geom_table .column (0 ))
150
+ else :
151
+ # Need to set geospatial metadata onto the Arrow table, because the table
152
+ # returned from duckdb has none.
153
+ new_schema = geom_table .schema .set (0 , geom_field )
154
+ return geom_table .with_schema (new_schema )
146
155
147
156
148
157
def _from_geoarrow (
Original file line number Diff line number Diff line change @@ -208,7 +208,6 @@ def test_create_table_as_custom_con():
208
208
209
209
210
210
def test_geometry_only_column ():
211
- # https://github.com/developmentseed/lonboard/issues/622
212
211
con = duckdb .connect ()
213
212
sql = f"""
214
213
INSTALL spatial;
@@ -222,3 +221,20 @@ def test_geometry_only_column():
222
221
223
222
m = viz (con .table ("data" ), con = con )
224
223
assert isinstance (m .layers [0 ], ScatterplotLayer )
224
+
225
+
226
+ def test_geometry_only_column_type_geometry ():
227
+ # For WKB parsing
228
+ pytest .importorskip ("shapely" )
229
+
230
+ # https://github.com/developmentseed/lonboard/issues/622
231
+ con = duckdb .connect ()
232
+ sql = f"""
233
+ INSTALL spatial;
234
+ LOAD spatial;
235
+ SELECT geom FROM ST_Read("{ cities_gdal_path } ");
236
+ """
237
+ query = con .sql (sql )
238
+
239
+ # Should create layer without erroring
240
+ _layer = ScatterplotLayer .from_duckdb (query , con )
You can’t perform that action at this time.
0 commit comments