R - how to display data from the “coordinates” slot in a spatial polygonal frame object

I saw a similar question to the one I have in mind, but the solution did not work for me, so I would like to post it here for your help.

I am doing an exercise based on the DataCamp course on geospatial data. Below is the code that I executed as a run:

library(sp)
library(tigris)
nyc_tracts <- tracts(state="NY",county="New York", cb=TRUE)

nyc_tracts is created as a spatial polygon object,

I tried to look at the first polygon in the list with the following syntax:

nyc_tracts@polygons[[1]], 

displays the following:

An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] -73.98733  40.71516

Slot "area":
[1] 9.884812e-06

Slot "hole":
[1] FALSE

Slot "ringDir":
[1] 1

Slot "coords":
           [,1]     [,2]
 [1,] -73.98975 40.71555
 [2,] -73.98915 40.71671
 [3,] -73.98837 40.71645
 [4,] -73.98672 40.71595
 [5,] -73.98501 40.71544
 [6,] -73.98426 40.71521
 [7,] -73.98334 40.71493
 [8,] -73.98245 40.71470
 [9,] -73.98471 40.71451
[10,] -73.98534 40.71446
[11,] -73.98716 40.71431
[12,] -73.98934 40.71413
[13,] -73.99022 40.71440
[14,] -73.98975 40.71555



Slot "plotOrder":
[1] 1

Slot "labpt":
[1] -73.98733  40.71516

Slot "ID":
[1] "156"

Slot "area":
[1] 9.884812e-06

Then I tried to display the "area" slot, the "ID" slot and the "plotOrder" slot, etc. with teams like below, and they all worked, for example.

nyc_tracts@polygons[[1]]@area

displayed:

[1] 9.884812e-06

"" (, 14x2, ), , , R :

nyc_tracts@polygons[[1]]@coords
nyc_tracts@polygons[[1]]@coords[1,1]

: "coords" ""

:

coordinates(nyc_tracts)

, ; , , "labpt" 1nyc_tracts, [[1]] ( , 14 ), .

, , . !

+4
1

R, , . :

nyc_tracts@polygons[[1]]@Polygons[[1]]@coords

:

       [,1]  [,2]
 [1,] -73.99 40.72
 [2,] -73.99 40.72
 [3,] -73.99 40.72
 [4,] -73.99 40.72
 [5,] -73.99 40.72
 [6,] -73.98 40.72
 [7,] -73.98 40.71
 [8,] -73.98 40.71
 [9,] -73.98 40.71
[10,] -73.99 40.71
[11,] -73.99 40.71
[12,] -73.99 40.71
[13,] -73.99 40.71
[14,] -73.99 40.72

- : , :

> nyc_tracts@polygons[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]] ....

, nyc_tracts@polygons[[1]], -, Polygons, nyc_tracts@polygons[[1]]@Polygon[[1]]. , , @coords, . , !

+1

Source: https://habr.com/ru/post/1682736/


All Articles