Пример #1
0
def minkowski_sum_circle_shapely_polygon(polygon: shapely.geometry.Polygon,
                                         radius: float, resolution: int) -> np.ndarray:
    """
    Computes the minkowski sum of a provided polygon and a circle with
    parametrized radius

    :param polygon: The polygon as a numpy array with columns as x and y
    coordinates
    :param radius: The radius of the circle
    :return: The minkowski sum of the provided polygon and the circle with the
    parametrized radius
    """
    assert isinstance(polygon, shapely.geometry.Polygon), \
        '<> Provided polygon is not an instance of shapely.geometry.Polygon,' \
        ' polygon = {}'.format(polygon)
    assert radius > 0, '<> Provided radius must be positive. radius = {}'. \
        format(radius)
    # dilation with round cap style (style = 1)
    dilation = polygon.buffer(radius, cap_style=1, resolution=resolution)
    if isinstance(dilation, shapely.geometry.MultiPolygon):
        polys = [polygon for polygon in dilation]
        for p in polys:
            p_vertices = list()
            vertices = p.exterior.coords
            for v in vertices:
                p_vertices.append(np.array([v[0], v[1]]))
    # convert to array
    else:
        p_vertices = list()
        vertices = dilation.exterior.coords
        for v in vertices:
            p_vertices.append(np.array([v[0], v[1]]))
    return np.array(p_vertices)
Пример #2
0
def aggregate_polygons(polygons:dict,
		       poly_bbox:shapely.geometry.Polygon,
		       intersect=False) -> shapely.geometry.MultiPolygon:
    """returns a MultiPolygon Object from all Buildings"""
    if intersect:
        return MultiPolygon([poly_bbox.intersection(polygons[i]) for i in polygons])
    else:
        return MultiPolygon([polygons[i] for i in polygons])
Пример #3
0
def subtract(poly_main: shapely.geometry.Polygon,
             poly_tool: shapely.geometry.Polygon):
    """Geometry subtract tool poly from main poly.

    Args:
        poly_main (Polygon): Main polygon from which we will carve out
        poly_tool (Polygon or list): Poly or list of polys to subtract

    Returns:
        Polygon: Difference between the given Polygons
    """
    return poly_main.difference(poly_tool)
Пример #4
0
def _does_obstruct_target_helper(performer_start_position: Dict[str, float],
                                 target_or_location: Dict[str, Any],
                                 object_poly: shapely.geometry.Polygon,
                                 fully: bool = False) -> bool:

    obstructing_points = 0
    performer_start_coordinates = (performer_start_position['x'],
                                   performer_start_position['z'])
    bounds = target_or_location.get(
        'boundingBox',
        target_or_location.get('shows', [{
            'boundingBox': []
        }])[0]['boundingBox'])

    target_poly = rect_to_poly(bounds)
    target_center = target_poly.centroid.coords[0]
    points = bounds + [{'x': target_center[0], 'z': target_center[1]}]

    if not fully:
        for index, next_point in enumerate(bounds):
            previous_point = bounds[(index - 1) if (index > 0) else -1]
            line_full = shapely.geometry.LineString([
                (previous_point['x'], previous_point['z']),
                (next_point['x'], next_point['z'])
            ])
            line_full_center = line_full.centroid.coords[0]
            center_point = {'x': line_full_center[0], 'z': line_full_center[1]}
            points.append(center_point)
            for point_1, point_2 in [(previous_point, center_point),
                                     (center_point, next_point)]:
                line = shapely.geometry.LineString([
                    (point_1['x'], point_1['z']), (point_2['x'], point_2['z'])
                ])
                line_center = line.centroid.coords[0]
                points.append({'x': line_center[0], 'z': line_center[1]})

    for point in points:
        target_corner_coordinates = (point['x'], point['z'])
        line_to_target = shapely.geometry.LineString(
            [performer_start_coordinates, target_corner_coordinates])
        if object_poly.intersects(line_to_target):
            obstructing_points += 1
    return obstructing_points == 5 if fully else obstructing_points > 0