-
Notifications
You must be signed in to change notification settings - Fork 0
/
snooper.py
79 lines (60 loc) · 2.38 KB
/
snooper.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
import csv
import location_history_parser
import shapefile_helper
import climate_data_helper
import projection_helper
import segments_helper
#============================
# Complete processing
#============================
def process_files(filenames, filters = {}):
for filename in filenames:
process_file(filename, filters)
def process_file(filename, filters = {}):
print(f"\n### Processing {filename}...")
json_to_csv(filename, filters)
shp_filename = json_to_shapefile(filename, filters)
climate_data_helper.add_climate_data(shapefile)
projected_shapefile = shapefile.replace("Point Shapefiles", "Projected Point Shapefiles")
projected_shapefile = projected_shapefile.replace(".shp", "_projected.shp")
projection_helper.project(shapefile, 32632, projected_shapefile)
segments_shapefile = shapefile.replace("Point Shapefiles", "Segment Shapefiles")
segments_shapefile = segments_shapefile.replace(".shp", "_segments.shp")
segments_helper.generate_segments(projected_shapefile, segments_shapefile)
#============================
# CSV creation
#============================
def json_to_csv(filename, filters = {}):
print(f"Parsing file '{filename}'...")
data = location_history_parser.parse_json_file_as_rows(filename)
output_filename = filename.replace(".json", ".csv")
print(f"Writing {len(data)} row(s) to '{output_filename}'...")
write_csv_file(output_filename, data)
print("Done!")
def write_csv_file(filename, rows):
with open(filename, 'w') as output:
csv_writer = csv.writer(output, lineterminator='\n')
csv_writer.writerows(rows)
#============================
# Shapefile creation
#============================
def json_to_shapefile(filename, filters = {}):
print(f"Parsing file '{filename}'...")
data_points = location_history_parser.parse_json_file(filename)["locations"]
output_filename = filename.replace(".json", ".shp")
print(f"Writing {len(data_points)} row(s) to '{output_filename}'...")
shapefile_helper.json_to_shapefile(data_points, output_filename)
print("Done!")
return(output_filename)
def filters_example():
filters = {
"start": datetime(2018, 4, 1),
"end": datetime(2018, 8, 1),
"bbox": {
"min_lat": -90.0,
"min_lon": 6.0,
"max_lat": 90.0,
"max_lon": 12.0,
}
}
return filters