Beispiel #1
0
    def _query(self, geom):
        if self._n_geoms == 0:
            return []

        result = []

        def callback(item, userdata):
            idx = ctypes.cast(item, ctypes.py_object).value
            result.append(idx)

        lgeos.GEOSSTRtree_query(self._tree, geom._geom,
                                lgeos.GEOSQueryCallback(callback), None)
        return result
Beispiel #2
0
    def query(self, geom):
        """Returns a list of objects on the index whose extents
        intersect the given geometry's extents.
        """
        if self._n_geoms == 0:
            return []

        result = []

        def callback(item, userdata):
            geom = ctypes.cast(item, ctypes.py_object).value
            result.append(geom)

        lgeos.GEOSSTRtree_query(self._tree_handle, geom._geom, lgeos.GEOSQueryCallback(callback), None)

        return result
Beispiel #3
0
    def get(self, geom):
        """
        Get a list of identifiers of AtlasEntities whose bounds intersect the
        bounds defined by the geom parameter.
        """
        if self._n_geoms == 0:
            return []

        result = []

        def callback(item, userdata):
            identifier = ctypes.cast(item, ctypes.py_object).value
            result.append(identifier)

        _lgeos.GEOSSTRtree_query(self._tree_handle, geom._geom,
                                 _lgeos.GEOSQueryCallback(callback), None)

        return result
Beispiel #4
0
    def query(self, geom):
        """
        Search the index for geometry objects whose extents
        intersect the extent of the given object.

        Parameters
        ----------
        geom : geometry object
            The query geometry

        Returns
        -------
        list of geometry objects
            All the geometry objects in the index whose extents
            intersect the extent of `geom`.

        Note
        ----
        A geometry object's "extent" is its the minimum xy bounding
        rectangle.

        Examples
        --------

        A buffer around a point can be used to control the extent
        of the query.

        >>> from shapely.strtree import STRtree
        >>> from shapely.geometry import Point
        >>> points = [Point(i, i) for i in range(10)]
        >>> tree = STRtree(points)
        >>> query_geom = Point(2,2).buffer(0.99)
        >>> [o.wkt for o in tree.query(query_geom)]
        ['POINT (2 2)']
        >>> query_geom = Point(2, 2).buffer(1.0)
        >>> [o.wkt for o in tree.query(query_geom)]
        ['POINT (1 1)', 'POINT (2 2)', 'POINT (3 3)']

        A subsequent search through the returned subset using the
        desired binary predicate (eg. intersects, crosses, contains,
        overlaps) may be necessary to further filter the results
        according to their specific spatial relationships.

        >>> [o.wkt for o in tree.query(query_geom) if o.intersects(query_geom)]
        ['POINT (2 2)']

        To get the original indices of the returned objects, create an
        auxiliary dictionary. But use the geometry *ids* as keys since
        the shapely geometry objects themselves are not hashable.

        >>> index_by_id = dict((id(pt), i) for i, pt in enumerate(points))
        >>> [(index_by_id[id(pt)], pt.wkt) for pt in tree.query(Point(2,2).buffer(1.0))]
        [(1, 'POINT (1 1)'), (2, 'POINT (2 2)'), (3, 'POINT (3 3)')]
        """
        if self._n_geoms == 0:
            return []

        result = []

        def callback(item, userdata):
            geom = ctypes.cast(item, ctypes.py_object).value
            result.append(geom)

        lgeos.GEOSSTRtree_query(self._tree_handle, geom._geom, lgeos.GEOSQueryCallback(callback), None)

        return result