7

I have this street network of the center of Turin (IT), composed by lines representing streets, and black points representing intersections.

enter image description here

I have computed the centroids of each line and displayed these as red points. Now I would like to connect the centroids (red points) of each line that share the same intersection (black points) as in the "B" scheme of this picture:

enter image description here

The attribute of the intersections, that are the black points, are simple Ids:

enter image description here

Whereas in the attributes of the lines representing the streets I have the Ids, the start node (that is the Id of the black point where the line begin) and the end node (the Id of the black point where the line end.)

enter image description here

Do someone have an idea about how this can be done?

I've thought about pharsing the lines start points over the end points and vice-versa, but I really don't know how to do this.

  • Is non-QGIS of interest for you? – FelixIP Nov 28 '14 at 0:53
  • Well if you have any idea it would help me figure out how to do it in QGis! – Matteo Mandrile Dec 1 '14 at 15:22
  • I have an idea of how to perform this in QGIS, but could you share some sample data of the three layers for testing? Hopefully this hasn't impacted your thesis! – raphael Dec 23 '15 at 15:27
1

The script below assumes there are 3 feature layers:

  1. Point layer - nodes or street junctions
  2. Polyline layer - street segments. Associated table has 2 fields of integer type to store sequential number of from and to node.
  3. Polyline layer called 'connections' to store results.

Only essential part of the script shown below, i.e. no error handling, parameters assignment, etc:

## LIST TO STORE STREET SEGMENT MIDDLE POINT AND CONNECTED NODES ids
        bigList=[]
## ITERATE THROUGH SEGMENT TABLE AND AAPEND ABOVE LIST
        with arcpy.da.SearchCursor(theLinksLayer, ("SHAPE@",linksFromI,linksToI)) as cursor:
                for row in cursor:
                        pC=row[0].centroid
                        bigList.append((pC,row[1],row[2]))
        del row, cursor

## ARRAY TO STORE PAIRS OF POINTS AT INTERSECTING SEGMENTS
        theList=arcpy.Array()        
## ITERATE THROUGH EACH NODE and CALCULATE NUMBER OF CONNECTED SEGMENTS
        for i in xrange(nNodes):
                pList=[]
                for triple in bigList:
                        if i in triple:
                                p=triple[0]
                                pList.append(p)
                nCon=len(pList)
                if nCon>1:
## ITERATE THROUGH COMBINATION OF SEGMENTS AND CONNECT THEIR MIDDLE POINTS
                        for a in itt.combinations(xrange(nCon),2):
                                theList.removeAll()
                                theList.add(pList[a[0]])
                                theList.add(pList[a[1]])
                                l=arcpy.Polyline(theList)
                                curT.insertRow((arcpy.Polyline(theList),1))

Input sample, nodes labelled by their sequential number: enter image description here Output sample: enter image description here

  • Hello @FelixIP! thank you a lot for you help, I'll try the script and report back if it works for me! – Matteo Mandrile Dec 8 '14 at 16:57
  • Hello felix, I'm trying to run the script, copying and pasting it into the console but I get an error: !IMAGE. – Matteo Mandrile Dec 15 '14 at 14:32
  • This is ArGis solution. It is not going to work in any other environment – FelixIP Dec 15 '14 at 20:57

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.