[R-sig-Geo] Divide a polygon by a line?

Agustin Lobo Agustin.Lobo at ija.csic.es
Fri Nov 2 09:29:30 CET 2007


Thanks Hisaji,

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.

Regards,

Agus

Hisaji ONO escribio':
> Hi.
> 
>  I've create very simple example "cutting polygon by line
> c(0,5,10,5)" using by gpclib.
> 
> library(maptools)
> library(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
> 
> x2<-t(structure(c(-1,5,11,5+min_buffer_dist,11,5-min_buffer_dist,-1,5),dim=c(2,4)))
> # 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
> result
> 
> 
> 
> 
>  Regards.
> 
> 
> --- 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
>>
>>> Agus
>>>
>> -- 
>> 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
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster




More information about the R-sig-Geo mailing list