[R-sig-Geo] Can voronoi polygons calculated in R be converted to ESRI shapefile?
reeves at nceas.ucsb.edu
Thu Nov 15 22:48:47 CET 2007
The script that I had written before used the older, deprecated
to create a shapefile from the tripack() voronoi polygons.
Here is an example, based on the answer to your message from Roger Bivand,
that demonstrates the technique -
# example from the 'tripack' package documentation
voronoiShapefile <- function()
tritest.vm <- voronoi.mosaic(tritest$x,tritest$y)
tritest.vp <- voronoi.polygons(tritest.vm)
polys <- vector(mode="list", length=length(tritest.vp))
for (i in seq(along=polys))
pcrds <- cbind(tritest.vp[][,1],tritest.vp[][,2] )
pcrds <- rbind(pcrds, pcrds[1,])
polys[[i]] <- Polygons(list(Polygon(pcrds)), ID=as.character(i))
SP <- SpatialPolygons(polys) # 8 spatial polygons generated using
# Generate the SpatialPolygonsDataFrame object. For the purposes of this
# we use the last 8 points in the input point dataset as the data
component of the data frame.
# You will probably have 'actual' attribute data to assign to each
polygon. See data.frame documentation
SPDF <- SpatialPolygonsDataFrame(SP,
Areas <- sapply(slot(SP, "polygons"), function(x) slot(x, "area"))
SPDF1 <- SPDF[Areas < 0.866027,]
plot(SPDF1, axes=TRUE, xlim=c(1,10), ylim=c(1,10))
Debarchaa Ghosh wrote:
> Hi Rick,
> Thanks for your help. I'll be looking forward to your script.
> Rick Reeves wrote:
>> Hello Debs:
>> Yes, this can be done by 'promoting' the polygons generated by the
>> tripack package
>> into Spatial Polygon Data Frame objects, using the maptools and sp
>> packages. I have
>> an example R script, written a few years ago, that does this with an
>> older version of
>> the sp package. I suspect that it is easier to do now.....I could
>> clean it up and send it to you..
>> Rick Reeves
>> Debarchana Ghosh wrote:
>>> I have a point data frame with X and Y coordinates, where n=1051. I am
>>> trying to create Voronoi polygons using both the Tripack and PBSMapping
>>> testbird.vm<-voronoi.mosaic(testbird$X, testbird$Y)
>>>> >From here how can I create an ESRI shapefile of the voronoi
>>>> polygons in R
>>> and export to ArcGIS for further use.
>>> Thanks for the help,
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 339 bytes
Desc: not available
More information about the R-sig-Geo