def constructive(arr, operation, *args, **kwargs): if operation == 'boundary': geometries = pg.boundary(pg.from_wkb(arr), **kwargs) elif operation == 'buffer': geometries = pg.buffer(pg.from_wkb(arr), *args, **kwargs) elif operation == 'build_area': geometries = pg.build_area(pg.from_wkb(arr), **kwargs) elif operation == 'centroid': geometries = pg.centroid(pg.from_wkb(arr), **kwargs) elif operation == 'clip_by_rect': geometries = pg.clip_by_rect(pg.from_wkb(arr), *args, **kwargs) elif operation == 'convex_hull': geometries = pg.convex_hull(pg.from_wkb(arr), **kwargs) elif operation == 'delaunay_triangles': geometries = pg.delaunay_triangles(pg.from_wkb(arr), **kwargs) elif operation == 'envelope': geometries = pg.envelope(pg.from_wkb(arr), **kwargs) elif operation == 'extract_unique_points': geometries = pg.extract_unique_points(pg.from_wkb(arr), **kwargs) elif operation == 'make_valid': geometries = pg.make_valid(pg.from_wkb(arr), **kwargs) elif operation == 'normalize': geometries = pg.normalize(pg.from_wkb(arr), **kwargs) elif operation == 'offset_curve': geometries = pg.offset_curve(pg.from_wkb(arr), *args, **kwargs) elif operation == 'point_on_surface': geometries = pg.point_on_surface(pg.from_wkb(arr), **kwargs) elif operation == 'reverse': geometries = pg.reverse(pg.from_wkb(arr), **kwargs) elif operation == 'simplify': geometries = pg.simplify(pg.from_wkb(arr), *args, **kwargs) elif operation == 'snap': geometries = pg.snap(pg.from_wkb(arr), *args, **kwargs) elif operation == 'voronoi_polygons': geometries = pg.voronoi_polygons(pg.from_wkb(arr), **kwargs) else: warnings.warn(f'Operation {operation} not supported.') return None return pg.to_wkb(geometries)
def time_voronoi_polygons(self): pygeos.voronoi_polygons(self.points)
def test_voronoi_polygons_only_edges(): # example from PostGIS docs original = Geometry("MULTIPOINT (50 30, 60 30, 100 100, 10 150, 110 120)") actual = pygeos.voronoi_polygons(original, only_edges=True) assert pygeos.get_num_geometries(actual) == 7
def test_voronoi_polygons(): original = Geometry("MULTIPOINT (50 30, 60 30, 100 100, 10 150, 110 120)") actual = pygeos.voronoi_polygons(original) assert pygeos.get_num_geometries(actual) == 5
def create_voronoi( points: Sequence[pygeos.Geometry]) -> Sequence[pygeos.Geometry]: mp = pygeos.multipoints(points) polys = pygeos.get_parts(pygeos.voronoi_polygons(mp)) convex_hull = pygeos.buffer(pygeos.convex_hull(mp), 2) return pygeos.intersection(convex_hull, polys)