This commit is contained in:
2024-11-03 20:17:41 +03:00
commit 1c2772316e
13 changed files with 66666 additions and 0 deletions

36
main.py Normal file
View File

@@ -0,0 +1,36 @@
import json
# Загрузка исходного JSON файла
with open('ru.json', 'r', encoding='utf-8') as f:
data = json.load(f)
# Инициализация структуры GeoJSON
geojson = {
"type": "FeatureCollection",
"features": []
}
# Преобразование регионов в формат GeoJSON
for region_name, polygons in data.items():
feature = {
"type": "Feature",
"properties": {
"name": region_name
},
"geometry": {
"type": "Polygon",
"coordinates": []
}
}
# Перебор каждого многоугольника (если их несколько)
for polygon in polygons.values():
feature["geometry"]["coordinates"].append(polygon)
geojson["features"].append(feature)
# Сохранение результата
with open('ru_geojson.json', 'w', encoding='utf-8') as f:
json.dump(geojson, f, ensure_ascii=False, indent=2)
print("Файл успешно преобразован в GeoJSON!")