Adding more nodes to streets in order to better align with terrain

465
1
05-09-2022 06:59 AM
AlexGumos
New Contributor

Hi!

I would like to "densify/increase amount of" nodes in my street network, so that I have node like each 2m (or denser) along the street lines.

I imported OSM street network to CityEngine, but the amount of nodes, and distances between them are set arbitrary/varies a lot, and in my case I am experiencing misalignment of streets with the DTM/terrain (while applying "Align to terrain. I work on 20 x 20 km project site, so "correcting" position of nodes here and there would be truly time consuming...Even if I would like to do so, the geometry of the streets (distance between nodes again) is not enabling me to better match them with underlaying DTM.

Is there a quick way to increase amount of nodes in the street layer within CityEngine? Perhaps you know a CGA rule that would do the job?

Thanks a million should your reply/ give me a hint to solve the problem

Tags (4)
0 Kudos
1 Reply
JonasObertuefer
Esri Contributor

Hi @AlexGumos,

You can do this using the python scripting interface.

Here is a quick example script which adds midpoints to all selected segments:

# get a CityEngine instance
ce = CE()

def midpoint(node1, node2):
    mX = (node1[0] + node2[0])/2
    mY = (node1[1] + node2[1])/2
    mZ = (node1[2] + node2[2])/2
    return mX, mY, mZ

@noUIupdate
def addMidpoints():
    # get selected segments
    segments = ce.getObjectsFrom(ce.selection(),ce.isGraphSegment)
    for segment in segments:
        # get nodes from segment
        segmentNodes    = ce.getObjectsFrom(segment, ce.isGraphNode)
        # add new node to segment at midposition
        ce.insertGraphNodes(segment, midpoint(ce.getPosition(segmentNodes[0]), ce.getPosition(segmentNodes[1])))

if __name__ == '__main__':
    addMidpoints()

for your case you probably want to modify this example a bit further, for instance only add midpoint until a certain segment lenght threshold or add multiple nodes depending on the segment lenght.

Also note that this example does not work well with curved segments.

More infos on our python scripting interface:
https://doc.arcgis.com/en/cityengine/latest/python/cityengine-python-intro.htm

I recommed our tutorial 10 to get familiar with python in CE:
https://doc.arcgis.com/en/cityengine/latest/tutorials/tutorial-10-python-scripting.htm

 

Hope this points you in the right direction!

Cheers,
Jonas