Class: GDAL::Utils::VectorTranslate

Inherits:
Object
  • Object
show all
Defined in:
lib/gdal/utils/vector_translate.rb,
lib/gdal/utils/vector_translate/options.rb

Overview

Wrapper for ogr2ogr using GDALVectorTranslate C API.

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Class Method Details

.perform(dst_dataset: nil, dst_dataset_path: nil, src_datasets: [], options: Options.new) {|OGR::DataSource| ... } ⇒ OGR::DataSource

Perform the ogr2ogr (GDALVectorTranslate) operation.

Examples:

Translate a vector dataset (for dst_dataset_path).

src_dataset = OGR::DataSource.open("source.shp", "r")
dataset = GDAL::Utils::VectorTranslate.perform(
  dst_dataset_path: "destination.geojson",
  src_datasets: [src_dataset]
)

# Do something with the dataset.
puts dataset.layer(0).name

# You must close the dataset when you are done with it.
dataset.close
src_dataset.close

Translate a vector dataset with options (for dst_dataset_path).

src_dataset = OGR::DataSource.open("source.shp", "r")
dataset = GDAL::Utils::VectorTranslate.perform(
  dst_dataset_path: "destination.geojson",
  src_datasets: [src_dataset],
  options: GDAL::Utils::VectorTranslate::Options.new(options: ["-nlt", "MULTIPOLYGON"])
)

# Do something with the dataset.
puts dataset.layer(0).name

# You must close the dataset when you are done with it.
dataset.close
src_dataset.close

Translate a vector dataset using block syntax (for dst_dataset_path).

src_dataset = OGR::DataSource.open("source.shp", "r")
GDAL::Utils::VectorTranslate.perform(
  dst_dataset_path: "destination.geojson",
  src_datasets: [src_dataset]
) do |dataset|
  # Do something with the dataset.
  puts dataset.layer(0).name

  # Dataset will be closed automatically.
end
src_dataset.close

Translate a vector dataset (for dst_dataset).

src_dataset = OGR::DataSource.open("source.shp", "r")
dst_dataset = OGR::DataSource.open("destination.geojson", "w")

GDAL::Utils::VectorTranslate.perform(dst_dataset: dst_dataset, src_datasets: [src_dataset])

# You must close the dataset when you are done with it.
dst_dataset.close
src_dataset.close

Translate a vector dataset with options (for dst_dataset).

src_dataset = OGR::DataSource.open("source.shp", "r")
dst_dataset = OGR::DataSource.open("destination.geojson", "w")

GDAL::Utils::VectorTranslate.perform(
  dst_dataset: dst_dataset,
  src_datasets: [src_dataset],
  options: GDAL::Utils::VectorTranslate::Options.new(options: ["-nlt", "MULTIPOLYGON"])
)

# You must close the dataset when you are done with it.
dst_dataset.close
src_dataset.close

Parameters:

Yields:

Returns:

  • (OGR::DataSource)

    The destination dataset (only if block is not specified; dataset must be closed).



87
88
89
90
91
92
93
# File 'lib/gdal/utils/vector_translate.rb', line 87

def self.perform(dst_dataset: nil, dst_dataset_path: nil, src_datasets: [], options: Options.new, &block)
  if dst_dataset
    for_dataset(dst_dataset: dst_dataset, src_datasets: src_datasets, options: options)
  else
    for_dataset_path(dst_dataset_path: dst_dataset_path, src_datasets: src_datasets, options: options, &block)
  end
end