5

Does exist some plugin with it is possible to Splitting lines at a specified distance in Qgis?

  • I want to know if there is a plugin/tool in Qgis, that let me cut lines of a shapefile where the points of another shapefile are. Thanks in advance! – Milagros Antun Apr 21 '15 at 14:57
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. – Brad Nesom Apr 21 '15 at 15:32
  • I have similar problem, I know there is a tool called v.split.length (using QGIS 2.18.6) and I have road layer and need to split these roads to 5 km segments. I dissolved this layer to road types first so have only 3 different types. But unfortunately it didn't work. When I dissolved whole layer to one "single" line with 1 attribute I got same result. What this tool created was thousands of line divided by junctions (with different line length). It there any way how I can avoid this and really split line by 5 km segment? Please see attached screenshot. Blue lines are C roads, blue are B roads – DrottTom Mar 8 '18 at 14:33
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – LaughU Mar 8 '18 at 15:02
5

i think you can do this with Grass. vsplit or v.to.points works for you what you want...

v.split - Split lines to shorter segments. 
v.to.points - Create points along input lines in new vector with 2 layers. 

i hope it helps you...

0

Not a QGIS specific solution but I have a solution for the same problem using Python. The recursive function below break_line_max_length() takes a Shapely.geometry.LineString object and a distance value and returns a list of Shapely.geometry.LineString objects all of which has a maximum defined in dist argument.

from shapely.geometry import Point, LineString

def break_line_max_length(line, dist):
    if line.length <= dist:
        return [line]
    else: 
        segments = cut(line, dist)
        return [segments[0]] + break_line_max_length(segments[1], dist)

def cut(line, distance):
    # Cuts a line in two at a distance from its starting point
    # https://shapely.readthedocs.io/en/stable/manual.html
    if distance <= 0.0 or distance >= line.length:
        return [line]
    coords = list(line.coords)
    for i, p in enumerate(coords):
        pd = line.project(Point(p)) 
        if pd == distance:
            return [
                LineString(coords[:i+1]),
                LineString(coords[i:])]
        if pd > distance:
            cp = line.interpolate(distance)
            return [
                LineString(coords[:i] + [(cp.x, cp.y)]),
                LineString([(cp.x, cp.y)] + coords[i:])]

Example below:

>>> line_projected_crs = LineString([(964139.3529438695404679, 330222.9610171869280748), (964126.7161474197637290, 330216.1643494611489587), (964117.1236193983349949, 330210.6046891564619727), (964098.2156902365386486, 330199.1644833349855617), (964090.6063651703298092, 330194.5823128472547978), (964059.9382855900330469, 330176.2232018694048747), (963946.7483211233047768, 330109.7633781027398072), (963935.4178772714221850, 330103.7357962326495908), (963928.8533927279058844, 330100.1263311330112629), (963858.3536400874145329, 330057.5496864024316892), (963823.2569981947308406, 330036.5799001286504790), (963720.0721067255362868, 329974.9035306648002006), (963692.6907952920300886, 329960.0797074790461920), (963684.2196246678940952, 329955.5032849358394742), (963622.0352077478310093, 329916.8891303183045238), (963536.0845779583323747, 329861.5464295161655173), (963496.7778069525957108, 329833.3472477410687134), (963432.1966278479667380, 329789.1737683381652460), (963422.1127361512044445, 329781.4047729316516779)])
>>> line_projected_crs.length  #842.7394213492003
>>> line_segments = break_line_max_length(line_projected_crs, 100)
>>> for i in line_segments:
...     print(i.length)
100.00000000001499
99.99999999996642
100.0000000000037
100.00000000003674
100.00000000002392
100.00000000001194
100.0000000000049
99.99999999999824
42.73942134913942

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.