Class: GDAL::Driver

Inherits:
Object
  • Object
show all
Includes:
FFI::GDAL, MajorObject, LogSwitch::Mixin
Defined in:
lib/ffi-gdal/driver.rb

Constant Summary collapse

GDAL_DOCS_URL =
'http://gdal.org'

Constants included from FFI::GDAL

FFI::GDAL::ALTER_ALL_FLAG, FFI::GDAL::ALTER_NAME_FLAG, FFI::GDAL::ALTER_TYPE_FLAG, FFI::GDAL::ALTER_WIDTH_PRECISION_FLAG, FFI::GDAL::AppDefined, FFI::GDAL::AssertionFailed, FFI::GDAL::CPLES_BackslashQuotable, FFI::GDAL::CPLES_CSV, FFI::GDAL::CPLES_SQL, FFI::GDAL::CPLES_URL, FFI::GDAL::CPLES_XML, FFI::GDAL::CPLES_XML_BUT_QUOTES, FFI::GDAL::CPLE_WrongFormat, FFI::GDAL::CPLErr, FFI::GDAL::CPLValueType, FFI::GDAL::CPL_ENC_ASCII, FFI::GDAL::CPL_ENC_ISO8859_1, FFI::GDAL::CPL_ENC_LOCALE, FFI::GDAL::CPL_ENC_UCS2, FFI::GDAL::CPL_ENC_UCS4, FFI::GDAL::CPL_ENC_UTF16, FFI::GDAL::CPL_ENC_UTF8, FFI::GDAL::CSLT_ALLOWEMPTYTOKENS, FFI::GDAL::CSLT_HONOURSTRINGS, FFI::GDAL::CSLT_PRESERVEESCAPES, FFI::GDAL::CSLT_PRESERVEQUOTES, FFI::GDAL::CSLT_STRIPENDSPACES, FFI::GDAL::CSLT_STRIPLEADSPACES, FFI::GDAL::FileIO, FFI::GDAL::GDALAccess, FFI::GDAL::GDALAsyncStatusType, FFI::GDAL::GDALColorInterp, FFI::GDAL::GDALDataType, FFI::GDAL::GDALMD_AOP_AREA, FFI::GDAL::GDALMD_AOP_POINT, FFI::GDAL::GDALMD_AREA_OR_POINT, FFI::GDAL::GDALPaletteInterp, FFI::GDAL::GDALRATFieldType, FFI::GDAL::GDALRATFieldUsage, FFI::GDAL::GDALRWFlag, FFI::GDAL::GDALTileOrganization, FFI::GDAL::GDAL_DCAP_CREATE, FFI::GDAL::GDAL_DCAP_CREATECOPY, FFI::GDAL::GDAL_DCAP_OPEN, FFI::GDAL::GDAL_DCAP_RASTER, FFI::GDAL::GDAL_DCAP_VECTOR, FFI::GDAL::GDAL_DCAP_VIRTUALIO, FFI::GDAL::GDAL_DMD_CREATIONDATATYPES, FFI::GDAL::GDAL_DMD_CREATIONOPTIONLIST, FFI::GDAL::GDAL_DMD_EXTENSION, FFI::GDAL::GDAL_DMD_EXTENSIONS, FFI::GDAL::GDAL_DMD_HELPTOPIC, FFI::GDAL::GDAL_DMD_LONGNAME, FFI::GDAL::GDAL_DMD_MIMETYPE, FFI::GDAL::GDAL_DMD_OPTIONLIST, FFI::GDAL::GDAL_DMD_SUBDATASETS, FFI::GDAL::GDAL_DS_LAYER_CREATIONOPTIONLIST, FFI::GDAL::GDAL_OF_ALL, FFI::GDAL::GDAL_OF_RASTER, FFI::GDAL::GDAL_OF_READONLY, FFI::GDAL::GDAL_OF_SHARED, FFI::GDAL::GDAL_OF_UPDATE, FFI::GDAL::GDAL_OF_VECTOR, FFI::GDAL::GDAL_OF_VERBOSE_ERROR, FFI::GDAL::GMF_ALL_VALID, FFI::GDAL::GMF_ALPHA, FFI::GDAL::GMF_NODATA, FFI::GDAL::GMF_PER_DATASET, FFI::GDAL::IllegalArg, FFI::GDAL::NoWriteAccess, FFI::GDAL::None, FFI::GDAL::NotSupported, FFI::GDAL::ODrCCreateDataSource, FFI::GDAL::ODrCDeleteDataSource, FFI::GDAL::ODsCCreateGeomFieldAfterCreateLayer, FFI::GDAL::ODsCCreateLayer, FFI::GDAL::ODsCDeleteLayer, FFI::GDAL::OGRAxisOrientation, FFI::GDAL::OGRDatumType, FFI::GDAL::OGRERR_CORRUPT_DATA, FFI::GDAL::OGRERR_FAILURE, FFI::GDAL::OGRERR_INVALID_HANDLE, FFI::GDAL::OGRERR_NONE, FFI::GDAL::OGRERR_NOT_ENOUGH_DATA, FFI::GDAL::OGRERR_NOT_ENOUGH_MEMORY, FFI::GDAL::OGRERR_UNSUPPORTED_GEOMETRY_TYPE, FFI::GDAL::OGRERR_UNSUPPORTED_OPERATION, FFI::GDAL::OGRERR_UNSUPPORTED_SRS, FFI::GDAL::OGRFieldType, FFI::GDAL::OGRJustification, FFI::GDAL::OGRNullFID, FFI::GDAL::OGRStyleToolClassID, FFI::GDAL::OGRStyleToolParamBrushID, FFI::GDAL::OGRStyleToolParamLabelID, FFI::GDAL::OGRStyleToolParamPenID, FFI::GDAL::OGRStyleToolParamSymbolID, FFI::GDAL::OGRStyleToolUnitsID, FFI::GDAL::OGRUnsetMarker, FFI::GDAL::OGR_Z_MARKER, FFI::GDAL::OGRwkbByteOrder, FFI::GDAL::OGRwkbGeometryType, FFI::GDAL::OGRwkbVariant, FFI::GDAL::OLCAlterFieldDefn, FFI::GDAL::OLCCreateField, FFI::GDAL::OLCCreateGeomField, FFI::GDAL::OLCDeleteFeature, FFI::GDAL::OLCDeleteField, FFI::GDAL::OLCFastFeatureCount, FFI::GDAL::OLCFastGetExtent, FFI::GDAL::OLCFastSetNextByIndex, FFI::GDAL::OLCFastSpatialFilter, FFI::GDAL::OLCIgnoreFields, FFI::GDAL::OLCRandomRead, FFI::GDAL::OLCRandomeWrite, FFI::GDAL::OLCReorderFields, FFI::GDAL::OLCSequentialWrite, FFI::GDAL::OLCStringsAsUTF8, FFI::GDAL::OLCTransactions, FFI::GDAL::ObjectNull, FFI::GDAL::OpenFailed, FFI::GDAL::OutOfMemory, FFI::GDAL::UserInterrupt, FFI::GDAL::VERSION, FFI::GDAL::VSI_STAT_EXISTS_FLAG, FFI::GDAL::VSI_STAT_NATURE_FLAG, FFI::GDAL::VSI_STAT_SIZE_FLAG, FFI::GDAL::WKB_25D_BIT

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MajorObject

#all_metadata, #description, #description=, #metadata_domain_list, #metadata_for_domain, #metadata_item, #null?

Methods included from FFI::GDAL

#CPLFree, #cpla_assert, find_lib, #gdal_check_version, gdal_library_path, search_paths, #srcval, #validate_pointer0, #validate_pointer1, #validate_pointer_err

Constructor Details

#initialize(file_path: file_path, name: name, index: index, dataset: dataset) ⇒ Driver

Creates a new GDAL::Driver object based on the mutually exclusive given parameters. Pass in only one of the allowed parameters.

Parameters:

  • file_path (String) (defaults to: file_path)

    File to get the driver for.

  • name (String) (defaults to: name)

    Name of the registered GDALDriver.

  • index (Fixnum) (defaults to: index)

    Index of the registered driver. Must be less than GDAL::Driver.driver_count.

  • dataset (FFI::Pointer) (defaults to: dataset)

    Pointer to the GDALDataset.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ffi-gdal/driver.rb', line 33

def initialize(file_path: file_path, name: name, index: index, dataset: dataset)
  @gdal_driver_handle = if file_path
    GDALIdentifyDriver(::File.expand_path(file_path), nil)
  elsif name
    GDALGetDriverByName(name)
  elsif index
    count = self.class.driver_count
    raise "index must be between 0 and #{count - 1}." if index > count

    GDALGetDriver(index)
  elsif dataset
    GDALGetDatasetDriver(dataset)
  end
end

Class Method Details

.by_name(name) ⇒ GDAL::Driver

Returns:



21
22
23
# File 'lib/ffi-gdal/driver.rb', line 21

def self.by_name(name)
  new(name: name)
end

.driver_countFixnum

Returns:



16
17
18
# File 'lib/ffi-gdal/driver.rb', line 16

def self.driver_count
  FFI::GDAL.GDALGetDriverCount
end

Instance Method Details

#c_pointerObject



48
49
50
# File 'lib/ffi-gdal/driver.rb', line 48

def c_pointer
  @gdal_driver_handle
end

#copy_dataset_files(new_name, old_name) ⇒ Object

Copy all of the associated files of a dataset from one file to another.

Parameters:

Returns:

  • true on success, false on warning.

Raises:



90
91
92
93
94
# File 'lib/ffi-gdal/driver.rb', line 90

def copy_dataset_files(new_name, old_name)
  cpl_err = GDALCopyDatasetFiles(@gdal_driver_handle, new_name, old_name)

  cpl_err.to_bool
end

#create_dataset(filename, x_size, y_size, bands: 1, type: :GDT_Byte, **options) {|dataset| ... } ⇒ GDAL::Dataset

TODO:

Implement options.

Create a new Dataset with this driver. Legal arguments depend on the driver and can’t be retrieved programmatically.

Parameters:

Yields:

  • (dataset)

Returns:

  • (GDAL::Dataset)

    Returns the closed dataset. You’ll need to reopen it if you with to continue working with it.

Raises:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ffi-gdal/driver.rb', line 107

def create_dataset(filename, x_size, y_size, bands: 1, type: :GDT_Byte, **options)
  log "creating dataset with size #{x_size},#{y_size}"

  dataset_pointer = GDALCreate(@gdal_driver_handle,
    filename,
    x_size,
    y_size,
    bands,
    type,
    nil
  )

  raise CreateFail if dataset_pointer.null?

  dataset = Dataset.new(dataset_pointer)
  yield(dataset) if block_given?
  dataset.close

  dataset
end

#creation_option_listArray

Lists and describes the options that can be used when calling GDAL::Dataset.create or GDAL::Dataset.create_copy.

Returns:

  • (Array)


77
78
79
80
81
82
# File 'lib/ffi-gdal/driver.rb', line 77

def creation_option_list
  return [] unless @gdal_driver_handle

  creation_option_list_xml = GDALGetDriverCreationOptionList(@gdal_driver_handle)
  MultiXml.parse(creation_option_list_xml)['CreationOptionList']['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.

Parameters:

Returns:

  • true on success, false on warning.

Raises:



134
135
136
137
138
# File 'lib/ffi-gdal/driver.rb', line 134

def delete_dataset(file_name)
  cpl_err = GDALDeleteDataset(@gdal_driver_handle, file_name)

  cpl_err.to_bool
end

#help_topicString

Returns:



67
68
69
70
71
# File 'lib/ffi-gdal/driver.rb', line 67

def help_topic
  return '' unless @gdal_driver_handle

  "#{GDAL_DOCS_URL}/#{GDALGetDriverHelpTopic(@gdal_driver_handle)}"
end

#long_nameString

Returns:



60
61
62
63
64
# File 'lib/ffi-gdal/driver.rb', line 60

def long_name
  return '' unless @gdal_driver_handle

  GDALGetDriverLongName(@gdal_driver_handle)
end

#rename_dataset(new_name, old_name) ⇒ Object

Returns true on success, false on warning.

Parameters:

Returns:

  • true on success, false on warning.

Raises:



144
145
146
147
148
149
# File 'lib/ffi-gdal/driver.rb', line 144

def rename_dataset(new_name, old_name)
  cpl_err = GDALRenameDataset(@gdal_driver_handle, new_name, old_name)


  cpl_err.to_bool
end

#short_nameString

Returns:



53
54
55
56
57
# File 'lib/ffi-gdal/driver.rb', line 53

def short_name
  return '' unless @gdal_driver_handle

  GDALGetDriverShortName(@gdal_driver_handle)
end