In [ ]:
import numpy as np
import pysal as ps
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import matplotlib as mpl
import shapely
import time
from scipy.spatial import Voronoi, voronoi_plot_2d
%matplotlib inline

mpl.rcParams['figure.figsize'] = 10,10  #set the default map size
mpl.rcParams['patch.linewidth'] = 0.5  #set default polygon line width

np.random.seed(352)

# Local path on user's machine
path = '/Users/jgaboardi/Algorithms_etc./Data/'

In [ ]:
points_list

In [ ]:
# Create Simulated Data for the Voronoi
simulated_points = 6
simulated_range = range(simulated_points)
points_list = []
for i in simulated_range:
    points_list.append([float(np.random.uniform(0,10,1)), float(np.random.uniform(0,10,1))])

# Instantiate and Plot the Voronoi    
t1_simulated = time.time()
vor = Voronoi(points_list)
voronoi_plot_2d(vor)
plt.show()
t2_simulated = time.time()-t1_simulated
print t2_simulated, 'seconds to instantiate the Voronoi Tessellation and plot the diagram'
print vor.npoints, 'points'
print len(vor.regions), 'regions'

In [ ]:
print vor.vertices[:]
print vor.ridge_vertices[:]

In [ ]:
simulated_lines = [shapely.geometry.LineString(vor.vertices[line])
                    for line in vor.ridge_vertices
                    if -1 not in line]

In [ ]:
print simulated_lines[0]

In [ ]:
simulated_gdf = gpd.GeoSeries([p for p in shapely.ops.polygonize(simulated_lines)])

In [ ]:
simulated_gdf.plot()

In [ ]:
simulated_gdf = gpd.GeoDataFrame(simulated_gdf)

In [ ]:
simulated_gdf.columns = ['geometry']

In [ ]:
simulated_gdf.to_file('Users/jgaboardi/Desktop/VORONOI.shp')

In [ ]: