code: def patterntogeojson(pattern, color=False):
      import geojson
      
       
      # Base properties for the pattern
      properties = dict(
          pid = pattern['pid'],
          length = pattern['ln'],
          direction = pattern['rtdir'],
          color = color or ""
      )        
          
      points = [(float(point.get('lon')), float(point.get('lat'))) for point in pattern['pt']]
      
      return geojson.LineString(coordinates=points, properties=properties)
docs: Turns an an API response of a pattern into a GeoJSON FeatureCollection.
      Takes a dict that contains at least `pid`, `ln`, `rtdir`, and `pt`.
      
      >>> api_response = {'ln': '123.45', 'pid': '1', 'pt': [], 'rtdir': 'OUTBOUND'}
      >>> pt1 = {'lat': '40.449', 'lon': '-79.983', 'seq': '1', 'typ': 'W'}
      >>> pt2 = {'stpid': '1', 'seq': '2', 'stpnm': '3142 Test Ave FS', 'lon': '-79.984', 'pdist': '42.4', 'lat': '40.450', 'typ': 'S'}
      >>> api_response['pt'] = [pt1, pt2]
      >>> patterntogeojson(api_response) # doctest: +ELLIPSIS
      {"features": [{"geometry": {"coordinates": ... "name": "3142 Test Ave FS", "type": "stop"}, "type": "Feature"}], "type": "FeatureCollection"}