将shapefile转换为R中的x,y,z(lat / lon coords)

时间:2018-06-05 21:24:17

标签: r shapefile

我有一个shapefile,在提取x,y,z组件时遇到问题。我还想将UT和Y转换为Lat和Lon。

最终我想

plot(x, y)
map(add=T)

并添加其他积分。

例如,你如何理解这一预测:

library(PBSmapping)

r <- importShapefile("~/Desktop/BIO_CA_KelpPersistent/BIO_CA_KelpPersistent.shp")
 str(r)

- attr(*, "prj")= chr "PROJCS[\"NAD_1983_California_Teale_Albers\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1"| __truncated__

更新

require(sf)
nc <- st_read("BIO_CA_KelpPersistent.shp")

nc_points <- st_coordinates(st_geometry(st_centroid(nc)))

xy <- project(nc_points, paste("+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +datum=NAD83 +units=m +no_defs", sep = ""), inverse=T)

plot(xy, ylim=c(32, 33), xlim=c(-119, -117))
map(add=T, lwd=2)

但遗漏了很多要点......我该如何正确索引?

谢谢!

1 个答案:

答案 0 :(得分:2)

我正在使用 // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'com.google.gms:google-services:4.0.1' } 包附带的示例数据集。使用sf我们不需要将几何类型转换为x和y列。如果您只需绘制图层,则可以执行以下操作:

sf

enter image description here

但是,如果必须转换为x和y列,则可以使用library(sf) # Load shapefile nc <- st_read(system.file("shape/nc.shp", package = "sf")) # Plot it without converting geometry to x, y columns plot(st_geometry(nc)) plot(st_geometry(st_centroid(nc)), add = TRUE)

st_coordinates

如果数据如下:

# Convert geometry to x, y columns
nc_points <- st_coordinates(st_geometry(st_centroid(nc)))

变成:

                    geometry
1  POINT (-81.49826 36.4314)
2 POINT (-81.12515 36.49101)
3 POINT (-80.68575 36.41252)
4  POINT (-76.0275 36.40728)
5 POINT (-77.41056 36.42228)
6 POINT (-76.99478 36.36145)

然后我们可以用类似的方式绘制它:

          X        Y
1 -81.49826 36.43140
2 -81.12515 36.49101
3 -80.68575 36.41252
4 -76.02750 36.40728
5 -77.41056 36.42228
6 -76.99478 36.36145

enter image description here

相关问题