1

I have got a data frame / tibble, which contains the Lat/Long and Country for each data point. Currently, st_intersect is being used to output the row numbers for each row which intersect within the defined ring. The issue with this is that the function does not consider country, but I would like it to only consider rows which are within the ring AND of the same country. So I need to some how incorporate a country consideration when intersecting the points.

DATA

# A tibble: 3 × 3
  Country Longitude Latitude
  <chr>       <dbl>    <dbl>
1 France       5.74     45.2
2 France       5.74     45.2
3 Italy        5.74     45.2

CODE

myDist = 321869

data$UTMnum = ceiling((data$Longitude+180)/6)
data$UTMlet = if_else(data$Latitude>0,"N","S")
data$UTMZone = paste0(data$UTMnum,data$UTMlet)

data = st_as_sf(x = data,coords = c("Longitude","Latitude"),crs = 4326)

myCRS = st_crs(paste0("+proj=utm +zone=",
                          str_replace(str_replace("31N","S",""),"N",""),
                          if_else(grepl("S","31N")," +south",""),
                          " +datum=WGS84 +units=m +no_defs +type=crs"))

dataUTM = st_transform(data,myCRS)

myPoints_buffer = st_buffer(dataUTM,dist = myDist)

myPoints_intersections = st_intersects(dataUTM,dataUTM)

myPoints_intersections = lapply(myPoints_intersections,c)

myPoints_intersections

OUTPUT

[[1]]
[1] 1 2 3

[[2]]
[1] 1 2 3

[[3]]
[1] 1 2 3

However, I would like this to only show rows where the country is the same.

[[1]]
[1] 1 2

[[2]]
[1] 1 2

[[3]]
[1] 1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.