[英]How to read results from a shapefile using readOGR from the rgdal package in R?
因此,我輕松讀取了shapefile:
shape<-readOGR(".","shapefile")
然后如果我做head(shape,1)我得到以下結果:
An object of class "SpatialLinesDataFrame"
Slot "data":
ID NAME PROJECT UP DOWN
0 1 X 05076 110468 38282
Slot "lines":
[[1]]
An object of class "Lines"
Slot "Lines":
[[1]]
An object of class "Line"
Slot "coords":
[,1] [,2]
[1,] 1824583 547917.9
[2,] 1824544 547437.1
Slot "ID":
[1] "0"
Slot "bbox":
min max
x 1824543.9 1824583.4
y 547437.1 547917.9
Slot "proj4string":
CRS arguments: NA
因此,獲取數據很容易,我只需執行shape $ NAME,然后從數據中獲取所有名稱。
但是我不知道如何訪問我要訪問的插槽“ coords”所在的位置,或者我該如何訪問不在數據插槽上的內容?
換句話說,我想讀取shapefile並以等於1824583的變量結尾,該變量是coords插槽矩陣的左上值。
有人可以幫忙嗎?
我們可以使用@
訪問插槽。 在這里,我以meuse
數據集為例。
library(sp)
data(meuse)
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")
head(meuse@coords)
# x y
# 1 181072 333611
# 2 181025 333558
# 3 181165 333537
# 4 181298 333484
# 5 181307 333330
# 6 181390 333260
meuse@coords[1, 1]
# [1] 181072
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.