Sha256: afe6c6acd8f3d85de0f6b80b4ed8d9d05619d934d092813bef22bd11251af1db

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

module GeoWorks
  module Processors
    module Raster
      class Info
        attr_accessor :doc
        attr_writer :min_max, :size

        def initialize(path)
          @doc = gdalinfo(path)
        end

        # Returns the min and max values for a raster.
        # @return [String] computed min and max values
        def min_max
          @min_max ||= raster_min_max
        end

        # Returns the raster size.
        # @return [Array] raster size
        def size
          @size ||= raster_size
        end

        private

          # Runs the gdalinfo command and returns the result as a string.
          # @param path [String] path to raster file
          # @return [String] output of gdalinfo
          def gdalinfo(path)
            stdout, _stderr, _status = Open3.capture3("gdalinfo -mm #{path}")
            stdout
          end

          # Given an output string from the gdalinfo command, returns
          # a formatted string for the computed min and max values.
          # @return [String] computed min and max values
          def raster_min_max
            match = %r{(?<=Computed Min/Max=).*?(?=\s)}.match(doc)
            match ? match[0].tr(',', ' ') : ''
          end

          # Given an output string from the gdalinfo command, returns
          # an array containing the raster width and height as strings.
          # @return [String] raster size
          def raster_size
            match = /(?<=Size is ).*/.match(doc)
            match ? match[0].tr(',', '') : ''
          end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
geo_works-0.2.0 app/processors/geo_works/processors/raster/info.rb
geo_works-0.1.4 app/processors/geo_works/processors/raster/info.rb
geo_works-0.1.3 app/processors/geo_works/processors/raster/info.rb
geo_works-0.1.2 app/processors/geo_works/processors/raster/info.rb
geo_works-0.1.1 app/processors/geo_works/processors/raster/info.rb
geo_works-0.1.0 app/processors/geo_works/processors/raster/info.rb