【问题标题】:converting from coordinate data to latitude and longitude in R?从坐标数据转换为R中的纬度和经度?
【发布时间】:2017-03-21 02:10:44
【问题描述】:

我一直在使用以下代码读取人口普查区数据并为每个人口普查区生成质心数据。我想从中提取纬度和经度,以便通过 Foursqaure API 进行一些采样,该 API 需要纬度和经度。我注意到这段代码给了我与纬度经度不同的坐标系。知道我如何能够提取纬度经度是转换坐标还是通过不同的函数?

#load libraries-----------------------------
library(rgdal)
library(sp)
library(GISTools)
library(ggplot2)

#load census tact file------------------------
tracts = readOGR("nycb2010.shp", layer="nycb2010")

#extract centroids
centroids = as.data.frame(getSpPPolygonsLabptSlots(tracts))

#map new data
ggplot() +  geom_polygon(data=tracts, aes(x=long, y=lat, group=group), fill="black", colour="grey90", alpha = 1)+
  geom_point(data=centroids, aes(x=V1, y=V2, group = 1, color = 'red'), size = .1)

【问题讨论】:

    标签: r gis rgdal


    【解决方案1】:

    您可以使用函数spTransform 来更改空间数据的坐标系,如下所示:

    library(sp)
    library(rgdal)
    
    lat_long = CRS("+init=epsg:4326") 
    tracts_lat_long <- spTransform(tracts, lat_long)
    
    proj4string(tracts_lat_long)
    [1] "+init=epsg:3035 +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
    

    【讨论】:

    • 没关系,我意识到我没有使用新变量是多么愚蠢。谢谢!
    猜你喜欢
    • 2016-10-09
    • 2021-07-18
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 2010-11-14
    相关资源
    最近更新 更多