Delauney.py
3.4 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# coding=utf-8
#author: 4N
#createtime: 2022/3/15
#email: nheweijun@sina.com
from osgeo import ogr
from osgeo.ogr import *
import math
import os
import copy
from test.zonghe.RepresentPoint import RepresentPoint
import time
class DelauneyNode:
def __init__(self, rp):
self.rp = rp
self.children_nodes = list()
self.children_delauney_lines = list()
def get_all_node(self):
for node in self.children_nodes:
yield node.get_all_node()
yield self
def get_rps(self):
for node in self.children_nodes:
for rp in node.get_rps():
yield rp
yield self.rp
def get_polygons(self):
for node in self.children_nodes:
for rp in node.get_rps():
yield rp.polygon
yield self.rp.polygon
def get_delauney_lines(self):
for node in self.children_nodes:
for ll in node.get_delauney_lines():
yield ll
for l in self.children_delauney_lines:
yield l
def add_children(self,node,delauney_line):
self.children_nodes.append(node)
self.children_delauney_lines.append(delauney_line)
class DelauneyLine:
def __init__(self,rp1,rp2):
self.rp1 = rp1
self.rp2 = rp2
self.distance = rp1.polygon.Distance(rp2.polygon)
self.line = ogr.Geometry(ogr.wkbLineString)
self.line.AddPoint(self.rp1.point.GetX(),self.rp1.point.GetY())
self.line.AddPoint(self.rp2.point.GetX(),self.rp2.point.GetY())
class DelauneyMinTree:
def __init__(self):
self.delauney_lines_list = list()
self.rps = set()
self.touch_delauney_lines = set()
def append(self,delauney_line,other_delauney_lines_kv):
candicates = []
if not self.rps.__contains__(delauney_line.rp1):
self.rps.add(delauney_line.rp1)
candicates.extend(other_delauney_lines_kv.get(delauney_line.rp1))
if not self.rps.__contains__(delauney_line.rp2):
self.rps.add(delauney_line.rp2)
candicates.extend(other_delauney_lines_kv.get(delauney_line.rp2))
for candicate in candicates:
if (candicate.rp1 in self.rps) and (candicate.rp2 in self.rps):
#初始化
try:
self.touch_delauney_lines.remove(candicate)
except:
print(111)
else:
self.touch_delauney_lines.add(candicate)
self.delauney_lines_list.append(delauney_line)
def get_rps(self):
return self.rps
def get_other_relate_delauney_lines(self,other_delauney_lines_kv,rps_set):
other_relate_delauney_lines = []
for rp in self.rps:
candicates = other_delauney_lines_kv.get(rp)
candicates = [c for c in candicates if c.rp1 in rps_set or c.rp2 in rps_set]
other_relate_delauney_lines.extend(candicates)
# other_relate_delauney_lines.append()
return other_relate_delauney_lines
def get_other_rp(self,delauney_line):
rp1 = delauney_line.rp1
rp2 = delauney_line.rp2
if not self.rps.__contains__(rp1):
return rp1
if not self.rps.__contains__(rp2):
return rp2
return None