我有一个shapefile,在提取x,y,z分量时遇到问题。我还想将x和y从UTM转换为Lat和Lon。
最终我想要
plot(x, y)
map(add=T)
并添加其他点。
对于ex,你如何理解这个投影:
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)
但是很多地方都没有了。如何正确地对其进行索引?
谢谢!
发布于 2018-06-06 06:29:11
我使用的是sf
包附带的示例数据集。使用sf
,我们不需要将几何类型转换为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)
但是,如果必须转换为x和y列,则可以使用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
然后我们可以用类似的方式绘制它:
# Plot
plot(st_geometry(nc))
points(nc_points)
https://stackoverflow.com/questions/50709149
复制相似问题