Or this:

library(rgeos)
library(raster)

esp <- getData("GADM", country="ESP", level=0)
plot(esp)

res <- gIntersection(esp, as(drawExtent(), 'SpatialPolygons'))
# now click on the map for the two corners of the extent you want

plot(res)


Robert


On Sun, Nov 13, 2011 at 12:15 PM, Edzer Pebesma <
edzer.pebesma@uni-muenster.de> wrote:

> Ralf, you could try
>
> getData("GADM", country="ESP", level=1)-> sp_gadm
> plot(sp_gadm[-c(13,14),])
>
> On 11/13/2011 08:40 PM, Ralf Schäfer wrote:
> > Dear list members
> >
> > I would like to access polygons from a SpatialPolygonDataFrame in order
> to subset them based on the area
> >
> > setwd("~/Desktop/")
> > require(raster)
> > getData("GADM", country="ESP", level=0)-> sp_gadm
> > str(sp_gadm@polygons) # I can see the single polygons, but I have
> trouble to access them.
> >
> > What I would like to do is to delete all Polygons except for the first
> one to have only the mainland of Spain.
> >
> > Perhaps there is also an easier way - but the dataframe of the object
> has only one row, hence I can not subset the dataframe:
> > sp_gadm@data
> >
> > Any help appreciated
> > Best regards
> > Ralf
> >
> > ------------------------------------------------------------
> > Prof. Dr. rer. nat. Ralf Bernhard Schäfer
> > Juniorprofessor for Quantitative Landscape Ecology
> > Environmental Scientist (M.Sc.)
> > Institute for Environmental Sciences
> > University Koblenz-Landau
> > Fortstrasse 7
> > 76829 Landau
> > Germany
> > Mail: schaefer-ralf@uni-landau.de
> > Phone: ++49 (0) 6341 280-31536
> > Web: http://tinyurl.com/6dnpxna
> >
> >
> >       [[alternative HTML version deleted]]
> >
> >
> >
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> --
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster
> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
> http://www.52north.org/geostatistics      e.pebesma@wwu.de
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

