-
Notifications
You must be signed in to change notification settings - Fork 0
/
srt_to_geojson.py
47 lines (37 loc) · 1.22 KB
/
srt_to_geojson.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
import re
import json
def extract_coordinates_from_srt(srt_file):
with open(srt_file, 'r') as f:
srt_data = f.read()
pattern = r'\[latitude: ([-+]?\d+\.\d+)\] \[longitude: ([-+]?\d+\.\d+)\]'
coordinates = re.findall(pattern, srt_data)
return coordinates
def generate_geojson(coordinates):
features = []
for i, (lat, lon) in enumerate(coordinates, start=1):
feature = {
"type": "Feature",
"properties": {
"id": i
},
"geometry": {
"type": "Point",
"coordinates": [float(lon), float(lat)]
}
}
features.append(feature)
geojson_data = {
"type": "FeatureCollection",
"features": features
}
return geojson_data
def save_geojson(geojson_data, output_file):
with open(output_file, 'w') as f:
json.dump(geojson_data, f, indent=4)
if __name__ == "__main__":
srt_file = "merged_videos.srt"
output_file = "merged_videos.geojson"
coordinates = extract_coordinates_from_srt(srt_file)
geojson_data = generate_geojson(coordinates)
save_geojson(geojson_data, output_file)
print("GeoJSON file generated successfully.")