Skip to content

Combine line segments into one line

4 messages · Robin Lovelace, Remon Hanna

#
Hi

I have line segments that I would like to combine them within each corridor, I.e each corridor will be one line of combined segments of NAME_S2S and combined geometry  as per the screenshot.

I have managed to plot the segments on the map as you can see but when zooming in these segments are not in one, which I would like to group them.

I ran the below line to group them by corridor, but I get error below;
Error in gLineMerge(dataformap[dataformap$Corridor == 1, ]) :
  Invalid geometry, may only be applied to lines

Many thanks in advance

Remon Hanna

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
4 days later
#
Hi Remon,

Please could you provide a fully reproducible example to illustrate the
data you have, what you have tried, and what you hope to achieve?

I cannot see the screenshot mentioned.

All the best,

Robin

On Fri, Oct 8, 2021 at 1:55 PM Remon Hanna <akhnatononline at hotmail.com>
wrote:

  
  
#
Hi  Robin

Thanks for coming back to me, my data frame called ?data formap? and each line?s geometry  is in a list as below

Scheme, Corridor, UID,S2S,Geometry

Islington, Canonbury Road, 1447, 14605 to 14609, list(c(-0.100494685106162, -0.100768728775846, -0.100809237473678, -0.100829081233454, -0.101055753520492, -0.101056925872705, -0.101132027068313, -0.101179751049333, -0.101183341723369, -0.101214417461412, -0.101296576180155, -0.101302119916002, -0.101944537808155, 51.5434078452207, 51.5436641294246, 51.5436996947231, 51.5437244960352, 51.544168798304, 51.5441712130049, 51.544334107534, 51.5443894702274, 51.5443939279601, 51.5444353337587, 51.5444892923546, 51.544493149994, 51.5449669589982), c(-0.100337415159165,  -0.100420276584877, -0.100443482598481, -0.100465896635865, -0.100480620959424, -0.100500980394883, -0.100507243380856, -0.100501227668383, -0.100494685106162, 51.5430850037077, 51.5432533165555, 51.5432674582742, 51.5432850407821, 51.5433055391161, 51.5433471893563, 51.5433731318632, 51.5433990971125, 51.5434078452207))


Islington, Canonbury Road, 19934, 14609 TO 29772, list(c(-0.102378850945486, -0.102404766293504, -0.102612043222577, -0.102841140440283, -0.102857165923901, -0.10307303364985, -0.103096514259402, -0.103308545727647, -0.10331512465684, -0.103613310295447, -0.103628721780704, -0.104683501048217, 51.5460024466378, 51.5460044053932, 51.5460430024067, 51.5460719844139, 51.5460746176867, 51.5461185026024, 51.5461247589939, 51.5461957028378, 51.5461980449175, 51.5463107753556, 51.546317496109, 51.5468445401221), c(-0.101944538040546, -0.101987754430814,  -0.101995197988773, -0.102120422782938, -0.102135897924177, -0.102179623597572, -0.102185478839142, -0.102221057492863, -0.102249160660721, -0.102264674655534, -0.102353250310779, -0.10236569955816, -0.10238744921156, -0.102390154716109, -0.102369692569022, -0.102373676493536, -0.102378850945486, 51.5449669591696, 51.5449988326798, 51.5450048166063, 51.5451147525675, 51.5451321348331, 51.5451973544301, 51.5452078768073, 51.545287421255, 51.5453095810419, 51.545324703994, 51.5454336871467, 51.5454557182705,  51.5455198269438, 51.5455452536589, 51.5457128758933, 51.5459370064566, 51.5460024466378))


# converts table to sf format
dataformap <- st_as_sf(dataformap)

# Render leaflet map
map<- leaflet(data=dataformap)%>%
addProviderTiles("CartoDB.Positron",options = providerTileOptions(minZoom=7))%>%
  addPolylines(data=dataformap,color= ~ pal(Scheme), weight = 2,opacity = 0.75,
               smoothFactor = 0,label = ~dataformap$Scheme,
               popup = paste("Scheme:", dataformap$Scheme, "<br>","<br>",
                                    "Corridor:", dataformap$Corridor, "<br>" ))%>%
  addDrawToolbar(targetGroup = "Scheme", editOptions = editToolbarOptions())

map

Thanks

Remon

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Robin Lovelace<mailto:rob00x at gmail.com>
Sent: 12 October 2021 14:44
To: r-sig-geo at r-project.org<mailto:r-sig-geo at r-project.org>
Subject: Re: [R-sig-Geo] Combine line segments into one line

Hi Remon,

Please could you provide a fully reproducible example to illustrate the
data you have, what you have tried, and what you hope to achieve?

I cannot see the screenshot mentioned.

All the best,

Robin

On Fri, Oct 8, 2021 at 1:55 PM Remon Hanna <akhnatononline at hotmail.com>
wrote:
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
#
Great to see the geometry but this still isn't quite a 'reprex'. Can you
provide code that others can reproduce, e.g. starting with:

dataformap = ...

you should be able to get the ... bit from a minimal example of your data
with dput(dataformap). Even better, you could try creating a fully
reproducible example and test it's reproducible using the reprex. You can
do this by copying the code that is reproducible and then entering
reprex::reprex() into the R console. You need to have installed the reprex
package first.

If you'd like to paste code with images you could try pasting the output
into a GitHub issue tracker, e.g.
https://github.com/r-spatial/discuss/issues/

Hope that helps and look forward to seeing a fully reproducible example
that should enable identification of an efficient fix!

Robin

On Tue, Oct 12, 2021 at 4:44 PM Remon Hanna <akhnatononline at hotmail.com>
wrote: