Пример #1
0
def get_vertices_for_geom(geom: ogr.Geometry) -> List[List[float]]:
    """
    Gets a list of the vertices for the given geometry.

    :param geom: The geomery from which points are to be extracted.
    :type geom: :py:class:`ogr.Geometry`
    :return: A list of points that compose the geometry.
    :rtype: ``[[int, int]]``
    """
    vertices = []
    geom_name = geom.GetGeometryName()
    if geom_name == 'POINT':
        vertices.append([geom.GetPoint()[0], geom.GetPoint()[1]])
    elif geom_name == 'LINEARRING':
        num_vertices = geom.GetPointCount()
        for i in range(0, geom.GetPointCount()):
            point = geom.GetPoint(i)
            vertices.append([point[0], point[1]])
    else:
        geom_count = geom.GetGeometryCount()
        for i in range(0, geom_count):
            geom_ref = geom.GetGeometryRef(i)
            verts = get_vertices_for_geom(geom_ref)
            vertices.append(verts)

    return vertices
Пример #2
0
def Make_Discre_Road_Points(road_geo:ogr.Geometry, 
                           start_points:dict, 
                           seg_length:float):
    '''
    在road_geo上每隔seg_length取一个出发点(魔改版)
    start_point将会是一个元组而不是Startpoint对象
    (离散道路点, 前点, 后点)
    '''

     
    count = road_geo.GetPointCount()
    total_length = road_geo.Length()
    
    '''如果是在递归中seg_length比路的全长还要长,那就把路的最后一个点作为出发点'''
    if seg_length >= total_length:
        start_point_coord = road_geo.GetPoint_2D(count-1)
        point_A_coord = road_geo.GetPoint_2D(count-2)
        point_B_coord = road_geo.GetPoint_2D(count-1)
        start_points[start_point_coord] = (point_A_coord, point_B_coord)
        return 
    
    first_to_current_length = 0
    temp_length = 0
    temp_x1 = None
    temp_y1 = None
    temp_x2 = None
    temp_y2 = None
    
    '''计算当前线段的长度和累计长度'''
    for index in range(count-1):
        temp_x1 = road_geo.GetX(index)              
        temp_y1 = road_geo.GetY(index)  
        temp_x2 = road_geo.GetX(index+1)
        temp_y2 = road_geo.GetY(index+1)
        temp_length = math.sqrt( (temp_x1-temp_x2)**2 + (temp_y1-temp_y2)**2 )
        first_to_current_length = first_to_current_length + temp_length
        if seg_length < first_to_current_length:
            break
    '''这时从第零个点到第index+1个点的距离大于seg_length了'''

    '''算出发点的坐标'''
    len1 = seg_length - (first_to_current_length - temp_length)
    start_point_x = (len1 / temp_length) * (temp_x2 - temp_x1) + temp_x1
    start_point_y = (len1 / temp_length) * (temp_y2 - temp_y1) + temp_y1
    if temp_x1 == 0:
        print([temp_x1, temp_y1])
    start_points[(start_point_x, start_point_y)] = ((temp_x1, temp_y1), (temp_x2, temp_y2))
    
    '''给出发点后面的点做一个线的几何体,用来进行下一个递归'''
    temp_road_geo = ogr.Geometry(ogr.wkbLineString)
    temp_road_geo.AddPoint(start_point_x, start_point_y)
    for i in range(index+1, count):
        temp_x = road_geo.GetX(i)                   
        temp_y = road_geo.GetY(i)        
        temp_road_geo.AddPoint(temp_x, temp_y)
     
    Make_Discre_Road_Points(temp_road_geo, start_points, seg_length)
Пример #3
0
def Make_Start_Points_Road(road_geo:ogr.Geometry, 
                           start_points:dict, 
                           seg_length:float):
    '''在road_geo上每隔seg_length取一个出发点'''

     
    count = road_geo.GetPointCount()
    total_length = road_geo.Length()

    '''如果是在递归中seg_length比路的全长还要长,那就把路的最后一个点作为出发点'''
    if seg_length >= total_length:
        start_point = road_geo.GetPoint_2D(count-1)        
        start_points[start_point] = [road_geo.GetPoint_2D(count-2), road_geo.GetPoint_2D(count-1)] 
        #start_points = {出发点: [前驱点, 后继点]}
        return 
    
    first_to_current_length = 0
    temp_length = 0
    temp_x1 = 0
    temp_y1 = 0
    temp_x2 = 0
    temp_y2 = 0
    
    '''计算当前线段的长度和累计长度'''
    for index in range(count-1):
        temp_x1 = road_geo.GetX(index)              
        temp_y1 = road_geo.GetY(index)  
        temp_x2 = road_geo.GetX(index+1)
        temp_y2 = road_geo.GetY(index+1)
        temp_length = math.sqrt( (temp_x1-temp_x2)**2 + (temp_y1-temp_y2)**2 )
        first_to_current_length = first_to_current_length + temp_length
        if seg_length < first_to_current_length:
            pre_point = (temp_x1, temp_y1)
            nex_point = (temp_x2, temp_y2)
            break
    '''这时从第零个点到第index+1个点的距离大于seg_length了'''

    '''算出发点的坐标'''
    len1 = seg_length - (first_to_current_length - temp_length)
    start_point_x = (len1 / temp_length) * (temp_x2 - temp_x1) + temp_x1
    start_point_y = (len1 / temp_length) * (temp_y2 - temp_y1) + temp_y1
    start_points[(start_point_x, start_point_y)] = [pre_point, nex_point]
    
    '''给出发点后面的点做一个线的几何体,用来进行下一个递归'''
    temp_road_geo = ogr.Geometry(ogr.wkbLineString)
    temp_road_geo.AddPoint(start_point_x, start_point_y)
    for i in range(index+1, count):
        temp_x = road_geo.GetX(i)                   
        temp_y = road_geo.GetY(i)        
        temp_road_geo.AddPoint(temp_x, temp_y)
      
    Make_Start_Points_Road(temp_road_geo, start_points, seg_length)