[英]Converting a data frame to a spatial object
我正在嘗試在Shiny上發布地圖,但一直遇到此問題。
讓我們稱之為data.frame region
。 以下是各列:
library(mapedit)
library(mapview)
library(shiny)
library(leaflet)
library(leaflet.extras)
region$address
region$city
region$state
region$zip
region$county
region$xcol (these are the longitude coordinates)
region$ycol (these are the latitude coordinates)
但是,當我運行mapview(region)@map
,會產生以下錯誤:
錯誤:糟糕! 缺少xcol和/或ycol參數! 您可能希望turf_clean是一個空間對象。 但是,它屬於data.frame類。 要么將turf_clean轉換為空間對象,要么提供xcol和ycol。
我提供了x和y列,但仍然無法滿足我的需求。
庫sf
及其st_as_sf()
是一種將data.frame轉換為空間對象的方法。 crs
指的是基准面和投影,我只是在假設您的經/緯度相對於WGS84基准面的情況下猜測。 我相信投影是maps.google.com所使用的-網絡墨卡托輔助領域。
library(sf)
turf_clean <- st_as_sf(region, coords = c("xcol", "ycol"), crs = 4326)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.