[R-sig-Geo] Eliminate duplicate vertices in a SpatialPolygonsDataFrame object

Don MacQueen macq at llnl.gov
Sun Jun 17 00:34:07 CEST 2007


Another post to R-sig-geo gave me a hint! I now have a way to remove 
duplicate adjacent vertices.

Here's an outline for a simple single polygon case.
If the SpatialPollygonsDataFrame includes more than one polygon then 
some looping will be needed.


## tmpn is a SpatialPolygonsDataFrame with only one polygon
## and it has duplicate adjacent vertices
tmpfix <- tmpn

ickm <- tmpfix at polygons[[1]]@Polygons[[1]]@coords
ickmg <- rbind(ickm[!duplicated(ickm),], ickm[nrow(ickm),] )

tmpfix at polygons[[1]]@Polygons[[1]]@coords <- ickmg


## one way to test for success:
try( as.owin.SpatialPolygons(polygons(tmpfix)) )

Thanks
-Don


At 5:51 PM -0700 6/15/07, Don MacQueen wrote:
>I have managed to create several SpatialPoygonsDataFrame objects in
>which the polygons have duplicate vertices. That is, there are
>duplicate rows in the matrix in "coords" slot of the object.
>
>In most cases, the object has just one polygon, but in at least one
>case it has an outer polygon and a hole.
>
>I would really appreciate some suggestions about an efficient way to
>remove duplicate rows from the matrix containing the polygon vertices.
>
>I have a solution using an application called Quantum GIS (the same
>app I used to create the duplicate rows without realizing it!), but
>it's rather awkward and tedious. Surely I can do better in R, but I
>haven't managed to learn yet how to extract, edit, update the
>contents of the coords slots (especially if there's more than one, as
>in a hole).
>
>Any ideas would be very welcome.
>
>Thanks
>-Don
>--
>--------------------------------------
>Don MacQueen
>Environmental Protection Department
>Lawrence Livermore National Laboratory
>Livermore, CA, USA
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo at stat.math.ethz.ch
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
---------------------------------
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
macq at llnl.gov




More information about the R-sig-Geo mailing list