Exemplo n.º 1
0
def along(line, distance, units):
    if line["type"] == 'Feature':
        coords = line["geometry"]["coordinates"]
    elif line["type"] == 'LineString':
        coords = line["coordinates"]
    else:
        raise ValueError("input must be a LineString Feature or Geometry")

    travelled = 0
    for i in range(len(coords)):
        if distance >= travelled and (i == len(coords) - 1):
            break
        elif travelled >= distance:
            overshot = distance - travelled
            if not overshot:
                return Point(coords[i])
            else:
                direction = bearing(coords[i], coords[i - 1]) - 180
                interpolated = destination(coords[i], overshot, direction,
                                           units)
                return interpolated
        else:
            travelled += measure_distance(coords[i], coords[i + 1], units)

    return Point(coords[coords.length - 1])
Exemplo n.º 2
0
def inner_function(pt, coords, units):
    closest_pt = Point((float("inf"), float("inf")), {
        "dist": float("inf")
    })
    for i in range(len(coords)):
        start = Point(coords[i])
        stop = Point(coords[i + 1])
        # start
        start.properties.dist = distance(pt, start, units)
        # stop
        stop.properties.dist = distance(pt, stop, units)
        # perpendicular
        height_distance = max(start.properties.dist, stop.properties.dist)
        direction = bearing(start, stop)
        perpendicular_pt1 = destination(pt, height_distance, direction + 90, units)
        perpendicular_pt2 = destination(pt, height_distance, direction - 90, units)
        intersect = line_intersects(
            perpendicular_pt1.geometry.coordinates[0],
            perpendicular_pt1.geometry.coordinates[1],
            perpendicular_pt2.geometry.coordinates[0],
            perpendicular_pt2.geometry.coordinates[1],
            start.geometry.coordinates[0],
            start.geometry.coordinates[1],
            stop.geometry.coordinates[0],
            stop.geometry.coordinates[1]
        )

        if intersect:
            intersect_pt = Point(intersect)
            intersect_pt.properties.dist = distance(pt, intersect_pt, units)

        if start.properties.dist < closest_pt.properties.dist:
            closest_pt = start
            closest_pt.properties.index = i
        if stop.properties.dist < closest_pt.properties.dist:
            closest_pt = stop
            closest_pt.properties.index = i
        if intersect_pt and intersect_pt.properties.dist < closest_pt.properties.dist:
            closest_pt = intersect_pt
            closest_pt.properties.index = i

    return closest_pt
Exemplo n.º 3
0
def circle(center, radius, steps, units):
    steps = steps or 64
    coordinates = []

    for i in range(steps):
        point = destination(center, radius, i * 360 / steps, units)
        coordinates.append(point["geometry"]["coordinates"])

    coordinates.append(coordinates[0])

    return Polygon([coordinates])
Exemplo n.º 4
0
def line_slice_along(line, start_dist, stop_dist, units):
    slice = []
    if line["type"] == 'Feature':
        coords = line.geometry.coordinates
    elif line["type"] == 'LineString':
        coords = line.coordinates
    else:
        raise ValueError('input must be a LineString Feature or Geometry')

    travelled = 0
    for i in range(len(coords)):
        if start_dist >= travelled and i == coords.length - 1:
            break
        elif travelled > start_dist and len(slice) == 0:
            overshot = start_dist - travelled
            if not overshot:
                return slice.append(coords[i])
            direction = bearing(coords[i], coords[i - 1]) - 180
            interpolated = destination(coords[i], overshot, direction, units)
            slice.append(interpolated.geometry.coordinates)

        if travelled >= stop_dist:
            overshot = stop_dist - travelled
            if not overshot:
                return slice.append(coords[i])
            direction = bearing(coords[i], coords[i - 1]) - 180
            interpolated = destination(coords[i], overshot, direction, units)
            slice.append(interpolated.geometry.coordinates)
            return LineString(tuple(slice))

        if travelled >= start_dist:
            slice.append(coords[i])

        travelled += distance(coords[i], coords[i + 1], units)

    return LineString(coords[coords.length - 1])
Exemplo n.º 5
0
def midpoint(point_from, point_to):
    dist = distance(point_from, point_to, 'miles')
    heading = bearing(point_from, point_to)

    return destination(point_from, dist / 2, heading, 'miles')