Data frame to SpatialPolygonsDataFrame with multiple polygons

المشرف العام

Administrator
طاقم الإدارة
I have a data frame with a bunch of polygons, several points per polygon. How can I convert it to a SpatialPolygonsDataFrame object?

Here's my data frame:

> buildings_df lon lat id1 96.13597 16.83363 convocation_hall2 96.13580 16.83315 convocation_hall3 96.13631 16.83298 convocation_hall4 96.13656 16.83351 convocation_hall5 96.13400 16.83104 judson_church6 96.13392 16.83073 judson_church7 96.13432 16.83064 judson_church8 96.13444 16.83085 judson_church9 96.13596 16.83074 the_library10 96.13586 16.83044 the_library11 96.13615 16.83035 the_library12 96.13626 16.83065 the_library13 96.13599 16.83073 the_libraryThis can be reproduced with:

> dput(buildings_df)structure(list(lon = c(96.135972, 96.1358, 96.136315, 96.136562, 96.133997, 96.133922, 96.134319, 96.134437, 96.135961, 96.135864, 96.136154, 96.136261, 96.135993), lat = c(16.833625, 16.833153, 16.832978, 16.833512, 16.831038, 16.830729, 16.830637, 16.830853, 16.83074, 16.830442, 16.83035, 16.830647, 16.830729), id = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), .Label = c("convocation_hall", "judson_church", "the_library"), class = "factor")), .Names = c("lon", "lat", "id"), row.names = c(NA, -13L), class = "data.frame")From this data.frame, I then convert it to a list, then to polygons, then to a SpatialPolygons object

# make a listbuildings_list
 
أعلى