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

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

10
.idea/geojsonconv.iml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyInterpreterInspection" enabled="false" level="INFORMATION" enabled_by_default="false" />
</profile>
</component>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.11 (geojsonconv)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (geojsonconv)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/geojsonconv.iml" filepath="$PROJECT_DIR$/.idea/geojsonconv.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

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!")

18
main_delete_full.py Normal file
View File

@@ -0,0 +1,18 @@
import json
# Чтение данных из файла
with open('russia.geojson', 'r', encoding='utf-8') as infile:
data = json.load(infile)
# Поля, которые нужно оставить
fields_to_keep = ['id', 'name', 'full_name', 'major_cities', '_cartodb_id0', 'cartodb_id']
# Обновляем свойства в каждом объекте features
for feature in data['features']:
feature['properties'] = {key: feature['properties'][key] for key in fields_to_keep if key in feature['properties']}
# Запись резФультата в новый файл
with open('russia_2.geojson', 'w', encoding='utf-8') as outfile:
json.dump(data, outfile, ensure_ascii=False, separators=(',', ':'))
print("Обработка завершена. Результат записан в output.json.")

32916
ru.json Normal file

File diff suppressed because it is too large Load Diff

33648
ru_geojson.json Normal file

File diff suppressed because it is too large Load Diff

1
russia.geojson Normal file

File diff suppressed because one or more lines are too long

1
russia_2.geojson Normal file

File diff suppressed because one or more lines are too long