def bbox_match(sf,bbox,inside_only=True):
A,B,C,D = bbox<EOL>index = []<EOL>shape_records = []<EOL>for rec in enumerate(sf.shapeRecords()):<EOL><INDENT>a,b,c,d = rec[<NUM_LIT:1>].shape.bbox<EOL>if inside_only:<EOL><INDENT>if A <= a and B <= b and C >= c and D >= d:<EOL><INDENT>index.append(rec[<NUM_LIT:0>])<EOL>shape_records.append(rec[<NUM_LIT:1>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>cond1 = A <= a and B <= b and C >= a and D >= b<EOL>cond2 = A <= c and B <= d and C >= c and D >= d<EOL>cond3 = A <= a and D >= d and C >= a and B <= d<EOL>cond4 = A <= c and D >= b and C >= c and B <= b<EOL>cond5 = a <= C and b <= B and d >= D<EOL>cond6 = c <= A and b <= B and d >= D<EOL>cond7 = d <= B and a <= A and c >= C<EOL>cond8 = b <= D and a <= A and c >= C<EOL>if cond1 or cond2 or cond3 or cond4 or cond5 or cond6 or cond7 or cond8:<EOL><INDENT>index.append(rec[<NUM_LIT:0>])<EOL>shape_records.append(rec[<NUM_LIT:1>])<EOL><DEDENT><DEDENT><DEDENT>return index,shape_records<EOL>
Return the geometry and attributes of a shapefile that lie within (or intersect) a bounding box

:param sf: shapefile
:type sf: shapefile object
:param bbox: bounding box
:type bbox: list of floats [x_min,y_min,x_max,y_max]
:inside_only: True if the objects returned are those that lie within the bbox and False if the objects returned are any that intersect the bbox
:type inside_only: Boolean