<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Cambria;
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks Mike this was very useful.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In fact I want to clip the raster to try the gUnion function to dissolve some  features.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The gUnion is working but it is giving me a SpatialPolygons and not a SpatialPolygonsDataframe .<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Which make me loose the attribute table when I’m exporting the output shapefile. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Any hints?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thermo <- readOGR("//MAPPING-SERVER/Data/JosephVegMap/RS/Exported_New/thermo_n", layer="Thermo_n")<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>library(rgeos)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>#Thermo<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>#call the head of the Thermo attribute table<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>VV<-Thermo@data<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>TT<-gUnaryUnion(Thermo,VV$Class_name)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>JOSEPH BECHARA<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Wildfire Management Program Coordinator<o:p></o:p></span></b></p><p class=MsoNormal><span style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Ashrafieh 1020 Building, 8<sup>th</sup> floor, Mathaf, Beirut, Lebanon</span><b><span style='font-size:10.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'><o:p></o:p></span></b></p><p class=MsoNormal><span lang=FR style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Tel.: +961 (1) 426630-1-2<o:p></o:p></span></p><p class=MsoNormal><span lang=FR style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Fax: +961 (1) 426631<o:p></o:p></span></p><p class=MsoNormal><span lang=FR style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Mail: </span><span style='font-size:8.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><a href="mailto:jbejjani@lri-lb.org"><span lang=FR style='font-family:"Verdana","sans-serif";color:#7F7F7F'>jbechara@lri-lb.org</span></a></span><span lang=FR style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><a href="http://www.lri-lb.org/"><span style='font-size:9.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>www.lri-lb.org</span></a></span><span style='font-size:9.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'><o:p></o:p></span></p><p class=MsoNormal><a name="_GoBack"></a><span style='font-family:"Calibri","sans-serif";color:#1F497D'><img border=0 width=200 height=139 id="Picture_x0020_1" src="cid:image001.jpg@01CEBAA1.01872C60" alt="Description: Description: LRI-logo-Email"></span><span style='font-family:"Cambria","serif";color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Michael Sumner [mailto:mdsumner@gmail.com] <br><b>Sent:</b> Wednesday, September 25, 2013 11:21 PM<br><b>To:</b> Joseph Bechara<br><b>Cc:</b> RsigGeo<br><b>Subject:</b> Re: [R-sig-Geo] clip shape file<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>I use code like this: <o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>## UNTESTED<o:p></o:p></p></div><div><p class=MsoNormal>library(rgdal)<o:p></o:p></p></div><div><p class=MsoNormal>d <- readOGR("/path/to/file", "shpfile")<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>## use raster for an easy shortcut to build a clipping def<o:p></o:p></p></div><div><p class=MsoNormal>library(raster)<o:p></o:p></p></div><div><p class=MsoNormal>## dummy values, <o:p></o:p></p></div><div><p class=MsoNormal>ext <- extent(0, 100, 10, 90)<o:p></o:p></p></div><div><p class=MsoNormal>clipe <- as(ext, "SpatialPolygons")<o:p></o:p></p></div><div><p class=MsoNormal>proj4string(clipe) <- CRS(proj4string(d))<o:p></o:p></p></div><div><p class=MsoNormal>cropd <- SpatialPolygonsDataFrame(clipe, data.frame(x = 1), match.ID = FALSE)<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>## Now do the clip<o:p></o:p></p></div><div><p class=MsoNormal>library(rgeos)<o:p></o:p></p></div><div><p class=MsoNormal>res <- gIntersection(d, cropd)<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>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. <o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Cheers, Mike. <o:p></o:p></p></div></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p><div><p class=MsoNormal>On Wed, Sep 25, 2013 at 11:13 PM, Joseph Bechara <<a href="mailto:jbechara@lri-lb.org" target="_blank">jbechara@lri-lb.org</a>> wrote:<o:p></o:p></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Hello, <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>I’m trying to clip a shapefile with an extent.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Unfortunately it is not working.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Can somebody give me a hint?<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:9.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>JOSEPH BECHARA</span></b><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:9.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Wildfire Management Program Coordinator</span></b><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Ashrafieh 1020 Building, 8<sup>th</sup> floor, Mathaf, Beirut, Lebanon</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Tel.: +961 (1) 426630-1-2</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Fax: <a href="tel:%2B961%20%281%29%20426631" target="_blank">+961 (1) 426631</a></span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR style='font-size:8.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>Mail: </span><span style='font-size:8.0pt'><a href="mailto:jbejjani@lri-lb.org" target="_blank"><span lang=FR style='font-family:"Verdana","sans-serif";color:#7F7F7F'>jbechara@lri-lb.org</span></a></span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><a href="http://www.lri-lb.org/" target="_blank"><span style='font-size:9.0pt;font-family:"Verdana","sans-serif";color:#7F7F7F'>www.lri-lb.org</span></a><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><a name="141554193f3f10d3__GoBack"></a><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p></div></div><p class=MsoNormal style='margin-bottom:12.0pt'><br>_______________________________________________<br>R-sig-Geo mailing list<br><a href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a><br><a href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a><o:p></o:p></p></div><p class=MsoNormal><br><br clear=all><o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>-- <br>Michael Sumner<br>Hobart, Australia<br>e-mail: <a href="mailto:mdsumner@gmail.com" target="_blank">mdsumner@gmail.com</a> <o:p></o:p></p></div></div></body></html>