In [1]:
import os,sys,inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir) 
import loadOSCdata
import pandas as pd
import numpy as np
import geopandas as gpd
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
data = loadOSCdata.downloadData(OSCid=367385, X = True, Y = True, Z = True, output = 'csv', outputFile = 'data.csv')
data.head()


Out[2]:
timestamp point_id v_value geometry image_url image_lab trip_id
792 2017-05-26 17:15:57.918 0.0 0.761113 POINT (-73.93671009000001 40.704303425) http://storage4.openstreetcam.org/files/photo/... NaN 367385
3462 2017-05-26 17:16:13.945 1.0 8.750670 POINT (-73.936764505 40.70428552) http://storage4.openstreetcam.org/files/photo/... NaN 367385
5727 2017-05-26 17:16:30.904 2.0 25.468589 POINT (-73.93671463999999 40.704234995) http://storage4.openstreetcam.org/files/photo/... NaN 367385
6128 2017-05-26 17:16:34.900 3.0 27.397556 POINT (-73.93687019000001 40.704219665) http://storage4.openstreetcam.org/files/photo/... NaN 367385
6434 2017-05-26 17:16:37.900 4.0 36.878148 POINT (-73.937003105 40.70423295000001) http://storage4.openstreetcam.org/files/photo/... NaN 367385

In [3]:
bufers = gpd.read_file('../data/nyc-bike-routes/nyc_bike_30mbuffer_epsg=3857.shp')
bikelanes=gpd.read_file('../data/nyc-bike-routes/nyc_bike_routes_2017.shp')

In [4]:
pointsDF = loadOSCdata.snapToBikelane(bikelaneDF = bikelanes, bufersDF = bufers, pointsDF = data)
pointsDF.head()


Out[4]:
timestamp point_id v_value geometry image_url image_lab trip_id bikelane_id original_x original_y
792 2017-05-26 17:15:57.918 0.0 0.761113 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.936710 40.704303
3462 2017-05-26 17:16:13.945 1.0 8.750670 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.936765 40.704286
5727 2017-05-26 17:16:30.904 2.0 25.468589 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.936715 40.704235
6128 2017-05-26 17:16:34.900 3.0 27.397556 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.936870 40.704220
6434 2017-05-26 17:16:37.900 4.0 36.878148 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.937003 40.704233

In [5]:
#pointsDF['original_x'] = pointsDF.geometry.map(lambda coord: coord.x)

In [6]:
pointsDF.head()


Out[6]:
timestamp point_id v_value geometry image_url image_lab trip_id bikelane_id original_x original_y
792 2017-05-26 17:15:57.918 0.0 0.761113 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.936710 40.704303
3462 2017-05-26 17:16:13.945 1.0 8.750670 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.936765 40.704286
5727 2017-05-26 17:16:30.904 2.0 25.468589 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.936715 40.704235
6128 2017-05-26 17:16:34.900 3.0 27.397556 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.936870 40.704220
6434 2017-05-26 17:16:37.900 4.0 36.878148 NaN http://storage4.openstreetcam.org/files/photo/... NaN 367385 NaN -73.937003 40.704233

In [8]:
(~pointsDF.geometry.isnull()).sum()


Out[8]:
44

In [ ]:
'''
pointsDF.timestamp = pointsDF.timestamp.map(lambda x: str(x))

point = pointsDF.drop(['line','pointOnLine'],axis=1)
point = point.to_crs(epsg=4326)
point.to_file('point')

line = pointsDF.drop(['geometry','pointOnLine','image_lab'],axis=1)


line.columns = [u'timestamp', u'point_id', u'v_value', u'image_url', 
       u'trip_id', u'geometry', u'bikelanesID']
line = line.dropna().to_crs(epsg=4326)
line.to_file('line')


newPoint = pointsDF.drop(['geometry','line','image_lab'],axis=1)
newPoint.columns = [u'timestamp', u'point_id', u'v_value', u'image_url', u'trip_id',
       u'bikelanesID', u'geometry']
newPoint = newPoint.dropna().to_crs(epsg=4326)
newPoint.to_file('newPoint')
newPoint.head()
'''

In [ ]:


In [ ]:


In [ ]: