AnsweredAssumed Answered

CityEngine Python Scripting: Batch grow streets and export as shape file

Question asked by stephen.condors on Jul 10, 2014
Latest reply on Aug 15, 2017 by TFuchs-esristaff

Hi all,

I'm fairly new to CityEngine but am hoping to build a python script that will allow me to batch grow a series of street networks (with some set parameters) and export each street network to a shape file as follows:

 

Pseudo code:

 

Start a new scene

Do while i < 100

{

     -growstreets(with some parameters)

     -select streets

     -export streets as .shp file with name: "streets" & i & ".shp"

     -select streets

     -delete streets

     i ++

}

 

I'm not new to programming but I am new to CityEngine and python.

I assume this is possible? !If anyone could point me in the direction of some suitable examples it would be much appreciated.

 

Many Thanks

Stephen

 

 

edit: I am playing with ce.growStreets(graph, settings) - however this function requires that I specify a graph from which streets are grown. Using the UI I can simply graph->grow streets in a blank world - can someone suggest how I do the same thing in a script (i.e. not pass a graph or pass an empty one). Thanks

 

edit2: OK - I am slowly moving forwards here - the following will create a new street network each time it is run, now i just need to export , delete the layer etc.

 

from scripting import *

 

# get a CityEngine instance

ce = CE()

 

def test():

    newGraph = ce.addGraphLayer('new')

    ce.growStreets(newGraph)

  

if __name__ == '__main__':

    test()

    pass

 

At this stage I'm unsure if a mod should delete this thread - but perhaps it will be use to someone else just starting out.

 

 

edit3: Close to a final solution - if I am doing this in a very cumbersome way please let me know

 

'''

Created on Jul 11, 2014

 

@author: Stephen

'''

from scripting import *

 

# get a CityEngine instance

ce = CE()

 

def batchGrowStreets():

    for i in range(1,11):

        ##Create a new graph layer

        newGraph = ce.addGraphLayer('new')

       

        ##Grow streets on it

        ce.growStreets(newGraph)

       

        ##Select them

        graph = ce.getObjectsFrom(ce.scene)

       

        ##setup the export file

        exportSettings = SHPExportGraphSettings()

        exportSettings.setFilename(ce.toFSPath("testCE" + str(i) + ".shp"))

       

        ##Export graph as shape file

        ce.export(graph, exportSettings)

       

        ##delete everything

        ce.delete(ce.getObjectsFrom(ce.scene))

 

if __name__ == '__main__':

    batchGrowStreets()

    pass

Outcomes