python script to extract polygons touching an area

edited March 2018 in Python scripting
Hi

I have a large oasis file and I need to extract polygons that touches a user specified rectangular area. Is there a tutorial on how to do this in python? I tried search the forum and didn't find a solution. Maybe this is too basic:-)

Thanks
enuinc

Comments

  • edited November -1

    Hi,

    there are many ways to achieve this. If your region is given in terms of coordinates, this is your code:

    import pya
    
    # Take polygons from layer 6/0 from the given search_region and keep as
    # a pya.Region in "touching"
    search_region = pya.DBox(550, -2800, 700, -2650)
    layout = pya.CellView.active().layout()
    src_layer = layout.layer(6, 0)
    src_cell = layout.top_cell()
    touching = pya.Region(src_cell.begin_shapes_rec_touching(src_layer, search_region))
    
    # write "touching" into a new layout and save
    new_layout = pya.Layout()
    new_top = new_layout.create_cell("touching")
    dest_layer = new_layout.layer(6, 0)
    new_top.shapes(dest_layer).insert(touching)
    new_layout.write("touching.oas")
    

    Another option is a clip, but I understand you want to see the polygons as a whole, not just the part inside the clip rectangle.

    Matthias

  • edited November -1
    Matthias

    Thanks. Can you also show me how to extract all the polygons (I suppose it has already been "flattened") in the "touching" cell

    Thanks
    enuinc
  • edited November -1

    What do you mean by "all the polygons"? Extracting a layer as a whole? With hierarchy or flat?

    Matthias

Sign In or Register to comment.