Select to view content in your preferred language

Selecting within a selection

302
4
09-18-2024 06:18 AM
MonicaClayton
Emerging Contributor

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:

MonicaClayton_0-1726665109527.png

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.

0 Kudos
4 Replies
desert
by
Occasional Contributor

I have referred to the link below.

getObjectsFrom

 

desert_1-1726716844128.png

 

change

shapes = getObjectsFrom(ce.scene)

to

shapes = getObjectsFrom(ce.selection, ce.isShape)

 

I hope this helps.

0 Kudos
MonicaClayton
Emerging Contributor

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!!

0 Kudos
JonasObertuefer
Esri Contributor

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

  1. Select all landuse shapes
  2. Apply & Generate the following CGA on them:
    attr landuse = "residential"
    
    Lot --> 
    	t(0,-5,0)  
    	extrude(10)
    	label(landuse)
    	color(1,0,0.5)​
  3. Connect the object attribute to the landuse attribute in the Inspector, if they are not automatically connected
  4. Select all footprints and assign&generate the following CGA onto them:
    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)​
  5. Add a new python file to the Scripts folder of the project
    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])​
  6. With the footprints still selected go to File -> Export -> Script Based Export (Python). Select the previously created python script and click on Finish
  7. All footprints inside a landuse shape will have a new landuse object attribute with the value of their respective surrounding landuse shape.
  8. Select them using your python script from above

I hope this is what you want to achieve. Let me know if you have any questions!

Cheers
Jonas