Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

Could anybody help me? Thanks! BM

share|improve this question
    
@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 help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… 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
show 8 more comments

4 Answers 4

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.

share|improve this answer
    
"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
add comment

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.

share|improve this answer
add comment

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;
  }
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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