11

I have a polyline which is divided into multiparts and these parts are not well ordered so that the vertex's ID are not following the polyline's plotting.

This polyline is a representing a bus line and I need to have the plotting following the driving way of the bus. I would like to know how to merge the multiparts of this polyline?

I have already tried to Split and Unsplit, as well as Multipart to Single Part, Union, Merge, etc. but no one is giving me the result I want.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
bmoussea
  • 111
  • 1
  • 1
  • 4
  • @bmoussea, did you use the Dissolve tool? – artwork21 Jun 15 '11 at 15:34
  • @artwork21 Yes I did, but it doesn't change anything: the polyline is still divided in multiparts... – bmoussea Jun 15 '11 at 15:47
  • Check Geometry verify that the multi-part is ordered correctly first http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000034000000.htm then dissolve a artwork21 mentions – Mapperz Jun 15 '11 at 15:49
  • I checked the geometry and there are no problem reported. The multiparts do not appears in the checkgeometry because they are already parts of the polyline. – bmoussea Jun 15 '11 at 16:17
  • The multiparts of my polyline appear when editing the layer where my polyline is, and then right clic on it -> Edit Vertices and look in the Sketch Properties. Here are the differents parts (multiparts) of my polyline I would like to merge. – bmoussea Jun 15 '11 at 16:31
  • Do your multiparts touch? I'm picturing that your polyline looks like two arrows with the heads touching when what you want is them going head to tail. If we had tools like Ungenerate and Generate from Workstation in Desktop, and if these worked with multiparts (that coverage format did not support), then I think a solution would be simple, but we don't. Feel free to vote for these tools in the ArcGIS Idea at http://ideas.arcgis.com/ideaView?id=08730000000boEsAAI – PolyGeo Jun 16 '11 at 12:00
  • You picturing precisely what my problem is. I voted for the tool it could be helpfull, but I hope somebody can help me before ESRI decide to developp it :) – bmoussea Jun 16 '11 at 14:02
  • When code eventually shows up to solve the problem at http://gis.stackexchange.com/q/11019/, it will also solve this one with little modification. – whuber Jun 17 '11 at 19:06
  • I'm curious how you made the polyline(s) that you are trying to fix. Was it an OOTB procedure or via code? – PolyGeo Jun 25 '11 at 03:02
  • I got it as they are from the GIS office of the city with whom I work. I guess they constructed the lines themself and then merged the different lines to get a polyline for each bus line. – bmoussea Jun 28 '11 at 10:46
  • http://forums.arcgis.com/threads/32704-How-to-make-a-one-part-polyline-from-a-multipart-polyline?p=113427&posted=1#top – bmoussea Jun 28 '11 at 16:31
  • Have you been successful getting the lines seperated? – Brad Nesom Aug 04 '11 at 21:35
  • What are you using arcObjects or arcpy? – Emi Jan 15 '13 at 07:44
  • Have you tried using the Dissolve tool? toolboxes\system toolboxes\data management tools.tbx\generalization\dissolve I've used the tool for polygons in the past, and it just did a good job for me with a multi part line. –  May 17 '13 at 20:48

4 Answers4

6

I see from your tags that you are running ArcGIS 10. I've used the following method for a similar task:

1) Use Multipart to Single Part

2) Use Unsplit

In order for this to work (i.e. so that you have the lines in the proper order) you may need to break the line into the constituent end points and then change the direction based on an attribute (e.g. 1 = start, 2 = end) - you can use this to conditionally connect only those points that are different (If 1 + 2 then create connecting lines).

If you're working with an IDE the code for doing this is quite lengthy, but I will do my best to help if you have specific questions.

Radar
  • 10,659
  • 9
  • 60
  • 113
  • 1
    "Unsplit Line" requires an ArcInfo license. If you do not have this license level then use "Dissolve", it has an Unsplit Line option. – klewis May 17 '13 at 22:20
1

I had to do exactly the same quite a while back using AV 3.x and Avenue. I had a quick look for the code but couldn't find it. If I remember correctly the logic went something like this: (I also had the bus stops and terminals as a different point shapefile so I was able to determine the start and end parts):

  1. Create an empty polyline to receive the sorted parts. Lets call it the 'sorted polyline'
  2. To get the first part:

    2a. Get the part that is closest to start terminal

    2b. Get the distances of the start and end node of this part to the start terminal. If the start vertex is the closest one add this part to the 'sorted polyline'. If its the end- FLIP it and then add it.

  3. To get the middle and end parts, start with the part (polyline) that you created in the previous step and within a while(true) loop, start comparing the distance between the end node of the first part to the other parts in the input polyline. The one that is closest is the 'next part'. Compare the distance of the start and end node of the next part to determine whether to flip it or not before adding it to the 'sorted polyline'
  4. Exit the loop when the number of part in the 'sorted polyline' is the same as in the input polyline.

... or something like that! :-)

Let me know if this makes sense to you and I can have another go finding my original Avenue code.

mapoholic
  • 2,360
  • 18
  • 20
1

I had exactly the same problem due to updates I made to bus routes using the "Reshape Feature" Tool. Dissolve, Merge and Unsplit were not working because the multipart features were not coincident.

If you haven't noticed this by now, take a closer look at the vertices that must coincide between your multipart features. Extend, trim or reshape as necessary and then use any of the tools stated above.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Abraham L
  • 265
  • 1
  • 2
  • 8
  • Oh, and by the way: By "closer look" I mean VERY VERY CLOSE. – Abraham L May 03 '16 at 19:17
  • 1
    I had the same problem and took a Much Much closer look at the part end vertices as Abraham suggests. They were, in fact, not connected. Turn on endpoint snapping and snap the end vertices together, problem solved.. for me anyhoo. –  Aug 12 '16 at 21:55
1

I worked in a project something similar of this, I used ArcObjects. My goal was connecting two adjacent polylines if one of it's end point is another one's starting point to make two short polylines into a single polyline. My process was:

1. Dictionary<PointKey, FeatureDataList> polylineDictionary;
  • PointKey is a class that contains a point.
  • FeatureDataList is a class that contains List of IFeatures.
  • Both classes overrides "Equals" and "GetHashCode" methods.

    Dictionary<PointKey, FeatureDataList> ToPointDictionary;
    Dictionary<PointKey, FeatureDataList> FromPointDictionary;
    public void CreateDictionary(IFeatureLayer featureLayer)
    {
        var featureFunctionality = new FeatureFunctionality();
        List<IFeature> features = GetAllFeatures(featureLayer.FeatureClass);
    
        foreach (var feature in features)
        {
            IPolyline polyline = GetPolylineFromFeature(feature);
            AddFeatureInDictionary(ToPointDictionary, feature, polyline.ToPoint);
            AddFeatureInDictionary(FromPointDictionary, feature, polyline.FromPoint);
        }
    }
    
    
    
    void AddFeatureInDictionary(Dictionary<PointKey, FeatureDataList> polylineDictionary, IFeature feature, IPoint point)
    {
        FeatureDataList featureDataList;
        PointKey key = PointKey.GetKey(point);
        if (!polylineDictionary.ContainsKey(key))
        {
            featureDataList = new FeatureDataList();
            featureDataList.Add(feature);
            polylineDictionary.Add(key, featureDataList);
        }
        else
        {
            featureDataList = polylineDictionary[key];
            featureDataList.Add(feature);
        }
    }
    

By these processes I made two dictionaries. After creating dictionaries, I check for if both dictionaries contain same point and in both dictionaries, that key has only one feature in feature list, then I created a new polyline with those two polylines and delete two short polylines.

To join two polylines into one:

   private IPolyline GetJoinedPolylineFromFeatures(List<IFeature> features)
   {
        IPolyline newPolyline = null;
        if (features.Count == 2)
        {
            IPolyline polyline1 = feature1.Shape as IPolyline;
            IPolyline polyline2 = feature2.Shape as IPolyline;
            if (PointKey.GetKey(polyline1.ToPoint).Equals(PointKey.GetKey(polyline2.FromPoint)))
            {
                var topoOperator2 = polyline1 as ITopologicalOperator2;
                if (topoOperator2 != null)
                    newPolyline = topoOperator2.Union(polyline2) as IPolyline;
            }
            else if (PointKey.GetKey(polyline1.FromPoint).Equals(PointKey.GetKey(polyline2.ToPoint)))
            {
                var topoOperator2 = polyline2 as ITopologicalOperator2;
                if (topoOperator2 != null)
                    newPolyline = topoOperator2.Union(polyline1) as IPolyline;
            }
        }
        return newPolyline;
  }
Emi
  • 2,405
  • 2
  • 22
  • 40