【发布时间】:2017-11-16 15:26:06
【问题描述】:
我正在尝试在 shapefile 上绘制纬度和经度坐标。我被告知他们有相同的坐标系(NAD27)。研究后我尝试了很多方法,但没有一个是完美的。他们要么映射一个或另一个,但不能同时映射两者。下面是一个读取它们的示例,但我什至不知道如何开始绘图,因为我的 csv 来自 sp 包,而 shp 来自 maptools 包。
pts <- read.csv("locations.csv")
pts <- pts[,4:5]
names(pts) <- c("Latitude", "Longitude")
pts <- pts[complete.cases(pts),]
pts <- SpatialPoints(pts)
border <- maptools::readShapePoly("landman_one shape.shp")
任何帮助将不胜感激。
以下是不同的结构。
> str(pts)
Formal class 'SpatialPoints' [package "sp"] with 3 slots
..@ coords : num [1:372, 1:2] 30.9 30.9 31 31 31 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:372] "1" "2" "3" "4" ...
.. .. ..$ : chr [1:2] "Latitude" "Longitude"
..@ bbox : num [1:2, 1:2] 29.5 -105.2 36 -76.1
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "Latitude" "Longitude"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr NA
> str(border)
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 1 obs. of 2 variables:
.. ..$ Id : int 0
.. ..$ PERIM_GEO: num 998432
.. ..- attr(*, "data_types")= chr [1:2] "N" "F"
..@ polygons :List of 1
.. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
.. .. .. ..@ Polygons :List of 1
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 922511 545445
.. .. .. .. .. .. ..@ area : num 3.45e+10
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:252, 1:2] 954182 954073 954006 953914 953828 ...
.. .. .. ..@ plotOrder: int 1
.. .. .. ..@ labpt : num [1:2] 922511 545445
.. .. .. ..@ ID : chr "0"
.. .. .. ..@ area : num 3.45e+10
..@ plotOrder : int 1
..@ bbox : num [1:2, 1:2] 819851 386743 1042230 669865
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr NA
另外,我对预测不太熟悉,因此我们将不胜感激。另外,如果有办法用同一个包做到这一点,我会愿意接受的。
【问题讨论】:
-
您会发布指向数据集的链接,还是使用来自网络链接或特定包的链接?
-
听起来他们有不同的投影,可能是因为
maptools::readShapePoly()默认不加载投影,所以必须指定。检查str(pts)和str(border)并发布结果 -
内特,我会试着整理一些东西,但我的大部分数据都是机密的。