<span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px"><div>Hi everybody,</div></span><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px"><div><br></div><div>I would like to use the gDifference function from the rgeos package to find the difference between 2 groups of polygons (poly1 and poly2).  I've tried the gDifference function with my given polygons (I made 2 shapefiles of 3 simple polygons that overlap so I could see how the function was working) and attached the output plot to this email.  I attached the gDifference between the gUnion and the gIntersection of the 2 shapefiles, because it shows you all the polygons from both shapefiles(in red), and where they intersect (in white).  The gDifference function seemed to work for 2 of the sets of overlapping polygons, but the 3rd (or rather the 1st, in the top left) set of polygons was not affected (as far as I know).  I believe this is because in the 2 overlapping polygons in the top left, the polygon from poly2 is COMPLETELY contained within the polygon from poly1.  Ideally, I would like the output to have a white hole where the overlapping polygon from poly2 is currently (like the other polygons).</div>
<div><br></div><div>Here is the code I am using:</div><div><br></div></span><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
<div>poly1 = polygons(spdf1)</div><div>poly2 = polygons(spdf2)</div></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">p_u = gUnion(poly1, poly2)</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">p_int = gIntersection(poly1, poly2)</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><div>p_diff = gDifference(p_u, p_int)</div><div>plot(p_diff, col = "red")</div>
</span></font></div></blockquote><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">

<div><br></div></span><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px"><div>I tried using gSymdifference, and also tried using the original polygons as opposed to the gUnion and gIntersection for the arguments (gSymdifference(poly1, poly2) gives the same output plot as above), but the same problem is always present.  I'm sure this problem can be rectified, but I imagine the same situation will come up when analysing larger data sets, so I'm going to look into it now.  There is a good chance I am not interpreting the data properly, as I'm very new to R, but I would appreciate any insight that could be provided.  I can provide more information regarding my problem if it is needed/requested.</div>

<div><br></div><div>Thanks a lot,</div><div>Cam</div>
</span>