Extract address components from coordiantes

后端 未结 3 605
有刺的猬
有刺的猬 2021-01-27 05:15

I\'m trying to reverse geocode with R. I first used ggmap but couldn\'t get it to work with my API key. Now I\'m trying it with googleway.

newframe[,c("Front         


        
3条回答
  •  Happy的楠姐
    2021-01-27 05:32

    You can use ggmap:revgeocode easily; look below:

    library(ggmap)
    df <- cbind(df,do.call(rbind,
            lapply(1:nrow(df),
              function(i) 
                revgeocode(as.numeric(
                  df[i,2:1]), output = "more")      
                    [c("administrative_area_level_1","locality","postal_code","address")])))
    
    #output:
    df
    #   Front.lat Front.long administrative_area_level_1  locality
    #   1 -37.82681   144.9592                    Victoria Southbank
    #   2 -37.82681   145.9592                    Victoria    Noojee
    #     postal_code                                     address
    #   1        3006 45 Clarke St, Southbank VIC 3006, Australia
    #   2        3833 Cec Dunns Track, Noojee VIC 3833, Australia
    

    You can add "route" and "street_number" to the variables that you want to extract but as you can see the second address does not have street number and that will cause an error.

    Note: You may also use sub and extract the information from the address.

    Data:

    df <- structure(list(Front.lat = c(-37.82681, -37.82681), Front.long = 
          c(144.9592, 145.9592)), .Names = c("Front.lat", "Front.long"), class = "data.frame", 
          row.names = c(NA, -2L))
    

提交回复
热议问题