Skip to content

Commit

Permalink
refactor: [api] to_geojson function to handle None
Browse files Browse the repository at this point in the history
trip_id values
  • Loading branch information
albertkun committed Nov 29, 2023
1 parent 944e2e3 commit bbfb97f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fastapi/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +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:
continue # skip this item
# Create a Point from the 'geometry' coordinates
geometry = Point(item['geometry']['coordinates'])
geometry = Point((item.geometry.longitude, item.geometry.latitude))
# Exclude the 'geometry' key from the properties
properties = {key: item[key] for key in item if key != 'geometry'}
properties = {key: getattr(item, key) for key in dir(item) if not key.startswith('_') and key != 'geometry'}
feature = Feature(geometry=geometry, properties=properties)
features.append(feature)
feature_collection = FeatureCollection(features)
Expand Down

0 comments on commit bbfb97f

Please sign in to comment.