Class: RGdal::Base
Instance Attribute Summary collapse
-
#current_layer ⇒ Object
readonly
Returns the value of attribute current_layer.
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
Instance Method Summary collapse
- #add_column(name, options = {}) ⇒ Object (also: #layer_field_definition)
- #close ⇒ Object
- #create_field_definition(name, options) ⇒ Object
- #feature(longitude, latitude, attributes = {}) ⇒ Object
-
#initialize(source) ⇒ Base
constructor
A new instance of Base.
- #layer(filename) ⇒ Object
- #layers ⇒ Object
- #new_layer(filename = 'export') ⇒ Object
- #switch_layer(name) ⇒ Object
Methods included from API
Constructor Details
#initialize(source) ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 |
# File 'lib/rgdal/base.rb', line 13 def initialize(source) @source = source @data_source = driver.create_data_source(@source) @current_layer = layers.first @columns = @current_layer ? @current_layer.fields.map(&:name) : [] end |
Instance Attribute Details
#current_layer ⇒ Object (readonly)
Returns the value of attribute current_layer.
6 7 8 |
# File 'lib/rgdal/base.rb', line 6 def current_layer @current_layer end |
#data_source ⇒ Object (readonly)
Returns the value of attribute data_source.
5 6 7 |
# File 'lib/rgdal/base.rb', line 5 def data_source @data_source end |
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
7 8 9 |
# File 'lib/rgdal/base.rb', line 7 def driver @driver end |
Instance Method Details
#add_column(name, options = {}) ⇒ Object Also known as: layer_field_definition
52 53 54 55 56 57 58 |
# File 'lib/rgdal/base.rb', line 52 def add_column(name, ={}) , name = {type: Gdal::Ogr::OFTSTRING, width: 254}.merge(), header(name) @columns.push(name) field_definition = create_field_definition(name, ) @current_layer.create_field(field_definition) field_definition = nil end |
#close ⇒ Object
45 46 47 48 49 50 |
# File 'lib/rgdal/base.rb', line 45 def close @driver = nil @data_source = nil @current_layer = nil @columns = nil end |
#create_field_definition(name, options) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/rgdal/base.rb', line 62 def create_field_definition(name, ) Gdal::Ogr::FieldDefn.new(name, [:type]).tap do |field| field.set_width([:width]) if [:width] field.set_precision([:precision]) if [:precision] end end |
#feature(longitude, latitude, attributes = {}) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/rgdal/base.rb', line 69 def feature(longitude, latitude, attributes={}) feat = Gdal::Ogr::Feature.new(@current_layer.definition) set_geometry(latitude, longitude, feat) set_attributes(attributes, feat) @current_layer.create_feature(feat) @current_layer.reset_reading end |
#layer(filename) ⇒ Object
41 42 43 |
# File 'lib/rgdal/base.rb', line 41 def layer(filename) @data_source.create_layer(filename, reference, format) end |
#layers ⇒ Object
20 21 22 |
# File 'lib/rgdal/base.rb', line 20 def layers @layers = @data_source.layers end |
#new_layer(filename = 'export') ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/rgdal/base.rb', line 33 def new_layer(filename='export') layer(filename).tap do |layer| @current_layer = layer @layers << layer @columns = [] end end |
#switch_layer(name) ⇒ Object
28 29 30 31 |
# File 'lib/rgdal/base.rb', line 28 def switch_layer(name) @current_layer = @layers.select { |layer| layer.name == name }.first @columns = @current_layer ? @current_layer.fields.map(&:name) : [] end |