forked from Riverscapes/pyBRAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamObjects.py
More file actions
68 lines (56 loc) · 2.27 KB
/
Copy pathStreamObjects.py
File metadata and controls
68 lines (56 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -------------------------------------------------------------------------------
# Name: Cluster
# Purpose: A class that holds a cluster of braided streams. Used primarily in BRAT_Braid_Handler.py
#
# Author: Braden Anderson
#
# Created: 03/2018
# -------------------------------------------------------------------------------
class Cluster:
def __init__(self, given_id):
"""
The constructor for our Cluster class
:param given_id: The identifier for our cluster, used in the equal function
"""
self.streams = []
self.endpoints = []
self.maxDA = 0.0
self.id = given_id
def addStream(self, newStream):
self.streams.append(newStream)
boundary = newStream.polyline.boundary()
self.endpoints.append(boundary.firstPoint)
self.endpoints.append(boundary.lastPoint)
self.maxDA = max(newStream.drainageArea, self.maxDA)
def merge(self, cluster_one, cluster_two):
"""
Takes the data from two clusters and combines them in this cluster
:param cluster_one: The first Cluster to merge
:param cluster_two: The second Cluster to merge
:return:
"""
if len(self.streams) != 0 or len(self.endpoints) != 0 or self.maxDA !=0: # we want this cluster to be empty
raise Exception("Trying to merge on a cluster that isn't empty!")
self.streams = cluster_one.streams + cluster_two.streams
self.endpoints = cluster_one.endpoints + cluster_two.endpoints
self.maxDA = max(cluster_one.maxDA, cluster_two.maxDA)
def containsStream(self, given_stream):
"""
Returns True if the stream given is inside the cluster, False if otherwise
:param given_stream: The stream ID that we want to check. Is an int
:return: Boolean
"""
for stream in self.streams:
if stream.id == given_stream:
return True
return False
def __eq__(self, other):
if isinstance(other, Cluster):
return False
else:
return self.id == other.id
class BraidStream:
def __init__(self, polyline, given_id, drainageArea):
self.polyline = polyline
self.id = given_id
self.drainageArea = drainageArea