Sha256: 209dbafe6951e78c354a698cf0ea8d3bde8cfeb087155ea845f27c56d7ffb1ad

Contents?: true

Size: 1.52 KB

Versions: 17

Compression:

Stored size: 1.52 KB

Contents

module GeoConcerns
  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

17 entries across 17 versions & 1 rubygems

Version Path
geo_concerns-0.3.4 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.3.3 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.3.2 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.3.1 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.3.0 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.2.0 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.1.1 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.1.0 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.10 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.9 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.8 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.7 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.6 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.5 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.4 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.3 app/processors/geo_concerns/processors/raster/info.rb
geo_concerns-0.0.2 app/processors/geo_concerns/processors/raster/info.rb