[R-sig-Geo] gUnion

Roger Bivand Roger.Bivand at nhh.no
Thu Sep 26 09:59:47 CEST 2013


On Thu, 26 Sep 2013, Joseph Bechara wrote:

> Thanks Mike this was very useful.
>
> In fact I want to clip the raster to try the gUnion function to dissolve 
> some features.
>
> The gUnion is working but it is giving me a SpatialPolygons and not a 
> SpatialPolygonsDataframe .

Obviously - how is the function to know which new features correspond to 
the dissolved ones? The row.names() of the input and output objects should 
provide some guidance about what has ended up where.

Roger

>
> Which make me loose the attribute table when I’m exporting the output 
> shapefile.
>
> Any hints?
>
>
>
>
>
> Thermo <- readOGR("//MAPPING-SERVER/Data/JosephVegMap/RS/Exported_New/thermo_n", layer="Thermo_n")
>
> library(rgeos)
>
> #Thermo
>
> #call the head of the Thermo attribute table
>
> VV<-Thermo at data
>
> TT<-gUnaryUnion(Thermo,VV$Class_name)
>
>
>
> JOSEPH BECHARA
>
> Wildfire Management Program Coordinator
>
> Ashrafieh 1020 Building, 8th floor, Mathaf, Beirut, Lebanon
>
> Tel.: +961 (1) 426630-1-2
>
> Fax: +961 (1) 426631
>
> Mail:  <mailto:jbejjani at lri-lb.org> jbechara at lri-lb.org
>
> <http://www.lri-lb.org/> www.lri-lb.org
>
> Description: Description: LRI-logo-Email
>
>
>
>
>
> From: Michael Sumner [mailto:mdsumner at gmail.com]
> Sent: Wednesday, September 25, 2013 11:21 PM
> To: Joseph Bechara
> Cc: RsigGeo
> Subject: Re: [R-sig-Geo] clip shape file
>
>
>
> I use code like this:
>
>
>
> ## UNTESTED
>
> library(rgdal)
>
> d <- readOGR("/path/to/file", "shpfile")
>
>
>
> ## use raster for an easy shortcut to build a clipping def
>
> library(raster)
>
> ## dummy values,
>
> ext <- extent(0, 100, 10, 90)
>
> clipe <- as(ext, "SpatialPolygons")
>
> proj4string(clipe) <- CRS(proj4string(d))
>
> cropd <- SpatialPolygonsDataFrame(clipe, data.frame(x = 1), match.ID = FALSE)
>
>
>
> ## Now do the clip
>
> library(rgeos)
>
> res <- gIntersection(d, cropd)
>
>
>
>
>
> Now, for questions like this you should provide the code you are trying with even if it doesn't work so we don't have to make it up.
>
>
>
> Cheers, Mike.
>
>
>
> On Wed, Sep 25, 2013 at 11:13 PM, Joseph Bechara <jbechara at lri-lb.org> wrote:
>
> Hello,
>
>
>
> I’m trying to clip a shapefile with an extent.
>
> Unfortunately it is not working.
>
> Can somebody give me a hint?
>
>
>
> JOSEPH BECHARA
>
> Wildfire Management Program Coordinator
>
> Ashrafieh 1020 Building, 8th floor, Mathaf, Beirut, Lebanon
>
> Tel.: +961 (1) 426630-1-2
>
> Fax: +961 (1) 426631 <tel:%2B961%20%281%29%20426631>
>
> Mail:  <mailto:jbejjani at lri-lb.org> jbechara at lri-lb.org
>
> <http://www.lri-lb.org/> www.lri-lb.org
>
>
>
>
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
>
>
>
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list