[R-sig-Geo] Help: creating owin{spats tat} objects from GIS data
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Thu Mar 31 13:48:33 CEST 2011
On Thu, Mar 31, 2011 at 2:29 AM, Axel Urbiz <axel.urbiz at gmail.com> wrote:
> Dear List,
>
> I'm trying to create an object of class "owin" (observation window) in the
> package spatstat from GIS mapping data. Here's an example of my problem.
> Everything goes well until the last line of code. I get the error message
> shown at the bottom:
>
> "Error in owin(poly = opls) :
> Polygon data contain overlaps between polygons"
>
> Thanks for any help,
I'm guessing its because the polygon data contains overlaps between polygons...
When I run it I also get a lot of useful messages:
> W <- as(SP, "owin")
Checking 43 polygons...1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43.
done.
Checking for cross-intersection between 43 polygons...1, Polygons 1
and 6 cross over
Polygons 1 and 10 cross over
Polygons 1 and 23 cross over
Polygons 1 and 32 cross over
etc.
Now I think those numbers dont map exactly to the polygons in SP - I
have only 27 in my map of switzerland. So tracking down what these
overlaps are could be a bit tricky.
If what you want is a window that is the whole of switzerland, then
either start with the adm0 level boundaries:
> con <- url("http://gadm.org/data/rda/CHE_adm0.RData")
> load(con)
> SP0 <- as(gadm, "SpatialPolygons")
> length(SP0)
[1] 1
> plot(SP0)
> as(SP0,"owin")
Checking 1 polygons...1.
[Checking polygon with 2390 edges...]
done.
window: polygonal boundary
enclosing rectangle: [5.957431, 10.49271] x [45.82166, 47.81115] units
Or dissolve the boundaries using package-of-the-month 'rgeos':
> outer = gUnionCascaded(SP)
> plot(outer)
> W = as(outer,"owin")
Checking 1 polygons...1.
[Checking polygon with 2386 edges...]
done.
rgeos is best got from r-forge at the moment.
Barry
More information about the R-sig-Geo
mailing list