def compute_hull(fargs): '''Compute the convex hull for a set of nodes Returns a geojson object. ''' clustidx, nodes = fargs points = np.array([(x.lon, x.lat) for x in nodes], dtype=int) try: hull = topotools.get_concave_hull(points, args.alphacut) feature = geojson.Feature( id=clustidx, geometry=hull, properties={ 'clust': clustidx } ) except QhullError: log.exception("Error in Qhull, returning null for cluster" " %i with %i nodes" % (clustidx, len(points))) feature = None return feature
# keep a list of nodes we orphan orphans = [] good_nodes = [] for clustidx, nodes in clustered_nodes: node_list = list(nodes) points = np.array([(x.lon, x.lat) for x in node_list], dtype=float) if len(node_list) < 20: log.info("Cluster has less than 20 nodes, orphaning") orphans.extend(node_list) continue log.info("Cleaning community %i with %i points", clustidx, len(points)) concave_hull = topotools.get_concave_hull(points, args.alphacut) # So tiny it doesn't even have a hull if concave_hull is None: log.info("No concave hull, orphaning judicously") orphans.extend(node_list) continue concave_area = concave_hull.area log.info("Found concave hull with area %g", concave_area) convex_hull = topotools.get_convex_hull(points) convex_area = convex_hull.area log.info("Found convex hull with area %g", convex_area) if not convex_area: log.warning("Community has no area! Discarding all nodes") orphans.extend(node_list)