-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_features.py
39 lines (34 loc) · 994 Bytes
/
generate_features.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
import os
import json
import math
from feature import FeatureCollection, Feature, Properties, Geometry
num_features = 360000
n = int(math.sqrt(num_features))
lt_x=105. #lt longitude
lt_y=35. #lt latitude
step=0.005
id=1
def get_feature(c, r):
x_step, y_step = c*step, r*step
coords = [
[
[lt_x+x_step, lt_y+y_step],
[lt_x+x_step, lt_y+y_step+step],
[lt_x+x_step+step, lt_y+y_step+step],
[lt_x+x_step+step, lt_y+y_step],
[lt_x+x_step, lt_y+y_step],
]
]
feature = Feature(Geometry(coords), Properties())
return feature
def main():
try:
fc = FeatureCollection()
fc.features= [get_feature(c, r) for r in range(n) for c in range(n)]
os.makedirs("data", exist_ok=True)
with open("data/features.json", 'w') as f:
json.dump(fc.to_dict(), f)
except Exception as e:
print(e)
if __name__ =='__main__':
main()