Skip to main content
Solved

Does anyone know how you merge lines with the same ID together but hold the attributes from the line with the longest length?

  • February 25, 2016
  • 5 replies
  • 220 views

nath
Contributor
Forum|alt.badge.img+7
Does anyone know how you merge lines with the same ID together but hold the attributes from the line with the longest length?

Best answer by redgeographics

First use a LengthCalculator to calculate the length of every line. Then for the merging you can use an Aggregator or LineJoiner (depending on what your geometry looks like and how you want to merge it. These transformers will have an option to create a list, that's a 1-to-many relationship, so the resulting lines will have a list with all the attributes of all their component lines. You can use a ListSorter to sort that list on the length attribute and then a ListIndexer with the index set to 0 to grab the attributes out of the first list element and promote those to feature attributes.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

redgeographics
Celebrity
Forum|alt.badge.img+62
  • Celebrity
  • Best Answer
  • February 25, 2016

First use a LengthCalculator to calculate the length of every line. Then for the merging you can use an Aggregator or LineJoiner (depending on what your geometry looks like and how you want to merge it. These transformers will have an option to create a list, that's a 1-to-many relationship, so the resulting lines will have a list with all the attributes of all their component lines. You can use a ListSorter to sort that list on the length attribute and then a ListIndexer with the index set to 0 to grab the attributes out of the first list element and promote those to feature attributes.


erik_jan
Contributor
Forum|alt.badge.img+23
  • Contributor
  • February 25, 2016

First use a LengthCalculator to calculate the length of every line. Then for the merging you can use an Aggregator or LineJoiner (depending on what your geometry looks like and how you want to merge it. These transformers will have an option to create a list, that's a 1-to-many relationship, so the resulting lines will have a list with all the attributes of all their component lines. You can use a ListSorter to sort that list on the length attribute and then a ListIndexer with the index set to 0 to grab the attributes out of the first list element and promote those to feature attributes.

Do not forget to recalculate the length (if you want that attribute) after the merging as the calculated length will only represent one of the merged parts.


redgeographics
Celebrity
Forum|alt.badge.img+62

Do not forget to recalculate the length (if you want that attribute) after the merging as the calculated length will only represent one of the merged parts.

Ah yes, good call!


nath
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • February 26, 2016

Thx! It works perfect!


Forum|alt.badge.img
  • August 16, 2017

Hi there, by any chance, does anyone know how to do this in a way that doesn't result in overlapping multi-part features?

I'm trying to create a model that joins two datasets that share some identical features in common.

When I use Line Joiner grouped by their common ID field, either nothing happens or one of the matching features seems to become corrupted (is not visible in ArcMap unless you manually edit its vertices).

When I use Aggregator, I get multipart features with two identical parts.

In both cases, I've compared the exact coordinates of every vertex in a sample of the resulting features, and they're completely identical.

I've attempted both methods with multiple unrelated datasets and have received the same results.