An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060912/d36976e7/attachment.pl>
Problem in converting SpatialPolygonsDataFrame to owin object
2 messages · Debarchana Ghosh, Edzer Pebesma
Debarchana Ghosh wrote:
Hi,
Using readShapePoly from maptools I've read a ESRI shapefile to a object of
class 'SpatialPolygonsDataFrame'.
xx<-readShapePoly("tcma.shp")
plot(xx, border="blue", las=1)
str(xx)
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots ..@ data :`data.frame': 7 obs. of 5 variables: .. ..$ COUNTY : Factor w/ 7 levels "27003","27019",..: 1 2 3 4 5 6 7 .. ..$ CountyDum: num [1:7] 1 2 3 4 5 6 7 .. ..$ area : num [1:7] 1.15e+09 9.74e+08 1.52e+09 1.57e+09 4.40e+08... .. ..$ X : num [1:7] 480680 436555 494806 462435 492163 ... .. ..$ Y : num [1:7] 5013322 4963352 4946475 4983552 4984842 ... However I'm getting errors to convert xx(SpatialPolygonsDataFrame-object) to 'owin' object by using spspatstat package.
xx1<-as(as(xx, "SpatialPolygons"), "owin")
Polygons 1 and 4 cross over Polygons 1 and 5 cross over Polygons 1 and 7 cross over Polygons 2 and 4 cross over Polygons 2 and 6 cross over Polygons 3 and 4 cross over Polygons 3 and 5 cross over Polygons 3 and 6 cross over Polygons 3 and 7 cross over Polygons 4 and 5 cross over Polygons 4 and 6 cross over Polygons 5 and 7 cross over Error in owin(poly = opls) : Polygon data contain overlaps between polygons
These error messages are from spatstat, and seem to indicate that there is a problem with the polygons you provide: do they have line segments that intersect?
Also,
Error in asMethod(object) : W must be a SpatialPolygons object
You can ignore this message; proceed with the previous version.
After getting this error I realised SpatialPolygons is not same as SpatialPolygonDataFrame. If I'm correct how will I convert
SpatialPolygonDataFrame simply extends SpatialPolygons with a data slot containing the attributes. The is() relation holds, but it was inherits() that was used in the code. Changed that.
'SpatialPolygonDataFrame' to 'SpatialPolygons' obgect?
The as(xx, "SpatialPolygons") works fine; I modified the code such that xx1<-as(xx, "owin") will work fine as well in the future. -- Edzer