def add_stream_to_clusters(clusters, polyline, stream_id, drainage_area): """ Adds the stream to the list of clusters that we have :param clusters: A list of clusters :param polyline: The geoprocessing object that contains a bunch of points we need :param stream_id: The stream's ID, which we'll use to compare against the original stream when it comes time to update it :param drainage_area: The stream's drainage area :return: None """ new_stream = BraidStream(polyline, stream_id, drainage_area) connected_clusters = find_connected_clusters(clusters, new_stream) if len(connected_clusters ) == 0: # If there's no connecting cluster, make a new cluster global cluster_id # Allows us to modify cluster_id, so it always keeps count properly new_cluster = Cluster(cluster_id) cluster_id += 1 new_cluster.add_stream(new_stream) clusters.append(new_cluster) elif len( connected_clusters ) == 1: # if there's only one cluster that touches our stream, add the stream to that cluster i = connected_clusters[0] clusters[i].add_stream(new_stream) elif len( connected_clusters ) == 2: # If there are two clusters that we touch, we merge those two clusters, while also adding our new stream cluster_one = clusters[connected_clusters[0]] cluster_two = clusters[connected_clusters[1]] new_cluster = merge_clusters(cluster_one, cluster_two, new_stream) clusters.remove(cluster_one) clusters.remove(cluster_two) clusters.append(new_cluster)
def addStreamToClusters(clusters, polyline, stream_id, drainageArea): """ Adds the stream to the list of clusters that we have :param clusters: A list of clusters :param polyline: The geoprocessing object that contains a bunch of points we need :param stream_id: The stream's ID, which we'll use to compare against the original stream when it comes time to update it :param drainageArea: The stream's drainage area :return: None """ newStream = BraidStream(polyline, stream_id, drainageArea) connectedClusters = findConnectedClusters(clusters, newStream) if len(connectedClusters) == 0: global cluster_id # Allows us to modify cluster_id, so it always keeps count properly new_cluster = Cluster(cluster_id) cluster_id += 1 new_cluster.addStream(newStream) clusters.append(new_cluster) elif len(connectedClusters) == 1: i = connectedClusters[0] clusters[i].addStream(newStream) elif len(connectedClusters) == 2: cluster_one = clusters[connectedClusters[0]] cluster_two = clusters[connectedClusters[1]] new_cluster = mergeClusters(cluster_one, cluster_two, newStream) clusters.remove(cluster_one) clusters.remove(cluster_two) clusters.append(new_cluster)
def addStreamToClustersWithID(newStream, clusterID, clusters): """ Adds clusters to the stream based on the :param newStream: The stream we want to add :param clusterID: The cluster we want to add it to :param clusters: The clusters we've already made :return: None """ for cluster in clusters: if cluster.id == clusterID: cluster.addStream(newStream) return #if we found the stream, we end now # If the for loop didn't return, add a new cluster with the new stream as the first stream newCluster = Cluster(clusterID) newCluster.addStream(newStream) clusters.append(newCluster)
def add_stream_to_clusters_with_id(new_stream, new_cluster_id, clusters): """ Adds clusters to the stream based on the :param new_stream: The stream we want to add :param new_cluster_id: The cluster we want to add it to :param clusters: The clusters we've already made :return: None """ for cluster in clusters: if cluster.id == new_cluster_id: cluster.add_stream(new_stream) # if we found the stream, we end now return # If the for loop didn't return, add a new cluster with the new stream as the first stream new_cluster = Cluster(new_cluster_id) new_cluster.add_stream(new_stream) clusters.append(new_cluster)
def mergeClusters(cluster_one, cluster_two, new_stream): """ Merges two clusters and a new stream and returns them up :param cluster_one: The first cluster to merge :param cluster_two: The second cluster to merge :param new_stream: The new stream that connects them :return: A new merged stream """ global cluster_id # Allows us to modify cluster_id, so it always keeps count properly new_cluster = Cluster(cluster_id) cluster_id += 1 new_cluster.merge(cluster_one, cluster_two) new_cluster.addStream(new_stream) return new_cluster