Sha256: ea69b308d4482cbc89c2b484b884fe47a5c3acc1ae271ae038af0c818ec0d206

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

require "bundler/setup"
require "ffi-gdal"

GDAL::Logger.logging_enabled = true

colors = %w[644d1e 745924 856728 95742b a5812d b69930 c8b22d d8cb3c e8e65a
            f4ee79 e0e457 c8da42 afd135 97b73c 7e993c 657e36 4b612c 314441 23295e
            282973]

floyd_path = File.join(__dir__, "../spec/support/images/Floyd/Floyd_1058_20140612_NRGB.tif")
floyd = GDAL::Dataset.open(floyd_path, "r")

#---
# Extracting...
#---

# NIR
floyd.extract_nir("nir.tif", 1).close

# Natural Color
floyd.extract_natural_color("nc.tif", band_order: %i[nir red green blue]).close

# NDVI as Float32
floyd.extract_ndvi("ndvi_float.tif", band_order: %i[nir red green blue],
                                     data_type: :GDT_Float32,
                                     remove_negatives: true).close

# NDVI as Byte
floyd.extract_ndvi("ndvi_byte.tif", band_order: %i[nir red green blue],
                                    data_type: :GDT_Byte,
                                    remove_negatives: true,
                                    photometric: "PALETTE").close

# NDVI as UInt16
floyd.extract_ndvi("ndvi_uint16.tif", band_order: %i[nir red green blue],
                                      data_type: :GDT_UInt16,
                                      remove_negatives: true,
                                      photometric: "PALETTE").close

#---
# Colorize after extraction...
#---

byte_dataset = GDAL::Dataset.open("ndvi_byte.tif", "w")
byte_band = byte_dataset.raster_band(1)
byte_band.colorize!(*colors)
byte_dataset.close

uint16_dataset = GDAL::Dataset.open("ndvi_uint16.tif", "w")
uint16_band = uint16_dataset.raster_band(1)
uint16_band.colorize!(*colors)
uint16_dataset.close

g_byte_dataset = GDAL::Dataset.open("gndvi_byte.tif", "w")
g_byte_band = g_byte_dataset.raster_band(1)
g_byte_band.colorize!(*colors)
g_byte_dataset.close

g_uint16_dataset = GDAL::Dataset.open("gndvi_uint16.tif", "w")
g_uint16_band = g_uint16_dataset.raster_band(1)
g_uint16_band.colorize!(*colors)
g_uint16_dataset.close

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-gdal-1.1.0 examples/extract_and_colorize.rb
ffi-gdal-1.0.4 examples/extract_and_colorize.rb
ffi-gdal-1.0.3 examples/extract_and_colorize.rb