I have a file with land use and building footprints. I have gotten to the point in python of selecting all the land use shps from the object attributes. In this picture:
I have written code that has selected everything tagged as residential in the object attributes.
def selectByAttribute(attr, value):
shapes = getObjectsFrom(ce.scene)
selection = []
for s in shapes:
attrvalue = ce.getAttribute(s, attr)
if attrvalue == value:
selection.append(s)
ce.setSelection(selection)
if __name__ == '__main__':
selectByAttribute("landuse","residential")
pass
My question then becomes, how do I select the footprints within those already selected polygons, and nothing else? This is where I have gotten stuck.
Please help? And help me like I have no coding knowledge what so ever. I have an art degree, and the above took me almost 2 days to figure out.
Thanks in advance!!!!
Monica
Edit: Essentially, I would like to "Select by Location" like I would in ArcPRO. Which, would be a nice feature to have in general.
I have referred to the link below.
change
shapes = getObjectsFrom(ce.scene)
to
shapes = getObjectsFrom(ce.selection, ce.isShape)
I hope this helps.
I did, and it gave me the same results. I want to select the footprints that are within the already selected land use polygons. Like my edit, a "Select by Location" option and the location being within my already selected polygons. Is this possible? There isn't any specific or differentiating attribute on the footprints that I can use to pick them out, the only thing they all have in common is the fact they are within a polygon tagged as "landuse, residential".
Thank you for the help!!
Hi @MonicaClayton,
There is way to do this in CityEngine although it is a rather complex workflow:
Asumming you have the landuse and footprint shapes in a different shape layer
attr landuse = "residential"
Lot -->
t(0,-5,0)
extrude(10)
label(landuse)
color(1,0,0.5)
Lot -->
contextCheck
contextCheck -->
case inside(inter, "residential") :
color(1,0,1)
report("landuse", "residential")
extrude(15)
// add more cases for all usages
else: extrude(15)
from scripting import *
# Get a CityEngine instance
ce = CE()
# Called for each shape after generation.
def finishModel(exportContextOID, shapeOID, modelOID):
ctx = ScriptExportModelSettings(exportContextOID)
shape = Shape(shapeOID)
model = Model(modelOID)
reports = model.getReports()
if 'landuse' in reports:
ce.setAttribute(shape, "landuse", reports['landuse'][0])
I hope this is what you want to achieve. Let me know if you have any questions!
Cheers
Jonas
To follow up on this, I recorded a quick video to showcase the workflow:
Additional resources: