0

I am new to the platform, my issue:

I have a dataset of Amsterdam with 500 dots (gps coordinates - longitude, latitude).

I would like to identify the dots, who are outside the centre of Amsterdam. The gps coordinates of centre of Amsterdam is latitude: 52.37 longitude: 4.88. I want a radius of 3 km.

Target picture

camille
  • 16,432
  • 18
  • 38
  • 60
  • 2
    Please [see here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to post a question that includes code and data that folks here can use to help you – camille May 04 '18 at 14:16

1 Answers1

0

There are many ways to do it, here is one.

amst <- matrix(c(52.37, 4.88), ncol=2)
points <- data.frame(longitude=..., latitude=..., anything=..., else=..., here=...)
some_limit <- 3000 # defaults to meters
inside <- geosphere::distHaversine(amst, points[c("longitude","latitude")]) < some_limit
points[inside,,drop=FALSE] # all points inside

But ultimately this incomplete answer would be much better informed when you provide sample data. Your previous efforts and perhaps some context are best informed by you showing any code you've tried; sometimes lack of code suggests "please code this for me for free", though that can often be jumping to conclusions when you have no idea.

Here is complete MWE, using a 30km radius around Amsterdam.

library(maps)
library(mapdata)
library(ggplot2)
library(geosphere)

neth <- map_data('worldHires', 'Netherlands')
amst <- data.frame(long=4.88, lat=52.37)

n <- 500
set.seed(2)
points <- data.frame(
  long = amst$long + runif(n, min=-1, max=+1),
  lat = amst$lat + runif(n, min=-1, max=+1)
)
some_limit <- 30000 # meters
points$inside <- distHaversine(amst, points) < some_limit

ggplot() +
  geom_polygon(data=neth, aes(x=long, y=lat, group=group)) +
  coord_fixed(1.3) +
  geom_point(data=amst, aes(x=long, y=lat), color='green', size=5) +
  geom_point(data=points, aes(x=long, y=lat, color=inside))

points around Amsterdam

r2evans
  • 141,215
  • 6
  • 77
  • 149