Class: GDAL::Driver
- Inherits:
-
Object
- Object
- GDAL::Driver
- Includes:
- Extensions, Logger, MajorObject
- Defined in:
- lib/gdal/driver.rb,
lib/gdal/extensions/driver/extensions.rb
Overview
Wrapper for GDAL drivers (aka “formats”). Useful for opening and working with GDAL datasets.
Defined Under Namespace
Modules: Extensions
Constant Summary collapse
- GDAL_DOCS_URL =
"http://gdal.org"
Instance Attribute Summary collapse
-
#c_pointer ⇒ Object
readonly
Returns the value of attribute c_pointer.
Class Method Summary collapse
- .at_index(index) ⇒ GDAL::Driver
- .by_name(name) ⇒ GDAL::Driver
- .count ⇒ Integer
-
.identify_driver(file_path) ⇒ GDAL::Driver
Returns nil if the file is unsupported.
Instance Method Summary collapse
-
#copy_dataset(source_dataset, destination_path, progress_block = nil, progress_arg = nil, strict: true, **options) {|destination_dataset| ... } ⇒ true
Copies
source_dataset
todestination_path
. -
#copy_dataset_files(old_name, new_name) ⇒ Object
Copy all of the associated files of a dataset from one file to another.
-
#create_dataset(filename, x_size, y_size, band_count: 1, data_type: :GDT_Byte, **options) ⇒ GDAL::Dataset
Create a new Dataset with this driver.
-
#creation_option_list ⇒ Array
Lists and describes the options that can be used when calling GDAL::Dataset.create or GDAL::Dataset.create_copy.
-
#delete_dataset(file_name) ⇒ Object
Delete the dataset represented by
file_name
. - #help_topic ⇒ String
-
#initialize(driver) ⇒ Driver
constructor
A new instance of Driver.
- #long_name ⇒ String
- #rename_dataset(old_name, new_name) ⇒ Object
- #short_name ⇒ String
- #validate_creation_options(options) ⇒ Boolean
Methods included from Extensions
#can_copy_datasets?, #can_create_datasets?, #can_do_rasters?, #can_do_vectors?, #can_do_virtual_io?, #can_open_datasets?, #capabilities, included
Methods included from MajorObject
#all_metadata, #description, #description=, #metadata, #metadata_domain_list, #metadata_item, #null?, #set_metadata_item
Constructor Details
Instance Attribute Details
#c_pointer ⇒ Object (readonly)
Returns the value of attribute c_pointer.
54 55 56 |
# File 'lib/gdal/driver.rb', line 54 def c_pointer @c_pointer end |
Class Method Details
.at_index(index) ⇒ GDAL::Driver
37 38 39 40 41 42 43 |
# File 'lib/gdal/driver.rb', line 37 def self.at_index(index) raise InvalidDriverIndex, "index must be between 0 and #{count - 1}." if index > count driver_ptr = FFI::GDAL::GDAL.GDALGetDriver(index) new(driver_ptr) end |
.by_name(name) ⇒ GDAL::Driver
25 26 27 28 29 30 31 |
# File 'lib/gdal/driver.rb', line 25 def self.by_name(name) driver_ptr = FFI::GDAL::GDAL.GDALGetDriverByName(name) raise InvalidDriverName, "'#{name}' is not a valid driver name." if driver_ptr.null? new(driver_ptr) end |
.count ⇒ Integer
17 18 19 |
# File 'lib/gdal/driver.rb', line 17 def self.count FFI::GDAL::GDAL.GDALGetDriverCount end |
.identify_driver(file_path) ⇒ GDAL::Driver
Returns nil if the file is unsupported.
47 48 49 50 51 52 |
# File 'lib/gdal/driver.rb', line 47 def self.identify_driver(file_path) driver_ptr = FFI::GDAL::GDAL.GDALIdentifyDriver(::File.(file_path), nil) return nil if driver_ptr.null? new(driver_ptr) end |
Instance Method Details
#copy_dataset(source_dataset, destination_path, progress_block = nil, progress_arg = nil, strict: true, **options) {|destination_dataset| ... } ⇒ true
Copies source_dataset
to destination_path
. Will yield a writable GDAL::Driver.{GDAL{GDAL::Dataset} of the destination dataset then close it if a block is given.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/gdal/driver.rb', line 187 def copy_dataset(source_dataset, destination_path, progress_block = nil, progress_arg = nil, strict: true, **) source_dataset_ptr = make_dataset_pointer(source_dataset) raise GDAL::OpenFailure, "Source dataset couldn't be read" if source_dataset_ptr&.null? = GDAL::Options.pointer() destination_dataset_ptr = FFI::GDAL::GDAL.GDALCreateCopy( @c_pointer, destination_path, source_dataset_ptr, strict, , progress_block, progress_arg ) raise CreateFail if destination_dataset_ptr.nil? || destination_dataset_ptr.null? if block_given? dataset = Dataset.new(destination_dataset_ptr, "w") yield(dataset) dataset.close end true end |
#copy_dataset_files(old_name, new_name) ⇒ Object
Copy all of the associated files of a dataset from one file to another.
126 127 128 129 130 |
# File 'lib/gdal/driver.rb', line 126 def copy_dataset_files(old_name, new_name) GDAL::CPLErrorHandler.manually_handle("Unable to copy dataset files: '#{old_name}' -> '#{new_name}'") do FFI::GDAL::GDAL.GDALCopyDatasetFiles(@c_pointer, new_name, old_name) end end |
#create_dataset(filename, x_size, y_size, band_count: 1, data_type: :GDT_Byte, **options) ⇒ GDAL::Dataset
Create a new Dataset with this driver. Legal arguments depend on the driver and can’t be retrieved programmatically. NOTE: In order to write out all data to the destination, you must call #close on the dataset!
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/gdal/driver.rb', line 144 def create_dataset(filename, x_size, y_size, band_count: 1, data_type: :GDT_Byte, **) = GDAL::Options.pointer() dataset_pointer = FFI::GDAL::GDAL.GDALCreate( @c_pointer, filename, x_size, y_size, band_count, data_type, ) raise CreateFail if dataset_pointer.null? dataset = GDAL::Dataset.new(dataset_pointer, "w") if block_given? result = yield(dataset) dataset.close result else dataset end end |
#creation_option_list ⇒ Array
Lists and describes the options that can be used when calling GDAL::Dataset.create or GDAL::Dataset.create_copy.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gdal/driver.rb', line 92 def creation_option_list return [] unless @c_pointer # The returned string should not be freed and is owned by the driver. creation_option_list_xml, ptr = FFI::GDAL::GDAL.GDALGetDriverCreationOptionList(@c_pointer) ptr.autorelease = false root = MultiXml.parse(creation_option_list_xml) return [] if root.nil? || root.empty? list = root["CreationOptionList"] return [] if list.nil? || list.empty? list["Option"] end |
#delete_dataset(file_name) ⇒ Object
Delete the dataset represented by file_name
. Depending on the driver, this could mean deleting associated files, database objects, etc.
220 221 222 223 224 |
# File 'lib/gdal/driver.rb', line 220 def delete_dataset(file_name) GDAL::CPLErrorHandler.manually_handle("Unable to delete dataset: #{file_name}") do FFI::GDAL::GDAL.GDALDeleteDataset(@c_pointer, file_name) end end |
#help_topic ⇒ String
80 81 82 83 84 85 86 |
# File 'lib/gdal/driver.rb', line 80 def help_topic # The returned string should not be freed and is owned by the driver. url, ptr = FFI::GDAL::GDAL.GDALGetDriverHelpTopic(@c_pointer) ptr.autorelease = false "#{GDAL_DOCS_URL}/#{url}" end |
#long_name ⇒ String
71 72 73 74 75 76 77 |
# File 'lib/gdal/driver.rb', line 71 def long_name # The returned string should not be freed and is owned by the driver. name, ptr = FFI::GDAL::GDAL.GDALGetDriverLongName(@c_pointer) ptr.autorelease = false name end |
#rename_dataset(old_name, new_name) ⇒ Object
229 230 231 232 233 |
# File 'lib/gdal/driver.rb', line 229 def rename_dataset(old_name, new_name) GDAL::CPLErrorHandler.manually_handle("Unable to rename dataset: #{old_name}") do FFI::GDAL::GDAL.GDALRenameDataset(@c_pointer, new_name, old_name) end end |