【问题标题】:How to implement a Geo Code Filter of the USA when retrieving Tweets via the TwitteR package in R通过 R 中的 TwitteR 包检索推文时如何实现美国的地理代码过滤器
【发布时间】:2018-04-03 11:24:01
【问题描述】:

我只想通过 R 中的 TwitteR 包从美国检索推文。在 SearchTwitteR 函数的解释中它只说:

对于地理编码参数,值以纬度、经度、半径的格式给出,其中半径可以以 mi(英里)或 km(公里)为单位。例如geocode='37.781157,-122.39720,1mi'."

但我不想从具有半径的特定地方进行过滤,我想要整个国家,美国。 有没有人对我有好的建议?

【问题讨论】:

    标签: r twitter filter geocode


    【解决方案1】:

    这可能无法回答您的问题,但如果您有纬度和经度列表并且需要确定它们是否在给定区域内,那么这应该会有所帮助。

    这个类似的问题在这里得到了解答: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))
    

    【讨论】:

      猜你喜欢
      • 2012-07-25
      • 2011-11-29
      • 2014-01-07
      • 1970-01-01
      • 2021-07-25
      • 2011-03-06
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      相关资源
      最近更新 更多