def test_check_single_point_in_polygon(): pol = Polygons(SMALL_POLY_INNER) poi = Points([(4.0, 4.0, 4.0)]) poi.operation_polygons(pol, value=1, opname="eli", inside=False) assert len(poi.dataframe) == 1 poi.operation_polygons(pol, value=1, opname="eli", inside=True) assert len(poi.dataframe) == 0
def test_check_multi_point_single_polygon_zdir(): pol = Polygons(SMALL_POLY_INNER) poi = Points([(4.0, 4.0, 0.0), (4.0, 4.0, 4.0), (4.0, 4.0, 8.0)]) assert len(poi.dataframe) == 3 # Note z-direction has no effect. All points are deleted. poi.operation_polygons(pol, value=1, opname="eli", inside=True) assert len(poi.dataframe) == 0
def test_polygons_overlap(): pol = Polygons(SMALL_POLY_INNER + SMALL_POLY_OVERLAP_INNER) # The Four points are placed: within first poly, within the overlap, within the # second poly, outside both poly poi = Points([(3.5, 3.5, 0.0), (4.5, 4.5, 0.0), (5.5, 5.5, 0.0), (6.5, 6.5, 0.0)]) poi.operation_polygons(pol, value=1, opname="eli", inside=True) assert len(poi.dataframe) == 1
def test_oper_points_inside_overlapping_polygon(oper, expected): pol = Polygons(SMALL_POLY_INNER + SMALL_POLY_OVERLAP_INNER) # The Four points are placed: within first poly, within the overlap, within the # second poly, outside both poly poi = Points([(3.5, 3.5, 10.0), (4.5, 4.5, 10.0), (5.5, 5.5, 10.0), (6.5, 6.5, 10.0)]) # Operations are performed n times, where n reflects the number of polygons a # point is outside poi.operation_polygons(pol, value=2, opname=oper, inside=False) assert list(poi.dataframe[poi.zname].values) == expected
def test_operation_inclusive_polygon(): pol = Polygons(SMALL_POLY_INNER) # We place a point on the edge of a polygon poi = Points([(4.0, 4.0, 0.0)]) poi.operation_polygons(pol, value=1, opname="eli", inside=True) assert len(poi.dataframe) == 0 # We place a point on a corner of a polygon poi = Points([(3.0, 3.0, 0.0)]) poi.operation_polygons(pol, value=1, opname="eli", inside=True) assert len(poi.dataframe) == 0
def test_check_multi_point_multi_polyon_outside_op(): pol = Polygons(SMALL_POLY_INNER + LARGE_POLY_SHIFTED) # Two points in small cube, one in large cube, one outside poi = Points([(4.0, 4.0, 0.0), (4.5, 4.0, 0.0), (7.0, 7.0, 0.0), (20.0, 5.0, 0.0)]) assert len(poi.dataframe) == 4 # Note the operation will loop over the polygons, and hence remove the points # in the small polygon when considering the large polygon, and vice versa poi.operation_polygons(pol, value=1, opname="eli", inside=False) assert len(poi.dataframe) == 0
def test_check_multi_point_multi_polyon_inside_op(): pol = Polygons(SMALL_POLY_INNER + LARGE_POLY_SHIFTED) # Two points in small cube, one in large cube, one outside poi = Points([(4.0, 4.0, 0.0), (4.5, 4.0, 0.0), (7.0, 7.0, 0.0), (20.0, 5.0, 0.0)]) assert len(poi.dataframe) == 4 poi.operation_polygons(pol, value=1, opname="eli", inside=True) assert len(poi.dataframe) == 1 poi = Points([(4.0, 4.0, 0.0), (4.5, 4.0, 0.0), (7.0, 7.0, 0.0), (20.0, 5.0, 0.0)]) poi.operation_polygons(pol, value=1, opname="eli", inside=False) assert len(poi.dataframe) == 0
def test_points_in_polygon(testpath): """Import XYZ points and do operations if inside or outside""" poi = Points(testpath / POINTSET2) pol = Polygons(testpath / POLSET2) assert poi.nrow == 30 # remove points in polygon poi.operation_polygons(pol, 0, opname="eli", where=True) assert poi.nrow == 19 poi = Points(testpath / POINTSET2) # remove points outside polygon poi.operation_polygons(pol, 0, opname="eli", inside=False, where=True) assert poi.nrow == 1
def test_points_in_polygon(): """Import XYZ points and do operations if inside or outside""" poi = Points(POINTSET2) pol = Polygons(POLSET2) assert poi.nrow == 30 # remove points in polygon poi.operation_polygons(pol, 0, opname="eli", where=True) assert poi.nrow == 19 poi.to_file(join(TMPD, "poi_test.poi")) poi = Points(POINTSET2) # remove points outside polygon poi.operation_polygons(pol, 0, opname="eli", inside=False, where=True) assert poi.nrow == 1
def test_oper_single_point_in_polygon(oper, expected): pol = Polygons(SMALL_POLY_INNER) poi = Points([(4.0, 4.0, 10.0)]) # operators work on z-values poi.operation_polygons(pol, value=2, opname=oper, inside=True) assert poi.dataframe[poi.zname].values[0] == expected