0311
This commit is contained in:
Generated
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
Generated
+10
@@ -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>
|
||||||
+6
@@ -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>
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
Generated
+7
@@ -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>
|
||||||
Generated
+8
@@ -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>
|
||||||
Generated
+6
@@ -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>
|
||||||
@@ -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!")
|
||||||
@@ -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.")
|
||||||
+33648
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user