[R-sig-Geo] Combining multiple polylines into a single polyline

Mayeul KAUFFMANN mayeul.kauffmann at jrc.ec.europa.eu
Fri Jun 18 10:08:55 CEST 2010


Hi,
Just a question to try and understand where the problem comes from: Are the
lines correctly represented in the shape files (and the problems comes when
importing/processing it), or is it already buggy in the shape files?

Also, you might want to look at the solution I use since I have the same
application as you and it works perfectly with a Qgis-R tandem.
I have lines as a shp layer in a QuantumGIS project, with distinct attributes
for each lines.
I use the "manageR" plugin to transfer data (line and DEM) to R:
http://www.ftools.ca/plugins.html

Then I created a "manageR" plugin (using library spatstat among others) to
sample along a line to get the profile according to DEM. It works nicely.
For the moment, it's only available at the link below, but you can copy-paste to
the tools.xml file:

http://code.google.com/p/ftools-qgis/source/detail?r=150
http://code.google.com/p/ftools-qgis/source/detail?r=151
(because of xml, the "<-" sign is represented as "<-")

Hope it helps,
Mayeul
_____________________________________________________
Dr. Mayeul KAUFFMANN, Conflict Specialist
European Commission, Joint Research Centre (JRC)
Institute for the Protection and Security of the Citizen (IPSC)
Global Security and Crisis Management - ISFEREA
Via E. Fermi 2749 - I-21027 Ispra (VA), ITALY
Phone: (+39) 033278 5071
http://isferea.jrc.ec.europa.eu/Staff/Pages/Kauffmann-Mayeul.aspx

(Office: building 48c, 1st floor, room 123. TP: 483)

-----Original Message-----
From: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Roger Bivand
Sent: Thursday, June 17, 2010 11:51 AM
To: Don MacQueen
Cc: r-sig-geo at stat.math.ethz.ch; Colin Rundel
Subject: Re: [R-sig-Geo] Combining multiple polylines into a single polyline

On Sat, 12 Jun 2010, Don MacQueen wrote:

> I have an input shapefile representing roads in a city, read into R where it 
> becomes a SpatialLInesDataFrame.
>
> Looking at just one road at a time, it looks fine when plotted. But in the 
> underlying structure, the single real-world road has been broken up into many 
> shorter polylines, and they are not included in the "correct" order, i.e., 
> end to end.

Is this an rgeos question - you seem to need a topology operation on 
geometries? Since rgeos is work in progress, there isn't support yet, and 
I don't know if there will be, but the use case seems convincing.

Roger

>
> When I sample along the road using spsample() with type='regular', the points 
> aren't equally spaced. I assumed this was because it is broken up into 
> separate lines. So I thought to combine the many short polylines into a 
> single long polyline, i.e., matching endpoints of one polyline with the 
> beginning of the next, dropping redundant nodes, and creating a new SLDF 
> object.
>
> I'm wondering if there's already an algorithm for this somewhere (in R or 
> GRASS, preferably!).
> (That's my main question)
>
>
> However, in my toy example below, consisting of just three polylines making 
> up a single road, spsample() does appear to equally space the points along 
> the entire length. So perhaps my real roads have some other structural 
> problem. Perhaps some endpoints don't match.
>
> Thanks
> -Don
>
> Here's a toy example:
>
> l1 <- matrix(c(1,1, 6,6, 4,8), byrow=TRUE, ncol=2)
> l2 <- matrix(c(4,8, 7,9), byrow=TRUE, ncol=2)
> l3 <- matrix(c(7,9, 11,10, 13,13), byrow=TRUE, ncol=2)
>
> LL1 <- Lines( list( Line(l1)) , ID='32')
> LL2 <- Lines( list( Line(l2)) , ID='147')
> LL3 <- Lines( list( Line(l3)) , ID='21')
>
> ## deliberately constructed out of order
> SL <- SpatialLines( list( LL2, LL3, LL1) )
> df <- data.frame( name=rep('Road',3))
> row.names(df) <- c('147','21','32')
> SLDF <- SpatialLinesDataFrame( SL, df)
>
> ## I would like to reduce to a structure like this:
> lc <- rbind(l1 , l2[-1,] , l3[-1,])
> df1 <- data.frame( name='Road')
> row.names(df1) <- 'a'
> SLDFfix <- SpatialLinesDataFrame( SpatialLines( list( Lines( list( Line(lc)) 
> , ID='a'))) , df1)
>
>

-- 
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



More information about the R-sig-Geo mailing list