2017-11-16 13 views
0

나는지도상의 점 주위에 버퍼를 플로팅하려했지만, 버퍼가 이처럼 올바른 장소에 나타나지 않습니다.지도상의 점 주위에 버퍼 놓기 - SFF

Faulty R Map

정확한 위치는 캘리포니아에 있습니다.

library(tigris) 
library(sf) 
library(tidyverse) 

projection <- 102003 

options(tigris_use_cache = TRUE) 
county_polys <- counties(class = 'sf') %>% 
    filter(STATEFP %in% c('06','41','53','04','16','32','49')) %>% 
    st_transform(projection) 

    centroids <- county_polys %>% 
    as_tibble %>% select(INTPTLON,INTPTLAT) %>% 
    mutate(
    INTPTLON = as.double(INTPTLON), 
    INTPTLAT = as.double(INTPTLAT)) %>% 
    st_as_sf(coords = c('INTPTLON','INTPTLAT'), crs = projection) 

pt <- centroids[2,] 
pt_buffer <- st_buffer(pt,150000) 


ggplot() + geom_sf(data = county_polys) + geom_sf(data = pt_buffer,color = 'red') 

답변

1

우리는 오류를 방지하기 위해 중심을 얻기 위해 st_centroid 기능을 사용할 수 있습니다 :

여기 내 코드입니다. sf 개체를 다른 클래스로 변환 할 필요가 없습니다.

# This is the only thing I changed from your original code 
# Get the centroid by st_centroid 
centroids <- county_polys %>% st_centroid() 

pt <- centroids[2,] 
pt_buffer <- st_buffer(pt,150000) 

ggplot() + geom_sf(data = county_polys) + geom_sf(data = pt_buffer,color = 'red') 

enter image description here