Spaces:
Sleeping
Sleeping
Commit
·
9283e79
1
Parent(s):
03ea002
improve render speed
Browse files
data/simplified_band_1.geojson
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c4c4af5e1796185fc653bb4bbe6d7e8da93a39cf355f813baa64d28964293340
|
3 |
+
size 22017800
|
notebooks/simplify_polygon.ipynb → simplify_polygon.ipynb
RENAMED
@@ -2,98 +2,16 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"id": "81ec2c58",
|
7 |
"metadata": {},
|
8 |
"outputs": [
|
9 |
{
|
10 |
-
"
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
" 'coordinates': [[[9.63254496008522, 37.40584843073688],\n",
|
16 |
-
" [9.63254496008522, 37.34548164364405],\n",
|
17 |
-
" [9.692911747178051, 37.34548164364405],\n",
|
18 |
-
" [9.692911747178051, 37.40584843073688],\n",
|
19 |
-
" [9.63254496008522, 37.40584843073688]]]}},\n",
|
20 |
-
" {'type': 'Feature',\n",
|
21 |
-
" 'properties': {'IWI': 0.21142578125},\n",
|
22 |
-
" 'geometry': {'type': 'Polygon',\n",
|
23 |
-
" 'coordinates': [[[9.451444598806724, 37.34548164364405],\n",
|
24 |
-
" [9.451444598806724, 37.28511485655122],\n",
|
25 |
-
" [9.511811385899556, 37.28511485655122],\n",
|
26 |
-
" [9.511811385899556, 37.34548164364405],\n",
|
27 |
-
" [9.451444598806724, 37.34548164364405]]]}},\n",
|
28 |
-
" {'type': 'Feature',\n",
|
29 |
-
" 'properties': {'IWI': 0.191650390625},\n",
|
30 |
-
" 'geometry': {'type': 'Polygon',\n",
|
31 |
-
" 'coordinates': [[[9.511811385899556, 37.34548164364405],\n",
|
32 |
-
" [9.511811385899556, 37.28511485655122],\n",
|
33 |
-
" [9.572178172992388, 37.28511485655122],\n",
|
34 |
-
" [9.572178172992388, 37.34548164364405],\n",
|
35 |
-
" [9.511811385899556, 37.34548164364405]]]}},\n",
|
36 |
-
" {'type': 'Feature',\n",
|
37 |
-
" 'properties': {'IWI': 0.1314697265625},\n",
|
38 |
-
" 'geometry': {'type': 'Polygon',\n",
|
39 |
-
" 'coordinates': [[[9.572178172992388, 37.34548164364405],\n",
|
40 |
-
" [9.572178172992388, 37.28511485655122],\n",
|
41 |
-
" [9.63254496008522, 37.28511485655122],\n",
|
42 |
-
" [9.63254496008522, 37.34548164364405],\n",
|
43 |
-
" [9.572178172992388, 37.34548164364405]]]}},\n",
|
44 |
-
" {'type': 'Feature',\n",
|
45 |
-
" 'properties': {'IWI': 0.169921875},\n",
|
46 |
-
" 'geometry': {'type': 'Polygon',\n",
|
47 |
-
" 'coordinates': [[[9.63254496008522, 37.34548164364405],\n",
|
48 |
-
" [9.63254496008522, 37.28511485655122],\n",
|
49 |
-
" [9.692911747178051, 37.28511485655122],\n",
|
50 |
-
" [9.692911747178051, 37.34548164364405],\n",
|
51 |
-
" [9.63254496008522, 37.34548164364405]]]}},\n",
|
52 |
-
" {'type': 'Feature',\n",
|
53 |
-
" 'properties': {'IWI': 0.261962890625},\n",
|
54 |
-
" 'geometry': {'type': 'Polygon',\n",
|
55 |
-
" 'coordinates': [[[9.692911747178051, 37.34548164364405],\n",
|
56 |
-
" [9.692911747178051, 37.28511485655122],\n",
|
57 |
-
" [9.75327853427088, 37.28511485655122],\n",
|
58 |
-
" [9.75327853427088, 37.34548164364405],\n",
|
59 |
-
" [9.692911747178051, 37.34548164364405]]]}},\n",
|
60 |
-
" {'type': 'Feature',\n",
|
61 |
-
" 'properties': {'IWI': 0.355712890625},\n",
|
62 |
-
" 'geometry': {'type': 'Polygon',\n",
|
63 |
-
" 'coordinates': [[[9.75327853427088, 37.34548164364405],\n",
|
64 |
-
" [9.75327853427088, 37.28511485655122],\n",
|
65 |
-
" [9.813645321363712, 37.28511485655122],\n",
|
66 |
-
" [9.813645321363712, 37.34548164364405],\n",
|
67 |
-
" [9.75327853427088, 37.34548164364405]]]}},\n",
|
68 |
-
" {'type': 'Feature',\n",
|
69 |
-
" 'properties': {'IWI': 0.36572265625},\n",
|
70 |
-
" 'geometry': {'type': 'Polygon',\n",
|
71 |
-
" 'coordinates': [[[9.813645321363712, 37.34548164364405],\n",
|
72 |
-
" [9.813645321363712, 37.28511485655122],\n",
|
73 |
-
" [9.874012108456544, 37.28511485655122],\n",
|
74 |
-
" [9.874012108456544, 37.34548164364405],\n",
|
75 |
-
" [9.813645321363712, 37.34548164364405]]]}},\n",
|
76 |
-
" {'type': 'Feature',\n",
|
77 |
-
" 'properties': {'IWI': 0.215087890625},\n",
|
78 |
-
" 'geometry': {'type': 'Polygon',\n",
|
79 |
-
" 'coordinates': [[[9.270344237528228, 37.28511485655122],\n",
|
80 |
-
" [9.270344237528228, 37.224748069458386],\n",
|
81 |
-
" [9.33071102462106, 37.224748069458386],\n",
|
82 |
-
" [9.33071102462106, 37.28511485655122],\n",
|
83 |
-
" [9.270344237528228, 37.28511485655122]]]}},\n",
|
84 |
-
" {'type': 'Feature',\n",
|
85 |
-
" 'properties': {'IWI': 0.145263671875},\n",
|
86 |
-
" 'geometry': {'type': 'Polygon',\n",
|
87 |
-
" 'coordinates': [[[9.33071102462106, 37.28511485655122],\n",
|
88 |
-
" [9.33071102462106, 37.224748069458386],\n",
|
89 |
-
" [9.391077811713892, 37.224748069458386],\n",
|
90 |
-
" [9.391077811713892, 37.28511485655122],\n",
|
91 |
-
" [9.33071102462106, 37.28511485655122]]]}}]"
|
92 |
-
]
|
93 |
-
},
|
94 |
-
"execution_count": 3,
|
95 |
-
"metadata": {},
|
96 |
-
"output_type": "execute_result"
|
97 |
}
|
98 |
],
|
99 |
"source": [
|
@@ -105,18 +23,20 @@
|
|
105 |
" geojson_data = json.load(a)\n",
|
106 |
"\n",
|
107 |
"\n",
|
108 |
-
"geojson_data['features']
|
|
|
109 |
]
|
110 |
},
|
111 |
{
|
112 |
"cell_type": "code",
|
113 |
-
"execution_count":
|
114 |
"id": "5720f337",
|
115 |
"metadata": {},
|
116 |
"outputs": [],
|
117 |
"source": [
|
118 |
"# Simplify a geometry\n",
|
119 |
"from shapely.geometry import shape, Point\n",
|
|
|
120 |
"def simplify_geometry_to_centroid(geometry):\n",
|
121 |
" geom = shape(geometry)\n",
|
122 |
" centroid = geom.centroid # Calculate the centroid of the polygon\n",
|
@@ -126,6 +46,11 @@
|
|
126 |
"for feature in geojson_data['features']:\n",
|
127 |
" feature['geometry'] = simplify_geometry_to_centroid(feature['geometry'])\n",
|
128 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
129 |
"with open('data/simplified_band_1.geojson', 'w') as w:\n",
|
130 |
" json.dump(geojson_data, w, indent=4)"
|
131 |
]
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 9,
|
6 |
"id": "81ec2c58",
|
7 |
"metadata": {},
|
8 |
"outputs": [
|
9 |
{
|
10 |
+
"name": "stdout",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"65673.0\n"
|
14 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
16 |
],
|
17 |
"source": [
|
|
|
23 |
" geojson_data = json.load(a)\n",
|
24 |
"\n",
|
25 |
"\n",
|
26 |
+
"num_points = len(geojson_data['features'])/2\n",
|
27 |
+
"print(num_points)"
|
28 |
]
|
29 |
},
|
30 |
{
|
31 |
"cell_type": "code",
|
32 |
+
"execution_count": 11,
|
33 |
"id": "5720f337",
|
34 |
"metadata": {},
|
35 |
"outputs": [],
|
36 |
"source": [
|
37 |
"# Simplify a geometry\n",
|
38 |
"from shapely.geometry import shape, Point\n",
|
39 |
+
"import random \n",
|
40 |
"def simplify_geometry_to_centroid(geometry):\n",
|
41 |
" geom = shape(geometry)\n",
|
42 |
" centroid = geom.centroid # Calculate the centroid of the polygon\n",
|
|
|
46 |
"for feature in geojson_data['features']:\n",
|
47 |
" feature['geometry'] = simplify_geometry_to_centroid(feature['geometry'])\n",
|
48 |
"\n",
|
49 |
+
"#shuffle data \n",
|
50 |
+
"random.shuffle(geojson_data['features'])\n",
|
51 |
+
"#only sample half of the data \n",
|
52 |
+
"geojson_data['features'] = geojson_data['features'][:int(num_points)]\n",
|
53 |
+
"\n",
|
54 |
"with open('data/simplified_band_1.geojson', 'w') as w:\n",
|
55 |
" json.dump(geojson_data, w, indent=4)"
|
56 |
]
|