## 将shapefile转换为R中的x，y，z（lat / lon coords）？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (1)
• 关注 (0)
• 查看 (81)

```plot(x, y)

```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_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))

### 1 个回答

```library(sf)

nc <- st_read(system.file("shape/nc.shp", package = "sf"))

# Plot it without converting geometry to x, y columns
plot(st_geometry(nc))

```# 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

```# Plot
plot(st_geometry(nc))
points(nc_points)```