Package: voronoi-diagram-for-polygons
Voronoi diagram for polygonsVoronoi diagram for polygonsis a tool to create aVoronoi diagramalso known asThiessen polygonsforpolygons. It's based onShapelyandGeoPandas. There are lots of tools to create aVoronoi diagramfor points, for exampleCreate Thiessen Polygons (Analysis)inArcGIS ProorArcGIS Desktop,Voronoi PolygonsinQGIS, orvoronoi_diagraminShapely. All of them are really cool. How about aVoronoi diagramfor polygons? That's what this tool does.Important!You have to install or upgrade to the latest developing version ofShapelybefore installVoronoi diagram for polygonsTable of contentsInstallation, update and uninstallationDependenciesTo installTo updateTo uninstallUsageFAQKnown shortagesHow to cite?ChangelogInstallation, update and uninstallationDependenciesImportant!It's based onvoronoi_diagramfromShapelywhich is new in version 1.8.dev0. As of today, it is still a developing version.(2020-07-26)You have to install or upgrade to the latest developing version from source firstly:pipinstallgit+https://github.com/Toblerity/Shapelypipinstall--upgradegit+https://github.com/Toblerity/ShapelyTo installQuick installation withpip:pipinstallvoronoi-diagram-for-polygonsOr from github:pipinstallgit+https://github.com/longavailable/voronoi-diagram-for-polygonsAlso, you can just copy related functions fromlongsgis/longsgis.pyto your work.To updatepipinstall--upgradevoronoi-diagram-for-polygonsTo uninstallpipuninstallvoronoi-diagram-for-polygonsUsageSeetests/01voronoiDiagram4plg.py.importgeopandasasgpdfromlongsgisimportvoronoiDiagram4plgbuiltup=gpd.read_file('input.geojson');builtup.crs=32650boundary=gpd.read_file('boundary.geojson');boundary.crs=32650vd=voronoiDiagram4plg(builtup,boundary)vd.to_file('output.geojson',driver='GeoJSON')FAQI/O support.It was noticed someone were struggled with the input/output files with a format of.geojson(https://github.com/longavailable/voronoi-diagram-for-polygons/issues/3,https://github.com/longavailable/voronoi-diagram-for-polygons/issues/5). Actually, that's not a question related to this package. I will explain more here about it. This package is totally based onGeoPandas. In other words, any format that can be converted togeopandas.GeoDataFrameobject is supported. As theofficial documentationsaid:geopandas can read almost any vector-based spatial data format including ESRI shapefile, GeoJSON files and more using the command:geopandas.read_file()That means, you can put your.shpfiles as inputs and output as well. Any format you'd like. I used a few geojson-s (input.geojson,boundary.geojson, andoutput.geojson) in my example because the geojson format is very open. However, it's NOT necessary.For more, I upload theinput.geojsonandboundary.geojsonfiles. Hope they helps. For the sake of caution, I declare here that they are only a test file, any actual geographical data, similar or not, I have no guarantee to the accuracy and authenticity for them.Known shortagesIt may produce multipolygons (consisted by some unconnected polygons) around the boundary.Special input may cause overlap. See the following:To avoid this, I recommend reasonable preprocessing of the input, but use a buffer operation with high-resolution carefully.A buffer operation with high-resolution will result in circular arcs, which will generate too many vertices in a local area. This may trigger other bugs. In my practices, the following code snippet worked well.defbufferDissolve(gdf,distance,join_style=3):'''Create buffer and dissolve thoese intersects.Parameters:gdf:Type: geopandas.GeoDataFramedistance: radius of the bufferType: floatReturns:gdf_bf: buffered and dissolved GeoDataFrameType: geopandas.GeoDataFrame'''#create buffer and dissolve by invoking `unary_union`smp=gdf.buffer(distance,join_style).unary_union#convert to GeoSeries and explode to single polygonsgs=gpd.GeoSeries([smp]).explode()#convert to GeoDataFramegdf_bf=gpd.GeoDataFrame(geometry=gs,crs=gdf.crs).reset_index(drop=True)returngdf_bfHow to citeIf this tool is useful to your research,starand cite it as below:Xiaolong Liu, & Meixiu Yu. (2020, July 26). longavailable/voronoi-diagram-for-polygons. Zenodo. 
http://doi.org/10.5281/zenodo.3960407Easily, you can import it toMendeley.Changelogv0.1.1First release.v0.1.2Fix aFutureWarning.v0.1.3Make it more robust for the less-vertice-geometry inputs.#4.Fix a fewFutureWarnings.v0.1.6 (Merged)Change asShapelygoes.MultiPolygonis not iterable any more fromShapely2.0.Upload a few test data.