[R-sig-Geo] Antw: Re: Intersection of Polygons (sp)

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed May 9 20:28:27 CEST 2012



On 05/09/2012 05:43 PM, Matteo Mattiuzzi wrote:
> Dear Edzer, thanks for your answer.
>  
> Attributes: ok so I mixed "ID" of the Polygon with an "attribute".
> Basically I just want to get the "ID" of those polygons (ie: "h18v04")

> names(sr[spos,])
[1] "h05v04" "h06v04" "h18v04" "h19v04" "h29v04" "h30v04"

>  
> #The plot of:
> library(rgeos)
> x = sr[spos,] # you could omit the , as sr has no attributes
> plot(x)
> # indicates that the polygons don't close in the way I want it. Polygons
> crossing lon +-180 close by crossing the entire globe and not crossing
> the line lon +-180...Is there a way to control this?

I recall there has been discussion about the issue on this list before.
Only 15K messages to go through, according to
http://r-project.markmail.org/search/?q=r-sig-geo ;-)

>  
> Thanks Matteo  
>  
>  
>>>> Edzer Pebesma <edzer.pebesma at uni-muenster.de> 5/9/2012 3:20 pm >>>
> 
> 
> On 05/09/2012 03:07 PM, Matteo Mattiuzzi wrote:
>> Dear List,
>> 
>> I have a table with corner coordinates:
>> 
>>
> download.file("http://landweb.nascom.nasa.gov/developers/sn_tiles/sn_gring_10deg.txt",
> dest=paste(tempdir(),"/sn_gring_10deg.txt",sep=""))
>> x <-
> read.table(paste(tempdir(),"/sn_gring_10deg.txt",sep=""),skip=7,nrows=648)
>> colnames(x) <-
> c("iv","ih","lllon","lllat","ullon","ullat","urlon","urlat","lrlon","lrlat")
>> x <- x[x$lllon != -999,] # remove not valid tiles
>> x[1:5,]
>> 
>> # and I wish to create polygons for each of the rows of "x".
>> require(sp)
>> tilepolys <- list()
>> for (u in 1:nrow(x)){
>> attribute <- paste("h", sprintf("%02d", x$ih[u]), "v", sprintf("%02d",
> x$iv[u]),sep="")
>> tilepolys[[u]] <-
> Polygons(list(Polygon(cbind(c(x$ullon[u],x$urlon[u],x$lrlon[u],x$lllon[u],x$ullon[u]),c(x$ullat[u],x$urlat[u],x$lrlat[u],x$lllat[u],x$ullat[u])),hole=FALSE)),attribute)
>> }
>> sr=SpatialPolygons(tilepolys)
>> 
>> plot(sr)
>> # some polygons are crossing the lon +-180 limit and they should close
> the on the right side (crossing that border and not the globe). I don't
> understand if this happens here? And if there is a way to control it?
>> #######################
>> # I have a second polygon:
>> po  <-
> Polygon(cbind(c(9.533616,17.16639,17.16639,9.533616,9.533616),c(49.01889,49.01889,46.38557,46.38557,49.01889)),hole=FALSE)
>> pos <- Polygons(list(po),"austria")
>> spos <- SpatialPolygons(list(pos))
>> 
>> plot(spos)
>> 
>> # Now I want to select (or better get the attribute of) every polygon
> in "sr" that is inside or touches the polygon "spos"?
>> 
> sr does not have attributes.
> 
>> I hope this is possible to do with "sp", in order to avoid further
> dependencies.
> 
> not without rgeos:
> 
> library(rgeos)
> x = sr[spos,] # you could omit the , as sr has no attributes
> plot(x)
> 
>> 
>> Thanks a lot, Matteo
>> 
>> 
>> 
>> 
>> 
>> 
>>
>> [[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
> 
> -- 
> 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 at wwu.de
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at 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 at wwu.de



More information about the R-sig-Geo mailing list