From 353cadfe2f6866b18a3a40ef0b00fb1817f1b5f8 Mon Sep 17 00:00:00 2001 From: Michael Dorman Date: Thu, 26 Oct 2023 11:07:44 +0300 Subject: [PATCH] ch04 comments --- 04-geometry-operations.qmd | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/04-geometry-operations.qmd b/04-geometry-operations.qmd index 75de58c7..0a5712df 100644 --- a/04-geometry-operations.qmd +++ b/04-geometry-operations.qmd @@ -261,7 +261,7 @@ In both cases, the method is applied on the `GeoSeries` part, returning a just t -Affine transformations of `GeoSeries` can be done using the `.affine_transform` method, which is a wrapper around the `shapely.affinity.affine_transform` function. +Affine transformations of `GeoSeries` can be done using the [`.affine_transform`](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.affine_transform.html) method, which is a wrapper around the `shapely.affinity.affine_transform` function. As [documented](https://shapely.readthedocs.io/en/stable/manual.html#shapely.affinity.affine_transform), a 2D affine transformation requires a six-parameter list `[a,b,d,e,xoff,yoff]` which represents the following equations for transforming the coordinates (@eq-affine1 and @eq-affine2)/ $$ @@ -279,7 +279,7 @@ There are also simplified `GeoSeries` [methods](https://geopandas.org/en/stable/ - `.rotate(angle, origin='center', use_radians=False)` - `.skew(angle, origin='center', use_radians=False)` -For example, *shifting* only requires the $x_{off}$ and $y_{off}$, using `.translate`. +For example, *shifting* only requires the $x_{off}$ and $y_{off}$, using [`.translate`](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.translate.html). The code below shifts the y-coordinates of `nz` by 100 $km$ to the north, but leaves the x-coordinates untouched. @@ -295,20 +295,25 @@ nz_shift Scaling enlarges or shrinks objects by a factor, and can be applied either globally or locally. Global scaling increases or decreases all coordinates values in relation to the origin coordinates, while keeping all geometries topological relations intact. -**geopandas** implements local scaling using the `.scale` method. +**geopandas** implements local scaling using the [`.scale`](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.scale.html) method. + Local scaling treats geometries independently and requires points around which geometries are going to be scaled, e.g., centroids. In the example below, each geometry is shrunk by a factor of two around the centroids (@fig-affine-transformations (b)). To achieve that, we pass the `0.5` and `0.5` scaling factors (for x and y, respectively), and the `'centroid'` option for the point of origin. -(Other than `'centroid'`, it is possible to use `'center'`, for the bounding box center, or specific point coordinates.) + ```{python} nz_scale = nz.scale(0.5, 0.5, origin='centroid') nz_scale ``` -Rotating the geometries can be done using the `.rotate` method. +::: callout-note +When setting the `origin` in `.scale`, other than `'centroid'` it is possible to use `'center'`, for the bounding box center, or specific point coordinates, such as `(0,0)`. +::: + +Rotating the geometries can be done using the [`.rotate`](https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.rotate.html) method. When rotating, we need to specify the rotation angle (positive values imply clockwise rotation) and the `origin` points (using the same options as in `scale`). For example, the following expression rotates `nz` by 30 degrees counter-clockwise, around the geometry centroids. @@ -339,6 +344,7 @@ nz_rotate.plot(ax=base, color='red', edgecolor='darkgrey'); ``` + ### Pairwise geometry-generating operations {#sec-clipping}