Skip to content

Commit

Permalink
chore: add broad station near streets plot
Browse files Browse the repository at this point in the history
  • Loading branch information
ncclementi committed Dec 8, 2023
1 parent d0084aa commit faa1525
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions docs/posts/ibis-duckdb-geospatial/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,39 @@ streets
Using the deferred API, we can check which streets are within `d=10` meters of distance.

```{python}
streets.filter(_.geom.d_within(broad_station.select(_.geom).to_array(), 10))
sts_near_broad =streets.filter(_.geom.d_within(broad_station.select(_.geom).to_array(), 10))
sts_near_broad
```

To visualize this we will convert our tables to Geopandas dataframes. We need to do this because,
at the moment, DuckDB geometries are not capable to store SRID information. By converting to
Geopandas we can assign a `crs` and make some nice plots.

```{python}
broad_station_gdf = broad_station.to_pandas()
broad_station_gdf.crs = "EPSG:26918"
sts_near_broad_gdf = sts_near_broad.to_pandas()
sts_near_broad_gdf.crs = "EPSG:26918"
streets_gdf = streets.to_pandas()
streets_gdf.crs = "EPSG:26918"
```

```{python}
#visualize multiple layers
import leafmap.deckgl as leafmap
```

```{python}
m = leafmap.Map()
m.add_vector(broad_station_gdf, get_fill_color='blue')
m.add_vector(sts_near_broad_gdf,get_color='red', opacity=0.5)
m.add_vector(streets_gdf, get_color='grey', zoom_to_layer=False, opacity=0.3)
m
```

![broad_station_streets](broad_station_streets.png)

### `buffer` (ST_Buffer)

Expand Down Expand Up @@ -164,6 +193,21 @@ distance of a street and get that information.
streets.filter(_.geom.d_within(h_near_broad.select(_.geom).to_array(), 2))
```


# TEST
```{python}
st_gdf = streets.to_pandas()
st_gdf.crs = "EPSG:26918"
import leafmap
import leafmap.deckgl as leafmap
m = leafmap.Map()
m.add_vector(st_gdf)
m
```


## Functions supported and next steps

At the moment in Ibis we have support for around thirty geospatial functions for the DuckDB and we will add some more
Expand Down

0 comments on commit faa1525

Please sign in to comment.