Module: GDAL::RasterBandMixins::AlgorithmMethods
- Included in:
- GDAL::RasterBand
- Defined in:
- lib/gdal/raster_band_mixins/algorithm_methods.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#checksum_image(x_offset, y_offset, x_size, y_size) ⇒ Integer
Computes a 16-bit (0-65535) checksum from a region of raster data.
-
#compute_proximity!(proximity_band, progress_function: nil, progress_arg: nil, **options) ⇒ Object
Computes the proximity of all pixels in the proximity_band to those in this band.
-
#fill_nodata!(mask_band, max_search_distance, smoothing_iterations, progress_function: nil, progress_arg: nil, **options) ⇒ Object
Fill selected raster regions by interpolation from the edges.
-
#polygonize(layer, mask_band: nil, pixel_value_field: -1,, use_integer_function: false, progress_function: nil, progress_arg: nil, **options) ⇒ OGR::Layer
Creates vector polygons for all connected regions of pixels in the raster that share a common pixel value.
-
#sieve_filter(size_threshold, connectedness, destination_band, mask_band: nil, progress_function: nil, progress_arg: nil, **options) ⇒ Object
The same as
sieve_filter!
, but returns a new GDAL::RasterBand as the result. -
#sieve_filter!(size_threshold, connectedness, mask_band: nil, progress_function: nil, progress_arg: nil, **options) ⇒ Object
Removes raster polygons that are smaller than the given threshold (in pixels) and replaces them with the pixel value of the largest neighbor polygon.
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 6 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#checksum_image(x_offset, y_offset, x_size, y_size) ⇒ Integer
Computes a 16-bit (0-65535) checksum from a region of raster data. Floating point data is converted to 32-bit integers so decimal portions of the raster data won’t affect the checksum. Real and imaginary components of complex bands influence the result.
98 99 100 101 102 103 104 105 106 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 98 def checksum_image(x_offset, y_offset, x_size, y_size) !!FFI::GDAL::Alg.GDALChecksumImage( @c_pointer, x_offset, y_offset, x_size, y_size ) end |
#compute_proximity!(proximity_band, progress_function: nil, progress_arg: nil, **options) ⇒ Object
Computes the proximity of all pixels in the proximity_band to those in this band. By default all non-zero pixels in this band will be considered as “target”, and all proximities will be computed in pixels. Target pixels are set to the value corresponding to a distance of zero.
Note that this modifies the source band in place with the computed values.
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 133 def compute_proximity!(proximity_band, progress_function: nil, progress_arg: nil, **) proximity_band_ptr = GDAL._pointer(GDAL::RasterBand, proximity_band) = GDAL::Options.pointer() FFI::GDAL::Alg.GDALComputeProximity( @c_pointer, proximity_band_ptr, , progress_function, progress_arg ) end |
#fill_nodata!(mask_band, max_search_distance, smoothing_iterations, progress_function: nil, progress_arg: nil, **options) ⇒ Object
Fill selected raster regions by interpolation from the edges. It interpolates values for all designated nodata pixels (marked by zeroes in mask_band
). For each pixel, a four-direction conic search is done to find values to interpolate from (using inverse distance weighting). Once all values are interpolated, zero or more smoothing iterations (3x3 average filters on interpolated pixels) are applied to smooth out artifacts.
This is generally suitable for interpolating missing regions of fairly continuously varying rasters (such as elevation models, for instance). It is also suitable for filling small holes and cracks in more irregularly varying images (like aerial photos). Its is generally not so great for interpolating a raster from sparse point data. See GDAL::Grid for that case.
Note that this alters values of the current raster band.
TODO: document what valid options are.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 174 def fill_nodata!(mask_band, max_search_distance, smoothing_iterations, progress_function: nil, progress_arg: nil, **) mask_band_ptr = GDAL._pointer(GDAL::RasterBand, mask_band) = GDAL::Options.pointer() !!FFI::GDAL::Alg.GDALFillNodata(@c_pointer, mask_band_ptr, max_search_distance, 0, # deprecated option in GDAL smoothing_iterations, , progress_function, progress_arg) end |
#polygonize(layer, mask_band: nil, pixel_value_field: -1,, use_integer_function: false, progress_function: nil, progress_arg: nil, **options) ⇒ OGR::Layer
Creates vector polygons for all connected regions of pixels in the raster that share a common pixel value. Optionally, each polygon may be labeled with the pixel value in an attribute. Optionally, a mask band can be provided to determine which pixels are eligible for processing.
The C API implements two functions for this: GDALPolygonize
and GDALFPolygonize
, where the former uses a 32-bit Integer buffer and the latter uses a 32-bit Float buffer. The Integer version may be quicker, but the Float version more accurate. As such, calling polygonize
defaults to use the Float version internally, but you can tell it to use the Integer version by using the use_integer_function
flag.
Polygon features will be created on layer
with Polygon geometries representing the polygons. The geometries will be in the georeferenced coordinate system of the image (based on the GeoTransform) of the source Dataset). It is acceptable for layer
to already have other features.
Note that this does not set the coordinate system on the output layer–the application is responsible for doing so.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 228 def polygonize(layer, mask_band: nil, pixel_value_field: -1, use_integer_function: false, progress_function: nil, progress_arg: nil, **) mask_band_ptr = GDAL._pointer(GDAL::RasterBand, mask_band, warn_on_nil: false) layer_ptr = GDAL._pointer(OGR::Layer, layer) raise OGR::InvalidLayer, "Invalid layer: #{layer.inspect}" if layer_ptr.null? log "Pixel value field: #{pixel_value_field}" = GDAL::Options.pointer() function = use_integer_function ? :GDALPolygonize : :GDALFPolygonize FFI::GDAL::Alg.send( function, @c_pointer, # hSrcBand mask_band_ptr, # hMaskBand layer_ptr, # hOutLayer pixel_value_field, # iPixValField , # papszOptions progress_function, # pfnProgress progress_arg # pProgressArg ) layer_ptr.instance_of?(OGR::Layer) ? layer_ptr : OGR::Layer.new(layer_ptr) end |
#sieve_filter(size_threshold, connectedness, destination_band, mask_band: nil, progress_function: nil, progress_arg: nil, **options) ⇒ Object
The same as sieve_filter!
, but returns a new GDAL::RasterBand as the result.
287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 287 def sieve_filter(size_threshold, connectedness, destination_band, mask_band: nil, progress_function: nil, progress_arg: nil, **) _sieve_filter(size_threshold, connectedness, destination_band, mask_band: mask_band, progress_function: progress_function, progress_arg: progress_arg, **) if destination_band.is_a? GDAL::RasterBand destination_band else GDAL::RasterBand.new(destination_band) end end |
#sieve_filter!(size_threshold, connectedness, mask_band: nil, progress_function: nil, progress_arg: nil, **options) ⇒ Object
Removes raster polygons that are smaller than the given threshold (in pixels) and replaces them with the pixel value of the largest neighbor polygon. Polygons are determined as regions of the raster where the pixels all have the same value, and that are contiguous (connected).
If mask_band
is given, “nodata” pixels in the band will not be treated as part of a polygon, regardless of their pixel values.
274 275 276 277 278 279 280 |
# File 'lib/gdal/raster_band_mixins/algorithm_methods.rb', line 274 def sieve_filter!(size_threshold, connectedness, mask_band: nil, progress_function: nil, progress_arg: nil, **) _sieve_filter(size_threshold, connectedness, self, mask_band: mask_band, progress_function: progress_function, progress_arg: progress_arg, **) end |