luzern_centroid <- st_centroid(luzern)ms_simplify()st_centroid() returns the center of mass β the balance point of the shapest_point_on_surface() always returns a point insidest_centroid(): Distance metrics, spatial analyticsst_point_on_surface(): Map labeling, feature samplingsf: applied directly to sfc objects using arithmetic operators| Operation | sf syntax | Effect |
|---|---|---|
| Shift | sfc + c(dx, dy) |
Move without changing shape |
| Scale | (sfc - p) * factor + p |
Grow or shrink around a point p |
| Rotate | (sfc - p) * R(ΞΈ) + center |
Rotate around a point p |
The same pattern applies to all three operations β only the transformation differs:
Transformations compose: shift first, then scale, then rotate gives a different result than the reverse order.
Closed book!
Do not use any external sources. Solve with your own ideas in groups
st_simplify() uses the Douglas-Peucker algorithm




st_simplify() processes each feature independentlyrmapshaper::ms_simplify() simplifies the whole layer at once β shared boundaries stay consistentst_centroid() returns the geometric centre of mass β useful for distance calculations and analytics, but it can fall outside the shape for concave or C-shaped geometries. Use st_point_on_surface() when you need a point guaranteed to lie inside.
Affine transformations (shift, scale, rotate) preserve shape and angles. All three follow the same pattern in sf: shift to the origin, apply the transformation, shift back. sf lets you do this with ordinary arithmetic directly on sfc objects. Transformations are not commutative β order matters.
st_simplify() reduces vertex count using the Douglas-Peucker algorithm: it recursively removes vertices that deviate less than tolerance Ξ΅ from the local baseline. It operates feature by feature, so shared boundaries between adjacent polygons can develop gaps and overlaps.
ms_simplify() (rmapshaper) uses the Visvalingam algorithm and processes the entire layer at once, keeping shared edges consistent. Prefer it whenever topology matters.