New locations added with gIntersection() using a self-intersecting Line

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

New locations added with gIntersection() using a self-intersecting Line

David PINAUD
Dear all,

I 'm intersecting a Line with a Polygon using gIntersection() in the
rgeos package.
When I'm using gIntersection() with a "self-intersecting" Line, the
"clipped" Line is correctly created, but a node is also added
corresponding to the "self intersection" :

library(rgeos)
Le chargement a nécessité le package : sp
Le chargement a nécessité le package : stringr
rgeos: (SVN revision 287)
  GEOS runtime version: 3.3.1-CAPI-1.7.1
  Polygon checking: TRUE
  WARNING! if you turn polygon checking off, and polygons are
  not valid in GEOS, you risk losing data as your R session may crash!
Po1 <- readWKT("POLYGON((0 0,0 2,1 3.5,3 3,4 1,3 0,0 0))")
Lin1 <- readWKT("LINESTRING(0 3,1 1,2 2,3 0.5, 1 2.5, 3.5 2.5)")
Lin1po1 <- gIntersection(Lin1, Po1)
coordinates(Lin1po1)  # new segments are created, with new endpoints at
(1.75, 1.75)
plot(Po1, axes=T, col="grey")
plot(Lin1, add=T)
plot(as(Lin1po1, "SpatialPoints"), add=T, col="red")

# even with no intersection with a larger polygon:
Po2 <- readWKT("POLYGON((-1 0,-1 3.5,4 4,4 -1,-1 0))")
Lin1po2 <- gIntersection(Lin1, Po2)
coordinates(Lin1po2)  # new segments are created, with new endpoints at
(1.75, 1.75)
plot(Po2, axes=T, col="blue")
plot(Lin1, add=T)
plot(as(Lin1po2, "SpatialPoints"), add=T, col="red")

In the last case, one could expect Lin1 and Lin1po2 to be strictly
identical (same nodes).
Is there a way to avoid the creation of such new location?
Thanks for your help.

David

--
***************************************************
Dr. David PINAUD
Ingénieur de Recherche "Analyses spatiales"

Centre d'Etudes Biologiques de Chizé - CNRS UPR1934
79360 Villiers-en-Bois, France
poste 485
Tel: +33 (0)5.49.09.35.58
Fax: +33 (0)5.49.09.65.26
http://www.cebc.cnrs.fr/

***************************************************


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

pinaud.vcf (336 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: New locations added with gIntersection() using a self-intersecting Line

Roger Bivand
Administrator
On Fri, 13 Jan 2012, Pinaud David wrote:

> Dear all,
>
> I 'm intersecting a Line with a Polygon using gIntersection() in the rgeos
> package.
> When I'm using gIntersection() with a "self-intersecting" Line, the "clipped"
> Line is correctly created, but a node is also added corresponding to the
> "self intersection" :

This is most likely a feature of JTS/GEOS, see:

http://www.vividsolutions.com/jts/bin/JTS%20Technical%20Specs.pdf

pp. 27-28.

Roger

>
> library(rgeos)
> Le chargement a nécessité le package : sp
> Le chargement a nécessité le package : stringr
> rgeos: (SVN revision 287)
> GEOS runtime version: 3.3.1-CAPI-1.7.1
> Polygon checking: TRUE
> WARNING! if you turn polygon checking off, and polygons are
> not valid in GEOS, you risk losing data as your R session may crash!
> Po1 <- readWKT("POLYGON((0 0,0 2,1 3.5,3 3,4 1,3 0,0 0))")
> Lin1 <- readWKT("LINESTRING(0 3,1 1,2 2,3 0.5, 1 2.5, 3.5 2.5)")
> Lin1po1 <- gIntersection(Lin1, Po1)
> coordinates(Lin1po1)  # new segments are created, with new endpoints at
> (1.75, 1.75)
> plot(Po1, axes=T, col="grey")
> plot(Lin1, add=T)
> plot(as(Lin1po1, "SpatialPoints"), add=T, col="red")
>
> # even with no intersection with a larger polygon:
> Po2 <- readWKT("POLYGON((-1 0,-1 3.5,4 4,4 -1,-1 0))")
> Lin1po2 <- gIntersection(Lin1, Po2)
> coordinates(Lin1po2)  # new segments are created, with new endpoints at
> (1.75, 1.75)
> plot(Po2, axes=T, col="blue")
> plot(Lin1, add=T)
> plot(as(Lin1po2, "SpatialPoints"), add=T, col="red")
>
> In the last case, one could expect Lin1 and Lin1po2 to be strictly identical
> (same nodes).
> Is there a way to avoid the creation of such new location?
> Thanks for your help.
>
> David
>
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway