<div dir="ltr">
  
    
  
  <div>
    <p>Hi Micha, hi all,</p>
    <p>sorry for my late response...however, just today I managed to try
      your approach of building polylines to connect "touching stream
      lines"...but...<br>
    </p>
    <div>On 24.02.20 16:48, Micha Silver wrote:<br>
    </div>
    <blockquote type="cite">
      <br>
      On 24/02/2020 10:45, Johannes Radinger wrote:
      <br>
      <blockquote type="cite">Hi all,
        <br>
        I have a large river network dataset (lines). Now I'd to assign
        unique categories to each group of connected lines that have an
        attribute in common.
        <br>
        <br>
        For example, my rivers are categorized based on some kind of
        stream order. I want to group all rivers that belong to stream
        order 2 and are spatially connected; each group should get a
        unique category value. I thought that I could first extract all
        rivers with a particular attribute (e.g. stream order = 2) which
        will provide me some scattered pattern of lines. Then I need a
        spatial join tool to make subgroups of lines that are connected.
        How can I achieve the latter? Any idea?
        <br>
      </blockquote>
      <br>
      <br>
      Here's a procedure that might work for you. Somewhat clunky, but I
      think it gets what you want.
      <br>
      <br>
      It's based on the v.build.polylines module to connect all touching
      stream reaches. First extract each order from the stream vector
      into a new vector. Then build polylines. Patch them all together.
      Now you have a polyline vector with a single cat value for each
      set of original stream reaches that had the same order and that
      were touching.
      <br>
    </blockquote>
    <p>Unfortunately, the v.build.polylines tool does not work as it
      only does not connect multiple (intersecting) lines like in a
      river network. As an example I tried to build polylines from the
      stream network of the NC dataset. Yous suggested approach should
      result that each sub-network (i.e. river network that is not
      connected to another one) should get its own ID/cat...however,
      v.build.polylines results in a connected stream network that
      consists of multiple cats:</p>
    <p>v.clean --overwrite input=streams@PERMANENT output=streams_break
      tool=break<br>
      v.build.polylines --overwrite input=streams_break@test
      output=streams_poly cats=first type=line<br>
      d.vect -c map=streams_poly</p><p>So what would be needed here is some kind of tool that connects all touching lines and assigns a common category value, similar to the v.dissolve tool for polygon features. I can imagine that such a task might be not that uncommon also in another context? Any suggestions how to achieve this in GRASS?</p><p>A workaround that came into my mind was to create buffers around lines in order to make areas out of lines. Subsequently these touching areas can be merged using v.dissolve and the information about the common category can be queried using v.distance. Nevertheless, a rather cumbersome way to just assign a common category value to all lines that are touching...</p><p>Any further ideas?</p><p>cheers,</p><p>Johannes</p>
    <blockquote type="cite">
      <br>
      Finally, with v.distance you can upload that cat value to the
      original streams.
      <br>
      <br>
      <br>
      # Get a list of stream orders
      <br>
      ORDERS=`v.db.select -c streams group=strahler column=strahler`
      <br>
      echo $ORDERS
      <br>
      #1 2 3 4 5 6
      <br>
      # How many stream segments in original
      <br>
      <a href="http://v.info" target="_blank">v.info</a> -t streams | grep lines
      <br>
      # lines=1420
      <br>
      <br>
      # Now loop thru list of stream orders and extract stream segments
      for each order
      <br>
      for o in $ORDERS; do
      <br>
              v.extract input=streams output=streams_${o}
      where="strahler=${o}"
      <br>
              # Create polyline for each stream order
      <br>
              # Line "connects" all touching stream segments
      <br>
              v.build.polylines input=streams_${o}
      output=streams_${o}_polyline type=line cat=first
      <br>
      done
      <br>
      <br>
      # Patch stream order polylines together
      <br>
      POLYLINES=`g.list vect pattern="streams*polyline" separator=comma`
      <br>
      echo $POLYLINES
      <br>
      v.patch input=$POLYLINES output=streams_polylines
      <br>
      <a href="http://v.info" target="_blank">v.info</a> -t streams_polylines | grep lines
      <br>
      # lines=738
      <br>
      <br>
      # Add a new column to the original streams for new ID value
      <br>
      v.db.addcolumn map=streams column="merged_id INTEGER"
      <br>
      # And use v.distance to update that column from cat values in
      polylines vector
      <br>
      v.distance from=streams to=streams_polylines upload=cat
      column=merged_id
      <br>
      <br>
      HTH
      <br>
      <blockquote type="cite">
        <br>
        Cheers,
        <br>
        Johannes
        <br>
        <br>
        _______________________________________________
        <br>
        grass-user mailing list
        <br>
        <a href="mailto:grass-user@lists.osgeo.org" target="_blank">grass-user@lists.osgeo.org</a>
        <br>
        <a href="https://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank">https://lists.osgeo.org/mailman/listinfo/grass-user</a>
        <br>
      </blockquote>
      <br>
    </blockquote>
  </div>

</div>