Example #1
0
def test_path_no_doubled_point_in_to_polygon():
    hand = np.array(
        [[1.64516129, 1.16145833],
         [1.64516129, 1.59375],
         [1.35080645, 1.921875],
         [1.375, 2.18229167],
         [1.68548387, 1.9375],
         [1.60887097, 2.55208333],
         [1.68548387, 2.69791667],
         [1.76209677, 2.56770833],
         [1.83064516, 1.97395833],
         [1.89516129, 2.75],
         [1.9516129, 2.84895833],
         [2.01209677, 2.76041667],
         [1.99193548, 1.99479167],
         [2.11290323, 2.63020833],
         [2.2016129, 2.734375],
         [2.25403226, 2.60416667],
         [2.14919355, 1.953125],
         [2.30645161, 2.36979167],
         [2.39112903, 2.36979167],
         [2.41532258, 2.1875],
         [2.1733871, 1.703125],
         [2.07782258, 1.16666667]])

    (r0, c0, r1, c1) = (1.0, 1.5, 2.1, 2.5)

    poly = Path(np.vstack((hand[:, 1], hand[:, 0])).T, closed=True)
    clip_rect = transforms.Bbox([[r0, c0], [r1, c1]])
    poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0]

    assert np.all(poly_clipped[-2] != poly_clipped[-1])
    assert np.all(poly_clipped[-1] == poly_clipped[0])
Example #2
0
def test_path_no_doubled_point_in_to_polygon():
    hand = np.array(
        [[1.64516129, 1.16145833],
         [1.64516129, 1.59375],
         [1.35080645, 1.921875],
         [1.375, 2.18229167],
         [1.68548387, 1.9375],
         [1.60887097, 2.55208333],
         [1.68548387, 2.69791667],
         [1.76209677, 2.56770833],
         [1.83064516, 1.97395833],
         [1.89516129, 2.75],
         [1.9516129, 2.84895833],
         [2.01209677, 2.76041667],
         [1.99193548, 1.99479167],
         [2.11290323, 2.63020833],
         [2.2016129, 2.734375],
         [2.25403226, 2.60416667],
         [2.14919355, 1.953125],
         [2.30645161, 2.36979167],
         [2.39112903, 2.36979167],
         [2.41532258, 2.1875],
         [2.1733871, 1.703125],
         [2.07782258, 1.16666667]])

    (r0, c0, r1, c1) = (1.0, 1.5, 2.1, 2.5)

    poly = Path(np.vstack((hand[:, 1], hand[:, 0])).T, closed=True)
    clip_rect = transforms.Bbox([[r0, c0], [r1, c1]])
    poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0]

    assert np.all(poly_clipped[-2] != poly_clipped[-1])
    assert np.all(poly_clipped[-1] == poly_clipped[0])
    def search_satellite(self, point, polygon):
        polygon_path = Path(polygon, closed=True)  # ?
        image = self.utils.center_image("satellite", point,
                                        self.zoom)  # /samples/staticmap2
        masked_image = self.utils.mask_image(image, polygon)  # masked image
        grayscale_image = self.utils.grayscale(
            masked_image)  # grayscaled masked image
        lot_paths = []

        edge_image = filters.prewitt(
            grayscale_image)  # image with prewitt operator applied
        edge_regions = self.regions.search(edge_image)  # 4 region boxes

        for region in edge_regions:
            region_image = masked_image[region[0][0]:region[1][0],
                                        region[0][1]:region[1]
                                        [1], :]  # splice image into regions
            profile = self.profiler.profile(region_image)  # ???

            if profile == PolygonProfile.LOT:
                bbox = self.utils.region_to_bbox(region)
                lot_paths.append(polygon_path.clip_to_bbox(bbox, inside=True))

        if self.debug and len(lot_paths) > 0:
            self.utils.draw_path_on_image(image, lot_paths)

        return lot_paths
Example #4
0
def square_polygon_intersection(xmin, xmax, ymin, ymax, x, y):
    poly = Path(zip(x, y))
    box = Bbox([[xmin, ymin], [xmax, ymax]])
    try:
        clipped_poly = poly.clip_to_bbox(box)
    except ValueError:
        return [], []
    else:
        return clipped_poly.vertices[:, 0], clipped_poly.vertices[:, 1]