-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f551356
commit 914f3d7
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: "Using buffers vs 'within distance' approaches" | ||
author: Olivier | ||
date: "2022-04-10" | ||
slug: geocompr-solutions | ||
categories: [vignette] | ||
tags: [geocompr2, buffers, rstats] | ||
draft: true | ||
--- | ||
|
||
This post explores two ways of calculating whether or not objects are within a certain distance of another object. | ||
This may sound rather abstract and the situation is perhaps best illustrated with reference to a simple reproducible example starting with (psuedo) randomly located points. | ||
|
||
```{r} | ||
library(sf) | ||
library(dplyr) | ||
library(tmap) | ||
set.seed(2022) | ||
point_locations = data.frame( | ||
x = rnorm(n = 100, mean = 0, sd = 1), | ||
y = rnorm(n = 100, mean = 0, sd = 1), | ||
n = 1:100 | ||
) %>% | ||
st_as_sf(coords = c("x", "y")) | ||
target_points = data.frame( | ||
x = rnorm(n = 5, mean = 0, sd = 1), | ||
y = rnorm(n = 5, mean = 0, sd = 1), | ||
n = 1:5 | ||
) %>% | ||
st_as_sf(coords = c("x", "y")) | ||
target_buffers = st_buffer(target_points, dist = 1) | ||
``` | ||
|
||
```{r} | ||
tm_shape(point_locations) + | ||
tm_dots() + | ||
tm_shape(target_buffers) + | ||
tm_borders() | ||
``` |