Ejemplo n.º 1
0
    def regular_grid(self, width, height, overlap=0.0, units='native'):
        """Create a dataframe that defines the a regular grid of samples.

        The width and height are given in pixels and multiplied by the
        pixel size of the raster to create samples at the native
        resolution of the raster.

        Note: in this context width and height are unrelated to the 
        DL model inputs.

        Args:
          width (int): sample size 
          height (int): sample size
          units (str): units applied to sample sizes ('native' or 'pixels')
          overlap (float): percentage overlap (default=0.0)

        Returns:
          (GeoDataframe)
        """

        if not self.src:
            raise RuntimeError('source not set or failed to open')

        if units == 'pixels':
            dims = width * self.src.res[0], height * self.src.res[1]
        elif units == 'native':
            dims = width, height
        else:
            raise ValueError('units must be "native" or "pixels"')

        gdf = grid.regular_grid(*self.src.bounds, *dims, overlap=overlap)
        gdf.crs = self.src.crs
        return gdf
Ejemplo n.º 2
0
    def regular_grid(self, width, height, overlap=0.0, units='native'):
        """Create a dataframe that defines the a regular grid of samples.

        When units='native', width and height are given in projection
        units (i.e. meters, feet, etc). The number of pixels within this
        area would depend on the pixel size. If units='pixel', width
        and height are multiplied by the pixel size to compute the
        sample boundaries.

        Note: width and height are unrelated to the DL model inputs.

        Args:
          width (int): sample size 
          height (int): sample size
          units (str): units applied to sample sizes ('native' or 'pixels')
          overlap (float): percentage overlap (default=0.0)

        Returns:
          (GeoDataframe)
        """

        if not self.src:
            raise RuntimeError('source not set or failed to open')

        if units == 'pixels':
            dims = width * self.src.res[0], height * self.src.res[1]
        elif units == 'native':
            dims = width, height
        else:
            raise ValueError('units must be "native" or "pixels"')

        gdf = grid.regular_grid(*self.src.bounds, *dims, overlap=overlap)
        gdf.crs = self.src.crs
        return gdf
Ejemplo n.º 3
0
    def regular_grid(self, width=0, height=0, overlap=0.0):
        """Create a dataframe that defines the a regular grid of samples.

        The width and height are given in pixels and multiplied by the
        pixel size of the raster to create samples at the native
        resolution of the raster.

        Args:
          width (int): sample size in pixels 
          height (int): sample size in pixels
          overlap (float): percentage overlap (default=0.0)

        Returns:
          (GeoDataframe)
        """

        width = width if width else self.width
        height = height if height else self.height
        if width < 1 or height < 1:
            raise ValueError('width and height must be specified')

        if not self.src:
            raise RuntimeError('source not set or failed to open')

        dims = width * self.src.res[0], height * self.src.res[1]
        gdf = grid.regular_grid(*self.src.bounds, *dims, overlap=overlap)
        gdf.crs = self.src.crs
        return gdf
Ejemplo n.º 4
0
def test_regular_grid_overlap():
    bounds, _, _ = grid.raster_meta('data/small.tif')
    size = (bounds[2]-bounds[0], bounds[3]-bounds[1])
    size = [i/10 for i in size]

    df = grid.regular_grid(*bounds, *size, overlap=.5)
    assert len(df) == 400
    assert df.total_bounds[0] >= bounds[0]
    assert df.total_bounds[1] >= bounds[1]
    assert df.total_bounds[2] <= bounds[2]
    assert df.total_bounds[3] <= bounds[3]