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

Expand capability of geojson class #694

Merged
merged 14 commits into from
Feb 4, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add error catching in geojson class
vtnate committed Jan 21, 2025
commit 1a87d987df96b4336d4828eb73ab0b5e6511134a
6 changes: 4 additions & 2 deletions geojson_modelica_translator/geojson/urbanopt_geojson.py
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ def __init__(self, filename, building_ids=None, skip_validation=False):
if feature["properties"]["type"] == "Building":
building = UrbanOptLoad(feature)
if not building_ids or building.id in building_ids:
# Ignore validation failures for features with 'detailed_model_filename' in the properties
# Do not attempt validation for features with 'detailed_model_filename' in the properties
# 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)
@@ -78,6 +78,8 @@ def get_feature_by_id(self, feature_id=None):
for feature in self.data.features:
if feature["properties"]["id"] == str(feature_id):
return feature
if feature_id not in self.data.features:
raise KeyError(f"No matches found for id {feature_id}")

def get_feature(self, jsonpath):
"""Return the parameter(s) from a jsonpath.
@@ -99,7 +101,7 @@ def get_feature(self, jsonpath):
# If only one value, then return that value and not a list of values
results = results[0]
elif len(results) == 0:
return print(f"No matches found for jsonpath {jsonpath}")
raise KeyError(f"No matches found for jsonpath {jsonpath}")

# otherwise return the list of values
return results