how to filter a shapefile ?
Thank you very much Roger. Still another question: Can you plot a polygon shapefile with borders but transparent interiors ? Arnald Marcer CREAF
On 09/16/2010 02:10 PM, Roger Bivand wrote:
On Thu, 16 Sep 2010, Mayeul KAUFFMANN wrote:
You can read your shapefile with: library(rgdal) countries_spdf <- readOGR(dsn=root_path, "countries_file_without_extension") #You'll have a spatial point data frame with marks. Look at str(countries_spdf). Try: plot(countries_spdf[countries_spdf at data$AREA>1000])
Correct, subset with the "[" method as with data.frame objects. But
avoid using the data slot directly, use the "$" method as with
data.frame objects:
plot(countries_spdf[countries_spdf$AREA>1000,])
and insert a comma in the "[" method to choose the rows matching the
condition:
library(rgdal)
dsn <- system.file("vectors", package = "rgdal")[1]
scot_BNG <- readOGR(dsn=dsn, layer="scot_BNG")
plot(scot_BNG, border="grey")
plot(scot_BNG[scot_BNG$SMR > 100,], border="black", lwd=2, add=TRUE)
Hope this helps,
Roger
Mayeul
_____________________________________________________ Dr. Mayeul KAUFFMANN, Conflict Specialist European Commission, Joint Research Centre (JRC) Institute for the Protection and Security of the Citizen (IPSC) Global Security and Crisis Management - ISFEREA Via E. Fermi 2749 - I-21027 Ispra (VA), ITALY Phone: (+39) 033278 5071 http://isferea.jrc.ec.europa.eu/Staff/Pages/Kauffmann-Mayeul.aspx (Office: building 48c, 1st floor, room 123. TP: 483) _____________________________________________________ Dr. Mayeul KAUFFMANN, Conflict Specialist European Commission, Joint Research Centre (JRC) Institute for the Protection and Security of the Citizen (IPSC) Global Security and Crisis Management - ISFEREA Via E. Fermi 2749 - I-21027 Ispra (VA), ITALY Phone: (+39) 033278 5071 http://isferea.jrc.ec.europa.eu/Staff/Pages/Kauffmann-Mayeul.aspx (Office: building 48c, 1st floor, room 123. TP: 483) -----Original Message----- From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Arnald Marcer Sent: Thursday, September 16, 2010 12:58 PM To: r-sig-geo Subject: [R-sig-Geo] how to filter a shapefile ? Hi, Can anyone give me a hint on how to extract/filter/subset polygons from a shapefile based on an attribute of its dbf table ? Example: shapefile: world.shp attributes of its dbf table: ID, AREA, COUNTRY, ... How can I plot a shapefile with only countries above a certain AREA value ? Thank you very much, Arnald Marcer CREAF _______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo _______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
----------------------------------------------------------------- Arnald Marcer Investigador Centre de Recerca Ecol?gica i Aplicacions Forestals (CREAF) Universitat Aut?noma de Barcelona 08193 Barcelona Tel: 93 5811312 Fax: 93 5814151 ----------------------------------------------------------------- Arnald Marcer Researcher Centre for Ecological Research and Forestry Applications (CREAF) Autonomous University of Barcelona 08193 Barcelona Phone: +34 93 5811312 Fax: +34 93 5814151