In [3]:
%matplotlib inline

import pandas as pd

import geopandas
from shapely.geometry import Point, Polygon

pd.options.display.max_rows = 10

In [1]:
# xsv partition transport_mode data BATO_GTFS.csv

In [8]:
stops = pd.read_csv("data/BATO_bus.csv")
stops['geometry'] = stops.apply(lambda z: Point(z.longitude, z.latitude), axis=1)
stops = geopandas.GeoDataFrame(stops)
stops


Out[8]:
source stop_id latitude longitude stop_name transport_mode geometry
0 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL46132 45.716301 4.814736 Gare d'Oullins bus POINT (4.814736 45.716301)
1 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL46133 45.713623 4.817385 Kellermann bus POINT (4.817385 45.713623)
2 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL3167 45.710812 4.820113 Yon Lug bus POINT (4.820113 45.710812)
3 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL3026 45.706046 4.820918 Vaillant Couturier bus POINT (4.820918 45.706046)
4 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL2318 45.702555 4.821277 Pierre-Bénite Centre bus POINT (4.821276999999999 45.702555)
... ... ... ... ... ... ... ...
149200 opendata_GTFS_fr-idf-OIF StopPoint:92:7 48.852338 2.601715 MAIRIE DE CHAMPS bus POINT (2.601715 48.852338)
149201 opendata_GTFS_fr-idf-OIF StopPoint:92:15 48.848283 2.585516 BOIS DE GRACE bus POINT (2.585516 48.848283)
149202 opendata_GTFS_fr-idf-OIF StopPoint:92:9 48.844801 2.582994 AMPERE bus POINT (2.582994 48.844801)
149203 opendata_GTFS_fr-idf-OIF StopPoint:92:11 48.841617 2.584096 CROUS bus POINT (2.584096 48.841617)
149204 opendata_GTFS_fr-idf-OIF StopPoint:92:13 48.794042 2.449382 CRETEIL L'ECHAT bus POINT (2.449382 48.794042)

149205 rows × 7 columns


In [9]:
dptm = geopandas.read_file("data/departements-20140306-5m.shp")
dptm.dropna(inplace=True)

In [10]:
stops = geopandas.sjoin(stops, dptm[['nom', 'geometry']].copy(), op='within')
stops.head()


/home/pclf/.local/share/virtualenvs/tt_bato_maproulette-_HzSl9D-/lib/python3.6/site-packages/geopandas/tools/sjoin.py:56: UserWarning: CRS of frames being joined does not match!(None != {'init': 'epsg:4326'})
  '(%s != %s)' % (left_df.crs, right_df.crs))
Out[10]:
source stop_id latitude longitude stop_name transport_mode geometry index_right nom
0 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL46132 45.716301 4.814736 Gare d'Oullins bus POINT (4.814736 45.716301) 69 b'Rh\xf4ne'
1 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL46133 45.713623 4.817385 Kellermann bus POINT (4.817385 45.713623) 69 b'Rh\xf4ne'
2 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL3167 45.710812 4.820113 Yon Lug bus POINT (4.820113 45.710812) 69 b'Rh\xf4ne'
3 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL3026 45.706046 4.820918 Vaillant Couturier bus POINT (4.820918 45.706046) 69 b'Rh\xf4ne'
4 opendata_GTFS_fr-se-open-GTFS StopPoint:DGL2318 45.702555 4.821277 Pierre-Bénite Centre bus POINT (4.821276999999999 45.702555) 69 b'Rh\xf4ne'

In [11]:
stops.to_csv("data/BATO_by_regions.csv")

In [ ]:
#xsv partition --filename BATO_{}.csv nom . BATO_by_regions.csv