Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow skipping GeoJSON validation #681

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions geojson_modelica_translator/geojson/urbanopt_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UrbanOptGeoJson:
URBANopt GeoJSON files.
"""

def __init__(self, filename, building_ids=None):
def __init__(self, filename, building_ids=None, skip_validation=False):
"""Initialize the UrbanOptGeoJson object by reading the GeoJSON file

:param filename: str, path to the GeoJSON file to parse
Expand All @@ -66,7 +66,8 @@ def __init__(self, filename, building_ids=None):
# Buildings defined by an osm don't have all keys in geojson, therefore will always fail validation
if "detailed_model_filename" not in feature["properties"]:
errors = self.schemas.validate("building", building.feature.properties)
if errors:

if errors and not skip_validation:
building_errors[building.id] = errors
else:
self.buildings.append(building)
Expand Down
6 changes: 5 additions & 1 deletion geojson_modelica_translator/geojson_modelica_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,27 @@ def __init__(
sys_params_filepath,
root_dir,
project_name,
**kwargs,
):
"""Create an instance of this class

:param geojson_filepath: str, path to GeoJSON file
:param sys_params_filepath: str, path to system parameters file
:param root_dir: str, where to create the package
:project_name: str, name of the package
:kwargs: additional keyword arguments
:skip_validation: bool, optional, skip validation of the GeoJSON file
"""
if not Path(geojson_filepath).exists():
raise FileNotFoundError(f"GeoJSON file path does not exist: {geojson_filepath}")
if not Path(sys_params_filepath).exists():
raise FileNotFoundError(f"System parameters file path does not exist: {sys_params_filepath}")

skip_validation = kwargs.get("skip_validation", False)
self._system_parameters = SystemParameters(sys_params_filepath)

geojson_ids = self._system_parameters.get_param("$.buildings.[*].geojson_id")
self._geojson = UrbanOptGeoJson(geojson_filepath, geojson_ids)
self._geojson = UrbanOptGeoJson(geojson_filepath, geojson_ids, skip_validation=skip_validation)

# Use different couplings for each district system type
# The first key of district_system is always the district system type
Expand Down
Loading
Loading