def test_single_geometry(self): hole_coords = [(25, 25), (75, 25), (75, 75), (25, 75)] geometry = Polygon([(0, 0), (100, 0), (100, 100), (0, 100)], holes=[hole_coords]) result = holes_of_union(geopandas.GeoSeries([geometry])) assert len(result) == 1 assert result[0] == Polygon(hole_coords)
def test_multiple_geometries(self): # 000 # 0 0 # 000 geometries = geopandas.GeoSeries([ square_at(point) for point in product([0, 1, 2], [0, 1, 2]) if point != (1, 1) ]) result = holes_of_union(geometries) assert len(result) == 1 assert result[0].equals(square_at((1, 1)))
def test_multiple_holes_of_union(self): # 00000 # 0 0 0 # 00000 geometries = geopandas.GeoSeries([ square_at(point) for point in product([0, 1, 2, 3, 4], [0, 1, 2]) if point not in [(1, 1), (3, 1)] ]) result = holes_of_union(geometries) assert len(result) == 2 squares = [square_at((1, 1)), square_at((3, 1))] assert (result[0].equals(squares[0]) and result[1].equals( squares[1])) or (result[1].equals(squares[0]) and result[0].equals(squares[1]))
def test_multipolygon(self): # 000 000 # 0 0 0 0 # 000 000 geometries = geopandas.GeoSeries([ square_at(point) for point in product([0, 1, 2], [0, 1, 2]) if point != (1, 1) ] + [ square_at(point) for point in product([4, 5, 6], [0, 1, 2]) if point != (5, 1) ]) result = holes_of_union(geometries) assert len(result) == 2 squares = [square_at((1, 1)), square_at((5, 1))] assert (result[0].equals(squares[0]) and result[1].equals( squares[1])) or (result[1].equals(squares[0]) and result[0].equals(squares[1]))
def topology_report(geometries, adj): overlaps = adj[adj.area > 0] gaps = holes_of_union(geometries) islands = geometries.loc[list( set(geometries.index) - set(i for pair in adj.index for i in pair))] invalid = geometries.loc[-geometries.is_valid] return Report( "Topology", [ ReportItem( "Invalid Geometries", len(invalid), overlap_plot(geometries, invalid), success=len(invalid) == 0, ), ReportItem( "Islands", len(islands), overlap_plot(geometries, islands), success=len(islands) == 0, ), ReportItem( "Overlaps", len(overlaps), overlap_plot(geometries, overlaps), success=len(overlaps) == 0, ), ReportItem( "Gaps", len(gaps), overlap_plot(geometries, gaps), success=len(gaps) == 0, ), # ReportItem("Area Histogram", image=histogram(geometries.area, bins=40)), ], )
def test_raises_for_non_polygons(self): has_a_point = geopandas.GeoSeries([Point((0, 0)), square_at((0, 0))]) with pytest.raises(TypeError): holes_of_union(has_a_point)