coordinates - Using Python with VK API, how can I get the checkins from a particular street? -
i've been using vk api places.getcheckins method check-ins particular street , use them sentiment analysis.
for work have specify latitude , longitude parameters. i've downloaded streets coordinates in geojson format:
{ ... "properties": { ... "name": "a-street-so-called", ... }, "geometry": { "type": "linestring", "coordinates": [ [ 37.399092526176915, 55.715745258737407 ], [ 37.398983226159537, 55.715823964808216 ] ] } }
you can download here (166 mb).
from these coordinates specified street script:
def get_streets(name): coordinates = [] in data['features']: try: if i['properties']['name'] == name: coordinates.append(i['geometry']['coordinates']) except: none return coordinates
that results in (i think of ("type":"linestring")):
[ [37.625916884336014, 55.67560424062041], [37.62689513625539, 55.67304407211511], [37.62689513625539, 55.67304407211511], [37.627487820628794, 55.671551422797954], [37.63091308536064, 55.66356606746359], [37.631465368960754, 55.663102380580035], ... ]
or this, if there more 1 instance of street in geojson file ("type":"multilinestring"):
[ [ [37.625916884336014, 55.67560424062041], [37.62689513625539, 55.67304407211511] ], [ [37.62689513625539, 55.67304407211511], [37.627487820628794, 55.671551422797954] ], [ [37.63091308536064, 55.66356606746359], [37.631465368960754, 55.663102380580035], ... ], ... ]
but there gaps between coordinates on straight parts of street:
i filling them with:
def calc_points(lat_0, lon_0, lat_1, lon_1): """ function takes in 2 coordinates , returns list of new coordinates, lie on line between first two. """ new_points = [] y_displacement = lat_0 - lat_1 x_displacement = lon_0 - lon_1 # using formula line: y = m * x + b. m = y_displacement / x_displacement b = lat_0 - m * lon_0 x = lon_0 if lon_1 > lon_0: while x < lon_1: x += 0.00001 lat_new = round(m * x + b, 6) new_points.append((x, lat_new)) elif lon_0 > lon_1: while x > lon_1: x -= 0.00001 lat_new = round(m * x + b, 6) new_points.append((x, lat_new)) return new_points
then trying automate of this:
def calc_streets(coordinates): j = 0 # check if coordinates list nested if coordinates[0][0] != none: in coordinates: threshold = len(i) - 1 while j < threshold: new = calc_points(i[j][1], i[j][0], i[j+1][1], i[j+1][0]) coordinates.append(new) j += 1 else: threshold = len(coordinates) - 1 while j < threshold: new = calc_points(coordinates[j][1], coordinates[j][0], coordinates[j+1][1], coordinates[j+1][0]) coordinates.append(new) j += 1
that gets me wondering if there better way check-ins. thanks.
Comments
Post a Comment