【发布时间】:2018-04-03 11:24:01
【问题描述】:
我只想通过 R 中的 TwitteR 包从美国检索推文。在 SearchTwitteR 函数的解释中它只说:
对于地理编码参数,值以纬度、经度、半径的格式给出,其中半径可以以 mi(英里)或 km(公里)为单位。例如
geocode='37.781157,-122.39720,1mi'."
但我不想从具有半径的特定地方进行过滤,我想要整个国家,美国。 有没有人对我有好的建议?
【问题讨论】:
我只想通过 R 中的 TwitteR 包从美国检索推文。在 SearchTwitteR 函数的解释中它只说:
对于地理编码参数,值以纬度、经度、半径的格式给出,其中半径可以以 mi(英里)或 km(公里)为单位。例如
geocode='37.781157,-122.39720,1mi'."
但我不想从具有半径的特定地方进行过滤,我想要整个国家,美国。 有没有人对我有好的建议?
【问题讨论】:
这可能无法回答您的问题,但如果您有纬度和经度列表并且需要确定它们是否在给定区域内,那么这应该会有所帮助。
这个类似的问题在这里得到了解答:Checking if Longtitude/Latitude within Greater Toronto Area in R
rgdal 和 sp 包可以映射一个点并测试它是否在给定的形状文件中,而不是地理编码。美国人口普查局:https://www.census.gov/geo/maps-data/data/cbf/cbf_nation.html
#dataframe of the points to test.
myTestDF <- data.frame(MyDate = c("USA", "Canada"),
latitude = c(37.781157, 43.8292),
longitude = c(-122.39720, -79.6563))
#Load the required library
library(rgdal)
#Download shape file from open data site and unzip contents into the working directory
#Read the shape file
USA<- readOGR(".", "cb_2016_us_nation_20m")
myTestPoints <- myTestDF
coordinates(myTestPoints) <- ~ longitude + latitude
proj4string(myTestPoints) <- proj4string(USA)
#over test to see if myTestPoints in the USA shapefile
cbind(myTestDF, over(myTestPoints, USA))
【讨论】: