Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/examples/spatial_join.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Spatial polars can perform a [spatial join](../SpatialFrame.md#spatial_polars.sp

To demonstrate how we can join data together from two dataframes spatially using spatial polars, we'll join some lake polygons with some administrative boundaries to see which lakes are in which countries.

```py title="Spatial Join" hl_lines="21-26" html="false"
```python title="Spatial Join" hl_lines="21-26"
--8<-- "spatial_join.py"
```

Expand All @@ -39,6 +39,10 @@ To demonstrate how we can join data together from two dataframes spatially using
9. Selecting the columns to make the lake name and SOVEREIGNT columns show up before the lake and boundary geometry columns.
10. Sort by the lake name just to make the results look nice in our output dataframe.

```python exec="on" result="text"
--8<-- "spatial_join.py"
```

Of the original 24 lakes and 177 bounaries, we have 36 rows now, beacause there are a few that cross the borders of the boundaries and were joined to more than one. Lake Victoria is one of these lakes, it intersects both Kenya and Uganda

The resulting dataframe has a row for each lake name/geometry from the lakes dataframe and the SOVEREIGNT and geometry_boundary from the boundary df where the lake intersects an admin boundary.
Expand Down
13 changes: 7 additions & 6 deletions docs/snippets/spatial_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

from spatial_polars import scan_spatial

lake_df = (
lake_lf = (
scan_spatial("https://naciscdn.org/naturalearth/110m/physical/ne_110m_lakes.zip")
.select("name", "geometry")
.collect(engine="streaming")
) # (1)!
print(f"There are {len(lake_df)} rows in lake_df")

boundary_df = (
boundary_lf = (
scan_spatial(
"https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip"
"https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip",
)
.select("SOVEREIGNT", "geometry")
.collect(engine="streaming")
) # (2)!

lake_df, boundary_df = pl.collect_all([lake_lf, boundary_lf])
print(f"There are {len(lake_df)} rows in lake_df")
print(f"There are {len(boundary_df)} rows in boundary_df")

lake_boundary_df = (
lake_df.spatial.join( # (3)!
other=boundary_df, # (4)!
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "spatial-polars"
version = "0.2.3" # dont forget __init__.py and uv lock
version = "0.2.4" # dont forget __init__.py and uv lock
description = "A package that extends polars for working with geospatial data."
readme = "README.md"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion src/spatial_polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"spatial_series_dtype",
]

__version__ = "0.2.3" # dont forget pyproject.toml and uv lock
__version__ = "0.2.4" # dont forget pyproject.toml and uv lock
12 changes: 6 additions & 6 deletions src/spatial_polars/spatialframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,14 @@ def to_scatterplotlayer(
)
validate_width_and_radius_input(self._df, line_width)
validate_width_and_radius_input(self._df, radius)
fill_color = self._make_color_array(
fill_color = fill_color or self._make_color_array(
fill_cmap_col,
fill_cmap_type,
fill_cmap,
fill_alpha,
normalize_cmap_col=fill_normalize_cmap_col,
)
line_color = self._make_color_array(
line_color = line_color or self._make_color_array(
line_cmap_col,
line_cmap_type,
line_cmap,
Expand Down Expand Up @@ -1178,15 +1178,15 @@ def to_pathlayer(
cmap_type,
cmap,
)
validate_width_and_radius_input(self._df, width)
color = self._make_color_array(
color = color or self._make_color_array(
cmap_col,
cmap_type,
cmap,
alpha,
normalize_cmap_col=normalize_cmap_col,
)

validate_width_and_radius_input(self._df, width)
if isinstance(width, str):
width = self._df.select(c(width)).to_series().to_numpy()

Expand Down Expand Up @@ -1371,14 +1371,14 @@ def to_polygonlayer(
)
validate_width_and_radius_input(self._df, line_width)

fill_color = self._make_color_array(
fill_color = fill_color or self._make_color_array(
fill_cmap_col,
fill_cmap_type,
fill_cmap,
fill_alpha,
normalize_cmap_col=fill_normalize_cmap_col,
)
line_color = self._make_color_array(
line_color = line_color or self._make_color_array(
line_cmap_col,
line_cmap_type,
line_cmap,
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading