[R-sig-Geo] How to delete some polygons from 'SpatialPolygonsDataFrame'
Jianyun Wu
jianyun.fred.wu at gmail.com
Fri Nov 28 06:33:15 CET 2014
Dear list,
I usually use 'readOGR()' from rgdal package in R to input the ESRI
shapefile.
So the inputted data are SpatialPolygonsDataFrame.
I am processing the New South Wales, Australia map for a spatial analysis.
There is an island far away from the mainland, which I want to delete it
from the map when I plot NSW. Because it makes the whole plot small due to
its long distant.
Below is the area contains the polygons of this island and surrounding
islands. There are 14 "@Polygons" contributing to the entire area. From
some experiments, I know that it is Polygon 3-14 making the distant
islands.
Is there a simple way that I can delete those small polygons from this area
polygon and their attributes from the data
Thank you
Fred
str(nsw_lga[153, ])
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 1 obs. of 3 variables:
.. ..$ STATE_CODE: Factor w/ 9 levels "1","2","3","4",..: 1
.. ..$ LGA_CODE11: Factor w/ 565 levels "10050","10110",..: 153
.. ..$ LGA_NAME11: Factor w/ 564 levels "Adelaide (C)",..: 483
..@ polygons :List of 1
.. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
.. .. .. ..@ Polygons :List of 14
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 3.83e-07
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:38, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 4.69e-07
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:13, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 7.82e-07
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:31, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 1.02e-06
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:47, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 1.14e-06
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:22, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.6
.. .. .. .. .. .. ..@ area : num 1.38e-06
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:24, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 1.52e-06
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:26, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 2.05e-06
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:32, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 2.61e-06
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:36, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 4.27e-06
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:109, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.5
.. .. .. .. .. .. ..@ area : num 1.42e-05
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:85, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 159.1 -31.6
.. .. .. .. .. .. ..@ area : num 0.00152
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:2929, 1:2] 159 159 159 159 159 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 142.2 -30.7
.. .. .. .. .. .. ..@ area : num 8.79
.. .. .. .. .. .. ..@ hole : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:5178, 1:2] 144 144 144 144 144 ...
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt : num [1:2] 141.5 -31.9
.. .. .. .. .. .. ..@ area : num 0.0162
.. .. .. .. .. .. ..@ hole : logi TRUE
.. .. .. .. .. .. ..@ ringDir: int -1
.. .. .. .. .. .. ..@ coords : num [1:131, 1:2] 141 141 141 141 141 ...
.. .. .. ..@ plotOrder: int [1:14] 13 14 12 11 10 9 8 7 6 5 ...
.. .. .. ..@ labpt : num [1:2] 142.2 -30.7
.. .. .. ..@ ID : chr "152"
.. .. .. ..@ area : num 8.79
..@ plotOrder : int 1
..@ bbox : num [1:2, 1:2] 141 -33.4 159.1 -29
.. ..- 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 "+proj=longlat +ellps=GRS80 +no_defs"
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list