-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResolvingOverlaps.py
158 lines (59 loc) · 1.71 KB
/
ResolvingOverlaps.py
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import maup
import geopandas
import matplotlib.pyplot as plt
# In[2]:
ut = geopandas.read_file("https://github.com/mggg-states/UT-shapefiles/raw/master/UT_precincts.zip")
# In[2]:
example = geopandas.read_file("zip://examples/overlaps.zip")
# In[6]:
resolved = maup.resolve_overlaps(example)
# In[17]:
resolved.plot(figsize=(12, 12), edgecolor="#004464", color="#eeeeee")
plt.axis('off')
# In[44]:
maup.adjacencies(example).plot(figsize=(14, 14))
# In[47]:
inters = maup.intersections(example, example, area_cutoff=None)
# In[50]:
non_self_inters = [i != j for i, j in inters.index]
inters = inters[non_self_inters]
# In[55]:
inters[inters.area > 0].plot(figsize=(12, 12), linewidth=5, edgecolor="black")
# In[64]:
inters.loc[[inters.area.idxmax()]].plot(figsize=(14,14))
plt.axis('off')
# In[65]:
polygon = inters[inters.area.idxmax()]
# In[80]:
from shapely.ops import triangulate
triangles = triangulate(polygon, edges=False)
# In[81]:
triangles_geo = geopandas.GeoSeries(triangles)
triangles_geo.centroid.scale(xfact=100).plot(figsize=(10, 10))
# In[87]:
from shapely.geometry import LineString
from shapely import affinity
# In[132]:
import numpy as np
from scipy.spatial import distance_matrix
# In[137]:
plt.matshow(distance_matrix(points, points))
# In[113]:
dist = distance_matrix(points, points)
# In[145]:
max_indices = np.argmax(dist, axis=1)
# In[83]:
line = LineString(triangles_geo.centroid)
# In[88]:
affinity.scale(line, xfact=100)
# In[18]:
example.plot(figsize=(12, 12), edgecolor="#004464", color="#eeeeee")
plt.axis('off')
# In[39]:
resolved
# In[41]:
resolved.loc[13].plot()
# In[ ]: