Skip to content

Commit

Permalink
docs(blog): update geospatial - no need to_array()
Browse files Browse the repository at this point in the history
  • Loading branch information
ncclementi authored and gforsyth committed Jan 25, 2024
1 parent 7ad32b1 commit 78434a0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions docs/posts/ibis-duckdb-geospatial/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ boroughs
```

```{python}
boroughs.filter(boroughs.geom.intersects(broad_station.select(broad_station.geom).to_array()))
boroughs.filter(_.geom.intersects(broad_station.geom))
```

### `d_within` (ST_DWithin)
Expand All @@ -133,15 +133,10 @@ streets
Using the deferred API, we can check which streets are within `d=10` meters of distance.

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

::: {.callout-note}
In the previous query, `streets` and `broad_station` are different tables. We use [`to_array()`](../../reference/expression-tables.qmd#ibis.expr.types.relations.Table.to_array) to generate a
scalar subquery from a table with a single column (whose shape is scalar).
:::

To visualize the findings, we will convert the tables to GeoPandas DataFrames.

```{python}
Expand Down Expand Up @@ -201,7 +196,7 @@ To find if there were any homicides in that area, we can find where the polygon
200 meters buffer to our "Broad St" station point intersects with the geometry column in our homicides table.

```{python}
h_near_broad = homicides.filter(_.geom.intersects(broad_station.select(_.geom.buffer(200)).to_array()))
h_near_broad = homicides.filter(_.geom.intersects(broad_station.geom.buffer(200)))
h_near_broad
```

Expand All @@ -210,7 +205,7 @@ data we can't tell the street near which it happened. However, we can check if t
distance of a street.

```{python}
h_street = streets.filter(_.geom.d_within(h_near_broad.select(_.geom).to_array(), 2))
h_street = streets.filter(_.geom.d_within(h_near_broad.geom, 2))
h_street
```

Expand Down

0 comments on commit 78434a0

Please sign in to comment.