I just installed TransitFlow and Preprocessing after following this link :


and I run this line of code :

python transitflow.py --name=chicago --bbox=-87.992249,41.605175,-87.302856,42.126747 --clip_to_bbox --exclude=o-9-amtrak,o-9-amtrakcharteredvehicle

Everything worked fine, except in the end, I got this error :

5 operators successfully downloaded.
0 operators failed.
Concatenating individual operator outputs.
Calculating trip segment bearings.
Traceback (most recent call last):
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2891, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 1675, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'bearing'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\generic.py", line 3571, in _set_item
    loc = self._info_axis.get_loc(key)
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2893, in get_loc
    raise KeyError(key) from err
KeyError: 'bearing'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "transitflow.py", line 406, in <module>
    df['bearing'] = df.apply(lambda row: calc_bearing_between_points(row['start_lat'], row['start_lon'], row['end_lat'], row['end_lon']), axis=1)
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\frame.py", line 3040, in __setitem__
    self._set_item(key, value)
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\frame.py", line 3117, in _set_item
    NDFrame._set_item(self, key, value)
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\generic.py", line 3574, in _set_item
    self._mgr.insert(len(self._info_axis), key, value)
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\internals\managers.py", line 1189, in insert
    block = make_block(values=value, ndim=self.ndim, placement=slice(loc, loc + 1))
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py", line 2719, in make_block
    return klass(values, ndim=ndim, placement=placement)
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py", line 2375, in __init__
    super().__init__(values, ndim=ndim, placement=placement)
  File "C:\Users\Evan\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py", line 130, in __init__
    f"Wrong number of items passed {len(self.values)}, "
ValueError: Wrong number of items passed 8, placement implies 1

The data come from this site : https://transit.land/feed-registry/

I looked into transitflow.py and I retrieved the line of code who's getting me this error (I think) :

 df['bearing'] = df.apply(lambda row: calc_bearing_between_points(row['start_lat'], row['start_lon'], row['end_lat'], row['end_lon']), axis=1)

So I searched the function calc_bearing_between_points in transitflow.py and the script tells me to go to this forum :

# Calculate bearing
# See: https://gis.stackexchange.com/questions/29239/calculate-bearing-between-two-decimal-gps-coordinates/48911
def calc_bearing_between_points(startLat, startLong, endLat, endLong):

    startLat = math.radians(startLat)
    startLong = math.radians(startLong)
    endLat = math.radians(endLat)
    endLong = math.radians(endLong)
    dLong = endLong - startLong
    dPhi = math.log(math.tan(endLat/2.0+math.pi/4.0)/math.tan(startLat/2.0+math.pi/4.0))
    if abs(dLong) > math.pi:
        if dLong > 0.0:
            dLong = -(2.0 * math.pi - dLong)
            dLong = (2.0 * math.pi + dLong)
    bearing = (math.degrees(math.atan2(dLong, dPhi)) + 360.0) % 360.0;
    return bearing

So I came here and I'm asking you if you could help me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.