[R-sig-Geo] Converting SpatialPolygons to non-overlapping SpatialLines

Karl Ove Hufthammer karl at huftis.org
Thu Apr 26 23:06:31 CEST 2012


Dear list members,

Consider a SpatialPolygons object, consisting of polygons that share
some boundaries (e.g., the states of the USA). It’s easy to convert this
into SpatialLines, but how can I create *non-overlapping* SpatialLines
where each line has a unique polygon membership, i.e., the entirety of
the line belong to the same polygon(s).

Example:

┌────────┐
│        │
│   A    ├───────┐
│        │       │
└─────┬──┘  B    │
      │          │
      └──────────┘

This should be split into three SpatialLines:

┌────────┐
│        │
│        
│        
└─────

and

         │
         │
      ───┘

and

         ────────┐
                 │
                 │
      │          │
      └──────────┘

Note that if the first two parts were merged, we would be left with
non-overlapping lines (touching at single nodes is OK), i.e., satisfying
the first condition,

┌────────┐
│        │
│        │
│        │
└────────┘


         ────────┐
                 │
                 │
      │          │
      └──────────┘

but the second condition is not satisfied, as part of the first line is
a member of only A, and part of it is a member of both A and B.

In theory, this splitting is simple to accomplish: Find all points where
two or more polygons touche at a single node (not a boundary), then
split all SpatialLines (that touch this point) at this point, and remove
duplicate lines. But how to do this in practice? Note that it’s not
necessary to keep the membership information for the lines (I’m creating
a SpatialLines, not a SpatialLinesDataFrame).

I’d be grateful for any help.

-- 
Karl Ove Hufthammer



More information about the R-sig-Geo mailing list