Sha256: 212db6a217212627fe689bb9fd21ecfec402a893d3c05dfb7289614bd452c85a

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

module GeoConcerns
  module Processors
    module Vector
      class Info
        attr_accessor :doc
        attr_writer :name, :driver

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

        # Returns the vector dataset name
        # @return [String] dataset name
        def name
          @name = vector_name
        end

        # Returns the ogr driver name
        # @return [String] driver name
        def driver
          @driver = driver_name
        end

        # Returns vector geometry type
        # @return [String] geom
        def geom
          @geom = vector_geom
        end

        private

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

          # Given an output string from the ogrinfo command, returns
          # the vector dataset name.
          # @return [String] vector dataset name
          def vector_name
            match = /(?<=\d:\s).*?((?=\s)|($))/.match(doc)
            match ? match[0] : ''
          end

          # Given an output string from the ogrinfo command, returns
          # the ogr driver used to read dataset.
          # @return [String] ogr driver name
          def driver_name
            match = /(?<=driver\s`).*?(?=')/.match(doc)
            match ? match[0] : ''
          end

          # Given an output string from the ogrinfo command, returns
          # the vector geometry type.
          # @return [String] vector geom
          def vector_geom
            match = /(?<=\().*?(?=\))/.match(doc)
            match ? match[0] : ''
          end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
geo_concerns-0.0.10 app/processors/geo_concerns/processors/vector/info.rb
geo_concerns-0.0.9 app/processors/geo_concerns/processors/vector/info.rb
geo_concerns-0.0.8 app/processors/geo_concerns/processors/vector/info.rb
geo_concerns-0.0.7 app/processors/geo_concerns/processors/vector/info.rb
geo_concerns-0.0.6 app/processors/geo_concerns/processors/vector/info.rb
geo_concerns-0.0.5 app/processors/geo_concerns/processors/vector/info.rb