Skip to content

Commit

Permalink
allow skipping GeoJSON validation (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
nllong authored Dec 16, 2024
1 parent f4f0129 commit af549e2
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 173 deletions.
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

0 comments on commit af549e2

Please sign in to comment.