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

Add handling for missing 'trip_id' key in to_geojson function #426

Merged
merged 2 commits into from
Nov 30, 2023
Merged
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
9 changes: 4 additions & 5 deletions fastapi/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ async def validation_exception_handler(request, err):
def to_geojson(data):
features = []
for item in data:
# Check if trip_id is None before trying to access it
if item.trip_id is None:
# Check if 'trip_id' is in the dictionary before trying to access it
if 'trip_id' not in item or item['trip_id'] is None:
continue # skip this item
# Create a Point from the 'geometry' coordinates
geometry = Point((item.geometry.longitude, item.geometry.latitude))
geometry = Point(item['geometry']['coordinates'])
# Exclude the 'geometry' key from the properties
properties = {key: getattr(item, key) for key in dir(item) if not key.startswith('_') and key != 'geometry'}
properties = {key: value for key, value in item.items() if key != 'geometry'}
feature = Feature(geometry=geometry, properties=properties)
features.append(feature)
feature_collection = FeatureCollection(features)
Expand All @@ -290,7 +290,6 @@ def to_geojson(data):
'timestamp': datetime.now().isoformat()
}
return feature_collection

# code from https://fastapi-restful.netlify.app/user-guide/repeated-tasks/

def csv_to_json(csvFilePath, jsonFilePath):
Expand Down
Loading