rtree/index.py
def _create_idx_from_stream(self, stream):
        """This function is used to instantiate the index given an
        iterable stream of data."""

        stream_iter = iter(stream)
        dimension = self.properties.dimension
        darray = ctypes.c_double * dimension
        mins = darray()
        maxs = darray()
        no_data = ctypes.cast(ctypes.pointer(ctypes.c_ubyte(0)),
                              ctypes.POINTER(ctypes.c_ubyte))

        def py_next_item(p_id, p_mins, p_maxs, p_dimension, p_data, p_length):
            """This function must fill pointers to individual entries that will
            be added to the index.  The C API will actually call this function
            to fill out the pointers.  If this function returns anything other
            than 0, it is assumed that the stream of data is done."""

            try:
                p_id[0], coordinates, obj = next(stream_iter)
            except StopIteration:
                # we're done
                return -1
            except Exception as exc:
                self._exception = exc
                return -1

            if self.interleaved:
                coordinates = Index.deinterleave(coordinates)

            # this code assumes the coords are not interleaved.
            # xmin, xmax, ymin, ymax, zmin, zmax
            for i in range(dimension):
                mins[i] = coordinates[i*2]
                maxs[i] = coordinates[(i*2)+1]

            p_mins[0] = ctypes.cast(mins, ctypes.POINTER(ctypes.c_double))
            p_maxs[0] = ctypes.cast(maxs, ctypes.POINTER(ctypes.c_double))

            # set the dimension
            p_dimension[0] = dimension
            if obj is None:
                p_data[0] = no_data
                p_length[0] = 0
            else:
                p_length[0], data, _ = self._serialize(obj)
                p_data[0] = ctypes.cast(data, ctypes.POINTER(ctypes.c_ubyte))

            return 0

        stream = core.NEXTFUNC(py_next_item)
        return IndexStreamHandle(self.properties.handle, stream)
def _create_idx_from_stream(self, stream):
        stream_iter = iter(stream)
        dimension = self.properties.dimension
        darray = ctypes.c_double * dimension
        mins = darray()
        maxs = darray()
        no_data = ctypes.cast(ctypes.pointer(ctypes.c_ubyte(0)),
                              ctypes.POINTER(ctypes.c_ubyte))

        def py_next_item(p_id, p_mins, p_maxs, p_dimension, p_data, p_length):
            """This function must fill pointers to individual entries that will
            be added to the index.  The C API will actually call this function
            to fill out the pointers.  If this function returns anything other
            than 0, it is assumed that the stream of data is done."""

            try:
                p_id[0], coordinates, obj = next(stream_iter)
            except StopIteration:
                # we're done
                return -1
            except Exception as exc:
                self._exception = exc
                return -1

            if self.interleaved:
                coordinates = Index.deinterleave(coordinates)

            # this code assumes the coords are not interleaved.
            # xmin, xmax, ymin, ymax, zmin, zmax
            for i in range(dimension):
                mins[i] = coordinates[i*2]
                maxs[i] = coordinates[(i*2)+1]

            p_mins[0] = ctypes.cast(mins, ctypes.POINTER(ctypes.c_double))
            p_maxs[0] = ctypes.cast(maxs, ctypes.POINTER(ctypes.c_double))

            # set the dimension
            p_dimension[0] = dimension
            if obj is None:
                p_data[0] = no_data
                p_length[0] = 0
            else:
                p_length[0], data, _ = self._serialize(obj)
                p_data[0] = ctypes.cast(data, ctypes.POINTER(ctypes.c_ubyte))

            return 0

        stream = core.NEXTFUNC(py_next_item)
        return IndexStreamHandle(self.properties.handle, stream)
def _create_idx_from_stream ( self , stream ) : stream_iter = iter ( stream ) dimension = self . properties . dimension darray = ctypes . c_double * dimension mins = darray ( ) maxs = darray ( ) no_data = ctypes . cast ( ctypes . pointer ( ctypes . c_ubyte ( 0 ) ) , ctypes . POINTER ( ctypes . c_ubyte ) ) def py_next_item ( p_id , p_mins , p_maxs , p_dimension , p_data , p_length ) : """This function must fill pointers to individual entries that will
            be added to the index.  The C API will actually call this function
            to fill out the pointers.  If this function returns anything other
            than 0, it is assumed that the stream of data is done.""" try : p_id [ 0 ] , coordinates , obj = next ( stream_iter ) except StopIteration : # we're done return - 1 except Exception as exc : self . _exception = exc return - 1 if self . interleaved : coordinates = Index . deinterleave ( coordinates ) # this code assumes the coords are not interleaved. # xmin, xmax, ymin, ymax, zmin, zmax for i in range ( dimension ) : mins [ i ] = coordinates [ i * 2 ] maxs [ i ] = coordinates [ ( i * 2 ) + 1 ] p_mins [ 0 ] = ctypes . cast ( mins , ctypes . POINTER ( ctypes . c_double ) ) p_maxs [ 0 ] = ctypes . cast ( maxs , ctypes . POINTER ( ctypes . c_double ) ) # set the dimension p_dimension [ 0 ] = dimension if obj is None : p_data [ 0 ] = no_data p_length [ 0 ] = 0 else : p_length [ 0 ] , data , _ = self . _serialize ( obj ) p_data [ 0 ] = ctypes . cast ( data , ctypes . POINTER ( ctypes . c_ubyte ) ) return 0 stream = core . NEXTFUNC ( py_next_item ) return IndexStreamHandle ( self . properties . handle , stream )
This function is used to instantiate the index given an
        iterable stream of data.
This function is used to instantiate the index given an iterable stream of data .