diff --git a/docs/examples/spatial_join.md b/docs/examples/spatial_join.md index 72ba9da..56addc0 100644 --- a/docs/examples/spatial_join.md +++ b/docs/examples/spatial_join.md @@ -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" ``` @@ -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. diff --git a/docs/snippets/spatial_join.py b/docs/snippets/spatial_join.py index d21c736..6abc9f0 100644 --- a/docs/snippets/spatial_join.py +++ b/docs/snippets/spatial_join.py @@ -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)! diff --git a/pyproject.toml b/pyproject.toml index b121538..b5b053a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/src/spatial_polars/__init__.py b/src/spatial_polars/__init__.py index 3c58648..489bc6a 100644 --- a/src/spatial_polars/__init__.py +++ b/src/spatial_polars/__init__.py @@ -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 diff --git a/src/spatial_polars/spatialframe.py b/src/spatial_polars/spatialframe.py index 5a550c0..b4f2179 100644 --- a/src/spatial_polars/spatialframe.py +++ b/src/spatial_polars/spatialframe.py @@ -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, @@ -1178,8 +1178,7 @@ 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, @@ -1187,6 +1186,7 @@ def to_pathlayer( 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() @@ -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, diff --git a/uv.lock b/uv.lock index 9bb67ac..1364631 100644 --- a/uv.lock +++ b/uv.lock @@ -3401,7 +3401,7 @@ wheels = [ [[package]] name = "spatial-polars" -version = "0.2.3" +version = "0.2.4" source = { editable = "." } dependencies = [ { name = "cloudpickle" },