- commented some imports that I do not use (and the method using it)

This commit is contained in:
Marius Stanciu 2020-08-25 14:39:29 +03:00 committed by Marius
parent ee664986b9
commit 9790f35b21
1 changed files with 45 additions and 45 deletions

View File

@ -23,8 +23,8 @@ import collections
import traceback import traceback
import numpy as np import numpy as np
from voronoi import Voronoi # from voronoi import Voronoi
from voronoi import Polygon as voronoi_polygon # from voronoi import Polygon as voronoi_polygon
import gettext import gettext
import appTranslation as fcTranslate import appTranslation as fcTranslate
@ -913,49 +913,49 @@ def farthest_point(origin, points_list):
return fartherst_pt return fartherst_pt
def voronoi_diagram(geom, envelope, edges=False): # def voronoi_diagram(geom, envelope, edges=False):
""" # """
#
:param geom: a collection of Shapely Points from which to build the Voronoi diagram # :param geom: a collection of Shapely Points from which to build the Voronoi diagram
:type geom: MultiPoint # :type geom: MultiPoint
:param envelope: a bounding box to constrain the diagram (Shapely Polygon) # :param envelope: a bounding box to constrain the diagram (Shapely Polygon)
:type envelope: Polygon # :type envelope: Polygon
:param edges: If False, return regions as polygons. Else, return only # :param edges: If False, return regions as polygons. Else, return only
edges e.g. LineStrings. # edges e.g. LineStrings.
:type edges: bool, False # :type edges: bool, False
:return: # :return:
:rtype: # :rtype:
""" # """
#
if not isinstance(geom, MultiPoint): # if not isinstance(geom, MultiPoint):
return False # return False
#
coords = list(envelope.exterior.coords) # coords = list(envelope.exterior.coords)
v_poly = voronoi_polygon(coords) # v_poly = voronoi_polygon(coords)
#
vp = Voronoi(v_poly) # vp = Voronoi(v_poly)
#
points = [] # points = []
for pt in geom: # for pt in geom:
points.append((pt.x, pt.y)) # points.append((pt.x, pt.y))
vp.create_diagram(points=points, vis_steps=False, verbose=False, vis_result=False, vis_tree=False) # vp.create_diagram(points=points, vis_steps=False, verbose=False, vis_result=False, vis_tree=False)
#
if edges is True: # if edges is True:
return vp.edges # return vp.edges
else: # else:
voronoi_polygons = [] # voronoi_polygons = []
for pt in vp.points: # for pt in vp.points:
try: # try:
poly_coords = list(pt.get_coordinates()) # poly_coords = list(pt.get_coordinates())
new_poly_coords = [] # new_poly_coords = []
for coord in poly_coords: # for coord in poly_coords:
new_poly_coords.append((coord.x, coord.y)) # new_poly_coords.append((coord.x, coord.y))
#
voronoi_polygons.append(Polygon(new_poly_coords)) # voronoi_polygons.append(Polygon(new_poly_coords))
except Exception: # except Exception:
print(traceback.format_exc()) # print(traceback.format_exc())
#
return voronoi_polygons # return voronoi_polygons
def nearest_point(origin, points_list): def nearest_point(origin, points_list):
""" """