def test_polygon_filter_byid(): """Filter a Polygon by a list of ID's""" pol = Polygons(POLSET3) assert pol.dataframe["POLY_ID"].iloc[0] == 0 assert pol.dataframe["POLY_ID"].iloc[-1] == 3 pol.filter_byid() assert pol.dataframe["POLY_ID"].iloc[-1] == 0 pol = Polygons(POLSET3) pol.filter_byid([1, 3]) assert pol.dataframe["POLY_ID"].iloc[0] == 1 assert pol.dataframe["POLY_ID"].iloc[-1] == 3 pol = Polygons(POLSET3) pol.filter_byid(2) assert pol.dataframe["POLY_ID"].iloc[0] == 2 assert pol.dataframe["POLY_ID"].iloc[-1] == 2 pol = Polygons(POLSET3) pol.filter_byid(99) # not present; should remove all rows assert pol.nrow == 0
def test_polygon_tlen_hlen(testpath): """Test the tlen and hlen operations""" pol = Polygons(testpath / POLSET3) pol.tlen() pol.hlen() assert pol.dataframe[pol.hname].all() <= pol.dataframe[pol.tname].all() assert pol.dataframe[pol.hname].any() <= pol.dataframe[pol.tname].any() pol.filter_byid(0) hlen = pol.get_shapely_objects()[0].length # shapely length is 2D! assert (abs(pol.dataframe[pol.hname].iloc[-1] - hlen)) < 0.001 assert (abs(pol.dataframe[pol.dhname].iloc[0] - 1761.148)) < 0.01