Code Monkey home page Code Monkey logo

voronoi-diagram-for-polygons's Introduction

Voronoi diagram for polygons

PyPI version PyPI - Downloads Downloads DOI

Voronoi diagram for polygons is a tool to create a Voronoi diagram also known as Thiessen polygons for polygons. It's based on Shapely and GeoPandas. There are lots of tools to create a Voronoi diagram for points, for example Create Thiessen Polygons (Analysis) in ArcGIS Pro or ArcGIS Desktop, Voronoi Polygons in QGIS, or voronoi_diagram in Shapely. All of them are really cool. How about a Voronoi diagram for polygons? That's what this tool does.

Important! You have to install or upgrade to the latest developing version of Shapely before install Voronoi diagram for polygons

Table of contents

Installation, update and uninstallation

Dependencies

Important! It's based on voronoi_diagram from Shapely which 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:

pip install git+https://github.com/Toblerity/Shapely
pip install --upgrade git+https://github.com/Toblerity/Shapely

To install

Quick installation with pip:

pip install voronoi-diagram-for-polygons

Or from github:

pip install git+https://github.com/longavailable/voronoi-diagram-for-polygons

Also, you can just copy related functions from longsgis/longsgis.py to your work.

To update

pip install --upgrade voronoi-diagram-for-polygons

To uninstall

pip uninstall voronoi-diagram-for-polygons

Usage

See tests/01voronoiDiagram4plg.py.

import geopandas as gpd
from longsgis import voronoiDiagram4plg

builtup = gpd.read_file('input.geojson'); builtup.crs = 32650
boundary = gpd.read_file('boundary.geojson'); boundary.crs = 32650
vd = voronoiDiagram4plg(builtup, boundary)
vd.to_file('output.geojson', driver='GeoJSON')

Known shortages

  • It 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.

def bufferDissolve(gdf, distance, join_style=3):	
	'''Create buffer and dissolve thoese intersects.
	
	Parameters:
		gdf: 
			Type: geopandas.GeoDataFrame
		distance: radius of the buffer
			Type: float
	Returns:
		gdf_bf: buffered and dissolved GeoDataFrame
			Type: 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 polygons
	gs = gpd.GeoSeries([smp]).explode()
	#convert to GeoDataFrame
	gdf_bf = gpd.GeoDataFrame(geometry=gs, crs=gdf.crs).reset_index(drop=True)
	return gdf_bf

How to cite

If this tool is useful to your research, star and cite it as below:

Xiaolong Liu, & Meixiu Yu. (2020, July 26). longavailable/voronoi-diagram-for-polygons. Zenodo. 
http://doi.org/10.5281/zenodo.3960407

Easily, you can import it to Mendeley.

Changelog

v0.1.1

  • First release.

voronoi-diagram-for-polygons's People

Contributors

longavailable avatar imgbotapp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.