diff --git a/data/majid_bello.geojson b/data/majid_bello.geojson new file mode 100644 index 00000000..96b306fd --- /dev/null +++ b/data/majid_bello.geojson @@ -0,0 +1,90 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Multipolygon", + "coordinates": [ + [ + [ + [ + -81.36226736610345, + 42.96538327741903 + ], + [ + -81.36226606408695, + 42.96539751865368 + ], + [ + -81.36169147743192, + 42.96539971389088 + ], + [ + -81.36169145437769, + 42.96539577872095 + ], + [ + -81.36160750096705, + 42.965396296109915 + ], + [ + -81.36167659355637, + 42.96554865177412 + ], + [ + -81.36143594626003, + 42.96560572998295 + ], + [ + -81.3612605719971, + 42.9652212961923 + ], + [ + -81.36153890966588, + 42.96521432093572 + ], + [ + -81.36172317324467, + 42.9651651651121 + ], + [ + -81.3617438333442, + 42.965204767431615 + ], + [ + -81.36220126106349, + 42.96509245874135 + ], + [ + -81.36231896772036, + 42.96532755243104 + ], + [ + -81.36230203685074, + 42.96533218062799 + ], + [ + -81.36232060244981, + 42.9653700064552 + ], + [ + -81.36226736610345, + 42.96538327741903 + ] + ] + ] + ] + }, + "id": 1, + "properties": { + "name": "Shifton Head Office", + "address": "N/A", + "function": 1000, + "height": 14, + "year_of_construction": 2017, + "adjacency": "attached" + } + } + ] +} \ No newline at end of file diff --git a/data/test.geojson b/data/test.geojson new file mode 100644 index 00000000..a5e2bc96 --- /dev/null +++ b/data/test.geojson @@ -0,0 +1,88 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -81.36226736610345, + 42.96538327741903 + ], + [ + -81.36226606408695, + 42.96539751865368 + ], + [ + -81.36169147743192, + 42.96539971389088 + ], + [ + -81.36169145437769, + 42.96539577872095 + ], + [ + -81.36160750096705, + 42.965396296109915 + ], + [ + -81.36167659355637, + 42.96554865177412 + ], + [ + -81.36143594626003, + 42.96560572998295 + ], + [ + -81.3612605719971, + 42.9652212961923 + ], + [ + -81.36153890966588, + 42.96521432093572 + ], + [ + -81.36172317324467, + 42.9651651651121 + ], + [ + -81.3617438333442, + 42.965204767431615 + ], + [ + -81.36220126106349, + 42.96509245874135 + ], + [ + -81.36231896772036, + 42.96532755243104 + ], + [ + -81.36230203685074, + 42.96533218062799 + ], + [ + -81.36232060244981, + 42.9653700064552 + ], + [ + -81.36226736610345, + 42.96538327741903 + ] + ] + ] + }, + "id": 1, + "properties": { + "name": "Shifton Head Office", + "address": "N/A", + "function": "1000", + "height": 14, + "year_of_construction": 2017, + "adjacency": "attached" + } + } + ] +} \ No newline at end of file diff --git a/data/test_updated.geojson b/data/test_updated.geojson new file mode 100644 index 00000000..4b3973a7 --- /dev/null +++ b/data/test_updated.geojson @@ -0,0 +1 @@ +{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-81.36226736610345, 42.96538327741903], [-81.36232060244981, 42.9653700064552], [-81.36230203685074, 42.96533218062799], [-81.36231896772036, 42.96532755243104], [-81.36220126106349, 42.96509245874135], [-81.3617438333442, 42.965204767431615], [-81.36172317324467, 42.9651651651121], [-81.36153890966588, 42.96521432093572], [-81.3612605719971, 42.9652212961923], [-81.36143594626003, 42.96560572998295], [-81.36167659355637, 42.96554865177412], [-81.36160750096705, 42.965396296109915], [-81.36169145437769, 42.96539577872095], [-81.36169147743192, 42.96539971389088], [-81.36226606408695, 42.96539751865368], [-81.36226736610345, 42.96538327741903]]]}, "id": 1, "properties": {"name": "Shifton Head Office", "address": "N/A", "function": "1000", "height": 14, "year_of_construction": 2017, "adjacency": "attached"}}]} \ No newline at end of file diff --git a/hub/imports/construction/helpers/construction_helper.py b/hub/imports/construction/helpers/construction_helper.py index 8eaf758c..bd6476c7 100644 --- a/hub/imports/construction/helpers/construction_helper.py +++ b/hub/imports/construction/helpers/construction_helper.py @@ -58,7 +58,8 @@ class ConstructionHelper: 'Boucherville': '6', 'Mascouche': '6', 'Saint-Leonard': '6', - 'La Prairie': '6' + 'La Prairie': '6', + 'London': '6' } _reference_city_to_israel_climate_zone = { diff --git a/majid_test.py b/majid_test.py new file mode 100644 index 00000000..8ee6f4b7 --- /dev/null +++ b/majid_test.py @@ -0,0 +1,29 @@ +from hub.imports.energy_systems_factory import EnergySystemsFactory +from hub.imports.geometry_factory import GeometryFactory +from hub.helpers.dictionaries import Dictionaries +from hub.imports.construction_factory import ConstructionFactory +from hub.imports.results_factory import ResultFactory +from hub.exports.exports_factory import ExportsFactory +import subprocess +from pathlib import Path + +from hub.imports.weather_factory import WeatherFactory + +input_file = "data/test_updated.geojson" +demand_file = "data/energy_demand_data.csv" +# Define specific paths for outputs from SRA (Simplified Radiosity Algorith) and PV calculation processes +output_path = (Path(__file__).parent.parent / 'out_files').resolve() +output_path.mkdir(parents=True, exist_ok=True) +sra_output_path = output_path / 'sra_outputs' +sra_output_path.mkdir(parents=True, exist_ok=True) +pv_assessment_path = output_path / 'pv_outputs' +pv_assessment_path.mkdir(parents=True, exist_ok=True) +city = GeometryFactory( + "geojson", + input_file, + height_field="height", + year_of_construction_field="year_of_construction", + function_field="function", + adjacency_field="adjacency", + function_to_hub=Dictionaries().montreal_function_to_hub_function).city +ConstructionFactory('nrcan', city).enrich() diff --git a/shapely_test.py b/shapely_test.py new file mode 100644 index 00000000..416a8f0e --- /dev/null +++ b/shapely_test.py @@ -0,0 +1,46 @@ +import json +from shapely.geometry import shape, mapping, MultiPolygon, Polygon +from shapely.ops import unary_union +from pathlib import Path + +def enforce_right_hand_rule(geojson): + for feature in geojson['features']: + geometry = shape(feature['geometry']) + if isinstance(geometry, Polygon): + if not geometry.exterior.is_ccw: + geometry = Polygon(geometry.exterior.coords[::-1], [interior.coords[::-1] for interior in geometry.interiors]) + elif isinstance(geometry, MultiPolygon): + new_polygons = [] + for polygon in geometry.geoms: # Use .geoms to iterate over the individual polygons + if not polygon.exterior.is_ccw: + polygon = Polygon(polygon.exterior.coords[::-1], [interior.coords[::-1] for interior in polygon.interiors]) + new_polygons.append(polygon) + geometry = MultiPolygon(new_polygons) + feature['geometry'] = mapping(geometry) + return geojson + +data_path = Path(__file__).parent.parent / 'hub/data' # Adjust this path as needed +# Load the GeoJSON file +input_filepath = data_path / 'test.geojson' +output_filepath = data_path / 'test_updated.geojson' + +with open(input_filepath, 'r') as f: + geojson_data = json.load(f) + +# Iterate through the features and convert MultiPolygons to Polygons +for feature in geojson_data['features']: + geom = shape(feature['geometry']) + if isinstance(geom, MultiPolygon): + # Merge the polygons into a single polygon + merged_polygon = unary_union(geom) + # Convert the merged polygon back to GeoJSON format + feature['geometry'] = mapping(merged_polygon) + +# Enforce the right-hand rule +geojson_data = enforce_right_hand_rule(geojson_data) + +# Save the updated GeoJSON file +with open(output_filepath, 'w') as f: + json.dump(geojson_data, f) + +