[R-sig-Geo] Divide a polygon by a line?
Agustin.Lobo at ija.csic.es
Fri Nov 2 09:29:30 CET 2007
The problem is that my line is not an straight line, but
a very complex polyline (a boundary between types of forest
manually digitized over aerial photography) imported from a shp file
into a SpatialLinesDataFrame object.
Hisaji ONO escribio':
> I've create very simple example "cutting polygon by line
> c(0,5,10,5)" using by gpclib.
> x1<-t(structure(c(0,0,10,0,10,10,0,10,0,0),dim=c(2,5))) #
> simple square
> ### method using buffer
> min_buffer_dist <- 1e-10 # set minimum value
> # buffered similar line as polygon
> # x2<-t(structure(c(-1,5,11,5,11,5,-1,5),dim=c(2,4))) #
> this line can't cut square, just vanished.
> plot(setdiff(as(x1,"gpc.poly"),as(x2,"gpc.poly"))) # plot
> --- Roger Bivand <Roger.Bivand at nhh.no> wrote:
>> On Tue, 30 Oct 2007, Agustin Lobo wrote:
>>> Is it possible to divide a polygon by a line
>>> into 2 polygons?
>> No, in general. All computational geometry ends up
>> in having to deal with
>> the type of polygon. A convex polygon is one thing,
>> and can be divided
>> into two parts, but a general polygon may be
>> concave, and the number of
>> parts does not have to be two - the line could cross
>> it multiple times.
>> The approach taken in the Rgshhs function in
>> maptools is to overlay a
>> rectangular box over the polygon(s), and see what
>> comes out, but quite
>> often it isn't two (or in that case a single part
>> within the rectangle).
>> Roger Bivand
>> Economic Geography Section, Department of Economics,
>> Norwegian School of
>> Economics and Business Administration, Helleveien
>> 30, N-5045 Bergen,
>> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
>> e-mail: Roger.Bivand at nhh.no
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
More information about the R-sig-Geo