使用Python和vkapi,如何从特定街道获取签入?

使用Python和vkapi,如何从特定街道获取签入?,python,coordinates,openstreetmap,vk,Python,Coordinates,Openstreetmap,Vk,我一直在使用从特定街道获取的登记,然后使用它们进行情绪分析 为了让它工作,我必须指定纬度和经度参数。 我下载了一些GeoJSON格式的街道坐标: { ... "properties": { ... "name": "a-street-so-called", ... }, "geometry": { "type": "LineString", "coordinates": [ [ 37.399092526

我一直在使用从特定街道获取的登记,然后使用它们进行情绪分析

为了让它工作,我必须指定纬度和经度参数。 我下载了一些GeoJSON格式的街道坐标:

{
 ...
 "properties": { 
     ...
     "name": "a-street-so-called", 
     ... 
  }, 
  "geometry": { 
     "type": "LineString", 
     "coordinates": [ 
         [ 37.399092526176915, 55.715745258737407 ], 
         [ 37.398983226159537, 55.715823964808216 ] 
     ] 
  } 
 }
你可以下载它(166MB)

通过这些,我可以通过脚本获得指定街道的坐标:

def get_streets(name):
    coordinates = []
    for i in data['features']:
        try:
            if i['properties']['name'] == name:
                coordinates.append(i['geometry']['coordinates'])
        except:
            None
     return coordinates
结果是这样的(我认为它是一个(“类型”:“LineString”):

或者,如果GeoJSON文件中有多个街道实例(“类型”:“MultiLineString”):

但街道笔直部分的坐标之间存在间隙:

我将用以下内容填充它们:

def calc_points(lat_0, lon_0, lat_1, lon_1):
    """
    The function takes in two coordinates and returns a
    list of new coordinates, which lie on the line between
    the first two.
    """
    new_points = []
    y_displacement = lat_0 - lat_1
    x_displacement = lon_0 - lon_1
    # Using the formula for a 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
def校准点(纬度0、经度0、纬度1、经度1):
"""
函数接受两个坐标并返回一个
新坐标的列表,位于
前两个。
"""
新的_点=[]
y_位移=lat_0-lat_1
x_位移=lon_0-lon_1
#对直线使用公式:y=m*x+b。
m=y_位移/x_位移
b=纬度0-m*lon\u 0
x=lon_0
如果lon_1>lon_0:
当xlon_1:
当x>lonu 1时:
x-=0.00001
lat_新=圆形(m*x+b,6)
新点。附加((x,lat新))
返回新的积分
然后我尝试将所有这些自动化:

def calc_streets(coordinates):
    j = 0
    # check if the coordinates list is nested
    if coordinates[0][0] != None:
        for i 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
def calc_街道(坐标):
j=0
#检查坐标列表是否嵌套
如果坐标[0][0]!=无:
对于坐标中的i:
阈值=len(i)-1
而j<阈值:
新=计算点(i[j][1],
i[j][0],,
i[j+1][1],
i[j+1][0])
坐标。追加(新)
j+=1
其他:
阈值=len(坐标)-1
而j<阈值:
新=计算点(坐标[j][1],
坐标[j][0],
坐标[j+1][1],
坐标[j+1][0])
坐标。追加(新)
j+=1
这让我想知道是否有更好的方式办理入住手续。
谢谢。

因为我不熟悉VK,所以我看不出你的主要目标。您是否尝试获取所有门店/。。。在一条街道内,所有登录过这家商店的用户?@MaM,不,不是商店。我正在努力了解交通堵塞时人们的信息。
def calc_points(lat_0, lon_0, lat_1, lon_1):
    """
    The function takes in two coordinates and returns a
    list of new coordinates, which lie on the line between
    the first two.
    """
    new_points = []
    y_displacement = lat_0 - lat_1
    x_displacement = lon_0 - lon_1
    # Using the formula for a 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
def calc_streets(coordinates):
    j = 0
    # check if the coordinates list is nested
    if coordinates[0][0] != None:
        for i 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