Joined reporting for features from different layers

5995
25
Jump to solution
09-19-2014 08:59 AM
PetrBocharnikov
New Contributor

Hello!

I am wondering, what is the best way to join reports for several shape layers? In my project, I have existing buildings (white), which are extruded from footprints shapes; new buildings (yellow), which are created from blocks of street network layer; and an underground parking (blue), which is extruded from a shape in another layer. How can I can report their attributes together - shall I create a forth layer to which I pass on the attributes of these three layers?

My general goal is to implement an interactive editing of new building volumes through the editing of street network. As a part of that, I would like to have the floor areas of existing buildings, new buildings and garage to appear together in the report panel. So that they could be assessed together.


picture for geonet.png

0 Kudos
25 Replies
AlanKlys
Occasional Contributor

That's a very helpful example, thanks a lot Chris.

I do have one resulting question, and a lot of python study it appears.

Let's say I want to write some of those reports (for the 10 parcels) along with the python calculated average total FAR to another shape's (eg. Precinct) object attributes.  I can then query that shape for a pre-generated report summary.

# Called after all shapes are generated.

Looking at the code after that statement I figured that it should work, but it doesn't.  Obviously I need to dig more into Python to understand why.

Precinct.jpg

0 Kudos
by Anonymous User
Not applicable

Here is a starting point. Put this in finishExport.

layers = ce.getObjectsFrom(ce.scene, ce.isLayer, ce.withName("My Precincts"))

shapesOnMyPrecinctsLayer = ce.getObjectsFrom(layers[0])

# The zero on layers is because layers is a list, and you want the layer with index zero.

ce.setAttribute(shapesOnMyPrecinctsLayer[0], 'averageTotalFAR', totalGFA / totalSiteArea)

# I have not tested this. Might not compile.  Remember that in Py, indention counts. If it fails, pay attention to the console, and see the trail of print statements to see where it fails.

Chris

0 Kudos
AlanKlys
Occasional Contributor

Thanks again for your help Chris.

What you wrote compiles just fine and sort of works.

Here's where python has me stumped however, in this example anyway.

In order for the Object Attributes to be written to the My Precincts layer it needs to have the same rule applied as the buildings and generate the appropriate areas it seems,  otherwise nothing gets written to it.  Which effectively throws off the reports as the precinct is contributing to the whole.

Even if I apply a different start rule to it and zero out the SiteArea and GFA in the reports the python script still fails to write things to it ?  It's obviously missing some form of context but I'm not at all sure what that is or why it needs it in this case.

This is what my finishExport looks like

def finishExport(exportContextOID):

    ctx = ScriptExportModelSettings(exportContextOID)

  

    # Loop thru building reports attaching them to parcels.

    print 'totalGFA ' + str(totalGFA)

    print 'siteArea ' + str(totalSiteArea)

    print allShapes

          

    for thisShape in allShapes:

        ce.setAttribute(thisShape, 'averageTotalFAR', totalGFA / totalSiteArea)

        print thisShape

  

layers = ce.getObjectsFrom(ce.scene, ce.isLayer, ce.withName("MyPrecincts"))

shapesOnMyPrecinctsLayer = ce.getObjectsFrom(layers[0])

# The zero on layers is because layers is a list, and you want the layer with index zero.

ce.setAttribute(shapesOnMyPrecinctsLayer[0], 'averageTotalFAR', totalGFA / totalSiteArea)

0 Kudos
by Anonymous User
Not applicable

What I wrote last would only work if the Precinct shape has an object attribute called averageTotalFAR... I forgot to mention that. The first script is writing to the object attributes, not the rule attributes. This could do the same, and you can reference that object attribute using any rule or start shape, as long as that rule has an attribute named the same as the object attribute on the shape.

AlanKlys
Occasional Contributor

Cheers once again Chris. 

It's all clicked into place and working as expected.   This has been an extremely handy example for me. 

My only wish now is that python examples and code snippets were half as well documented as cga ... can't have it all tho I guess

What's the best place for one to rummage to get a few more examples and uses of python ?  I've been through the standard tutorials and PDF - which are quite basic.     

0 Kudos
by Anonymous User
Not applicable

Glad it worked for you. We do need a place to rummage. I think I learned how to do the Python export code by looking at the tutorials here:

CityEngine Tutorials

0 Kudos