[R-sig-Geo] How to delete some polygons from 'SpatialPolygonsDataFrame'
Frede Aakmann Tøgersen
frtog at vestas.com
Fri Nov 28 09:51:23 CET 2014
Hi
If nsw_lga[153, ] is the island that you do not want to plot then you can do
plot(nsw_lga[ -153, ])
or you can set an xlim in plot()
plot(nsw_lga, xlim = c(140, 153))
you may perhaps need play with the settings of xlim to find the right ones.
If you want to have an object without the island then do
nsw_lga_wo_island <- nsw_lga[ -153, ]
Something like
nsw_lga[ -153, ] <- NULL doesn't seem to work. Don't know if something similar will work.
Yours sincerely / Med venlig hilsen
Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling
Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com
Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.
> -----Original Message-----
> From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of
> Jianyun Wu
> Sent: 28. november 2014 06:33
> To: R-sig-Geo at r-project.org
> Subject: [R-sig-Geo] How to delete some polygons from
> 'SpatialPolygonsDataFrame'
>
> 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]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list