Class: OGR::Driver
Overview
Wrapper for OGR’s Driver class. In this case, to use a driver, find the driver you’re looking for using .by_name
or .by_index
; that will return an instance of an OGR::Driver.
More about the C API here: www.gdal.org/ogr_drivertut.html.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#can_create_data_source?, #can_delete_data_source?
#all_metadata, #description, #description=, #metadata, #metadata_domain_list, #metadata_item, #null?, #set_metadata_item
Constructor Details
#initialize(driver) ⇒ Driver
You probably don’t want to use this directly–see .by_name and .at_index to instantiate a OGR::Driver object.
57
58
59
|
# File 'lib/ogr/driver.rb', line 57
def initialize(driver)
@c_pointer = GDAL._pointer(OGR::Driver, driver)
end
|
Instance Attribute Details
#c_pointer ⇒ FFI::Pointer
51
52
53
|
# File 'lib/ogr/driver.rb', line 51
def c_pointer
@c_pointer
end
|
Class Method Details
36
37
38
39
40
41
42
43
|
# File 'lib/ogr/driver.rb', line 36
def self.at_index(index)
raise OGR::DriverNotFound, index if index > count
driver_ptr = FFI::OGR::API.OGRGetDriver(index)
raise OGR::DriverNotFound, index if driver_ptr.null?
new(driver_ptr)
end
|
25
26
27
28
29
30
|
# File 'lib/ogr/driver.rb', line 25
def self.by_name(name)
driver_ptr = FFI::OGR::API.OGRGetDriverByName(name)
raise OGR::DriverNotFound, name if driver_ptr.null?
new(driver_ptr)
end
|
18
19
20
|
# File 'lib/ogr/driver.rb', line 18
def self.count
FFI::OGR::API.OGRGetDriverCount
end
|
.names ⇒ Array<String>
46
47
48
|
# File 'lib/ogr/driver.rb', line 46
def self.names
Array.new(count) { |i| at_index(i).name }.sort
end
|
Instance Method Details
#copy_data_source(source_data_source, new_file_name, **options) ⇒ OGR::DataSource?
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/ogr/driver.rb', line 122
def copy_data_source(source_data_source, new_file_name, **options)
source_ptr = GDAL._pointer(OGR::DataSource, source_data_source)
raise OGR::InvalidDataSource, source_data_source if source_ptr.nil? || source_ptr.null?
options_ptr = GDAL::Options.pointer(options)
data_source_ptr =
FFI::OGR::API.OGR_Dr_CopyDataSource(@c_pointer, source_ptr, new_file_name, options_ptr)
raise OGR::InvalidDataSource, "Unable to copy data source to #{new_file_name}" if data_source_ptr.null?
OGR::DataSource.new(data_source_ptr, nil)
end
|
#create_data_source(file_name, **options) {|ds| ... } ⇒ OGR::DataSource?
Creates a new data source at path file_name
. Yields the newly created data source to a block, if given. NOTE: in order to write out all in-memory data, you need to call #close on the created DataSource.
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/ogr/driver.rb', line 89
def create_data_source(file_name, **options)
unless test_capability("CreateDataSource")
raise OGR::UnsupportedOperation, "This driver does not support data source creation."
end
options_ptr = GDAL::Options.pointer(options)
data_source_ptr = FFI::OGR::API.OGR_Dr_CreateDataSource(@c_pointer,
file_name, options_ptr)
raise OGR::CreateFailure, "Unable to create DataSource '#{file_name}'" if data_source_ptr.null?
ds = OGR::DataSource.new(data_source_ptr, "w")
yield ds if block_given?
ds
end
|
#delete_data_source(file_name) ⇒ Object
108
109
110
111
112
113
114
115
116
|
# File 'lib/ogr/driver.rb', line 108
def delete_data_source(file_name)
unless test_capability("DeleteDataSource")
raise OGR::UnsupportedOperation, "This driver does not support deleting data sources."
end
OGR::ErrorHandling.handle_ogr_err("Unable to delete data source '#{file_name}'") do
FFI::OGR::API.OGR_Dr_DeleteDataSource(@c_pointer, file_name)
end
end
|
62
63
64
65
66
67
|
# File 'lib/ogr/driver.rb', line 62
def name
name, ptr = FFI::OGR::API.OGR_Dr_GetName(@c_pointer)
ptr.autorelease = false
name
end
|
#open(file_name, access_flag = "r") ⇒ OGR::DataSource?
72
73
74
75
76
77
78
79
80
|
# File 'lib/ogr/driver.rb', line 72
def open(file_name, access_flag = "r")
update = OGR._boolean_access_flag(access_flag)
data_source_ptr = FFI::OGR::API.OGR_Dr_Open(@c_pointer, file_name, update)
raise OGR::InvalidDataSource, "Unable to open data source at #{file_name}" if data_source_ptr.null?
OGR::DataSource.new(data_source_ptr, nil)
end
|
#test_capability(capability) ⇒ Boolean
139
140
141
|
# File 'lib/ogr/driver.rb', line 139
def test_capability(capability)
FFI::OGR::API.OGR_Dr_TestCapability(@c_pointer, capability)
end
|