def test_within_radius(self): """ Get the points near to another point using a quadtree approach. """ crs = karta.crs.LonLatWGS84 pt = karta.Point((0.0, 30.0), crs=crs) np.random.seed(42) x = (np.random.random(1000) - 0.5) * 180.0 y = (np.random.random(1000) - 0.5) * 30.0 mp_noindex = karta.Multipoint(zip(x, y), crs=crs, build_index=False) mp = karta.Multipoint(zip(x, y), crs=crs, build_index=True) subset_noindex = mp_noindex.within_radius(pt, 5e6) subset = mp.within_radius(pt, 5e6) self.assertEqual(len(subset), len(subset_noindex)) for i in range(0, len(subset), 50): self.assertTrue(subset[i] in subset_noindex) return
def test_sample_multipoint(self): grid = RegularGrid([0.0, 0.0, 1.0, 1.0, 0.0, 0.0], values=np.array([[0, 1], [1, 0.5]])) mp = karta.Multipoint([(0.6, 0.7), (0.6, 1.3), (1.4, 0.3), (1.6, 1.3)], crs=grid.crs) self.assertTrue( np.all( np.allclose(grid.sample(mp, method="nearest"), np.array([0.0, 1.0, 1.0, 0.5]))))
def test_polygon_contains(self): """ Search for points contained within a polygon, using a quadtree. """ crs = karta.crs.SphericalEarth th = np.linspace(-np.pi, np.pi, 18) xp = 5 * np.cos(th) yp = 5 * np.sin(th) poly = karta.Polygon(zip(xp, yp), crs=crs) np.random.seed(42) x = (np.random.random(1000) - 0.5) * 180.0 y = (np.random.random(1000) - 0.5) * 30.0 mp_noindex = karta.Multipoint(zip(x, y), crs=crs, build_index=False) mp = karta.Multipoint(zip(x, y), crs=crs, build_index=True) contained_noindex = mp_noindex.within_polygon(poly) contained = mp.within_polygon(poly) self.assertEqual(len(contained), len(contained_noindex)) for i in range(len(contained)): self.assertTrue(contained[i] in contained_noindex) return