monthly_energy_balance_work.../geojson_building_extracter.py

23 lines
675 B
Python
Raw Normal View History

2023-03-20 14:28:17 -04:00
from pathlib import Path
import json
try:
file_path = (Path(__file__).parent / 'input_files' / 'part.geojson')
output_file_path = (Path(__file__).parent / 'input_files' / 'selected_building.geojson').resolve()
selected_building = 5755
with open(file_path) as json_file:
_geojson = json.loads(json_file.read())
features = [_geojson['features'][selected_building - 1]]
output_json = {"type": "FeatureCollection",
"features": features
}
json_object = json.dumps(output_json, indent=4)
with open(output_file_path, "w") as outfile:
outfile.write(json_object)
except Exception as ex:
print(ex)
print('error: ', ex)