예제 #1
0
    def time_tree_nearest_all_poly_python(self):
        # returns all input points

        # use an arbitrary search tolerance that seems appropriate for the density of
        # geometries
        tolerance = 200
        b = shapely.buffer(self.points, tolerance, quadsegs=1)
        left, right = self.tree.query(b)
        dist = shapely.distance(self.points.take(left),
                                self.polygons.take(right))

        # sort by left, distance
        ix = np.lexsort((right, dist, left))
        left = left[ix]
        right = right[ix]
        dist = dist[ix]

        run_start = np.r_[True, left[:-1] != left[1:]]
        run_counts = np.diff(np.r_[np.nonzero(run_start)[0], left.shape[0]])

        mins = dist[run_start]

        # spread to rest of array so we can extract out all within each group that match
        all_mins = np.repeat(mins, run_counts)
        ix = dist == all_mins
        left = left[ix]
        right = right[ix]
        dist = dist[ix]
예제 #2
0
    def time_tree_nearest_points_equidistant_manual_all(self):
        # This benchmark approximates nearest_all for equidistant results
        # starting from singular nearest neighbors and searching for more
        # within same distance.

        # try to find all equidistant neighbors ourselves given single nearest
        # result
        l, r = self.grid_point_tree.nearest(self.grid_points)
        # calculate distance to nearest neighbor
        dist = shapely.distance(self.grid_points.take(l),
                                self.grid_point_tree.geometries.take(r))
        # include a slight epsilon to ensure nearest are within this radius
        b = shapely.buffer(self.grid_points, dist + 1e-8)

        # query the tree for others in the same buffer distance
        left, right = self.grid_point_tree.query(b, predicate="intersects")
        dist = shapely.distance(self.grid_points.take(left),
                                self.grid_point_tree.geometries.take(right))

        # sort by left, distance
        ix = np.lexsort((right, dist, left))
        left = left[ix]
        right = right[ix]
        dist = dist[ix]

        run_start = np.r_[True, left[:-1] != left[1:]]
        run_counts = np.diff(np.r_[np.nonzero(run_start)[0], left.shape[0]])

        mins = dist[run_start]

        # spread to rest of array so we can extract out all within each group that match
        all_mins = np.repeat(mins, run_counts)
        ix = dist == all_mins
        left = left[ix]
        right = right[ix]
        dist = dist[ix]
예제 #3
0
 def time_distance(self):
     shapely.distance(self.points, self.polygon)
예제 #4
0
파일: base.py 프로젝트: mwtoews/shapely
 def distance(self, other):
     """Unitless distance to other geometry (float)"""
     return float(shapely.distance(self, other))
예제 #5
0
def test_distance_missing():
    actual = shapely.distance(point, None)
    assert np.isnan(actual)
예제 #6
0
def test_distance():
    actual = shapely.distance(*point_polygon_testdata)
    expected = [2 * 2**0.5, 2**0.5, 0, 0, 0, 2**0.5]
    np.testing.assert_allclose(actual, expected)
예제 #7
0
def test_distance_empty():
    actual = shapely.distance(point, empty)
    assert np.isnan(actual)