Module: OGR

Defined in:
lib/ffi-ogr.rb,
lib/ffi-ogr/csv.rb,
lib/ffi-ogr/kml.rb,
lib/ffi-ogr/layer.rb,
lib/ffi-ogr/point.rb,
lib/ffi-ogr/tools.rb,
lib/ffi-ogr/reader.rb,
lib/ffi-ogr/writer.rb,
lib/ffi-ogr/feature.rb,
lib/ffi-ogr/polygon.rb,
lib/ffi-ogr/version.rb,
lib/ffi-ogr/envelope.rb,
lib/ffi-ogr/geo_json.rb,
lib/ffi-ogr/geometry.rb,
lib/ffi-ogr/point_25d.rb,
lib/ffi-ogr/shapefile.rb,
lib/ffi-ogr/data_source.rb,
lib/ffi-ogr/http_reader.rb,
lib/ffi-ogr/line_string.rb,
lib/ffi-ogr/linear_ring.rb,
lib/ffi-ogr/multi_point.rb,
lib/ffi-ogr/polygon_25d.rb,
lib/ffi-ogr/multi_polygon.rb,
lib/ffi-ogr/options_struct.rb,
lib/ffi-ogr/postgis_reader.rb,
lib/ffi-ogr/line_string_25d.rb,
lib/ffi-ogr/multi_point_25d.rb,
lib/ffi-ogr/multi_line_string.rb,
lib/ffi-ogr/multi_polygon_25d.rb,
lib/ffi-ogr/spatial_reference.rb,
lib/ffi-ogr/geometry_collection.rb,
lib/ffi-ogr/multi_line_string_25d.rb,
lib/ffi-ogr/geometry_collection_25d.rb,
lib/ffi-ogr/coordinate_transformation.rb

Defined Under Namespace

Modules: FFIOGR, Tools Classes: CSV, CoordinateTransformation, DataSource, Envelope, Feature, GeoJSON, Geometry, GeometryCollection, GeometryCollection25D, HttpReader, KML, Layer, LineString, LineString25D, LinearRing, MultiLineString, MultiLineString25D, MultiPoint, MultiPoint25D, MultiPolygon, MultiPolygon25D, OptionsStruct, Point, Point25D, Polygon, Polygon25D, PostgisReader, Reader, Shapefile, SpatialReference, Writer

Constant Summary collapse

OGR_BASE =
File.join(File.dirname(__FILE__), 'ffi-ogr')
DRIVER_TYPES =
{
  'shapefile' => 'ESRI Shapefile',
  'shp' => 'ESRI Shapefile',
  'geojson' => 'GeoJSON',
  'json' => 'GeoJSON',
  'csv' => 'CSV',
  'kml' => 'LIBKML',
  'kml_lite' => 'KML'
}
VERSION =
'0.2.0.pre'

Class Method Summary collapse

Class Method Details

.create_writer(path) ⇒ Object


359
360
361
362
363
364
365
# File 'lib/ffi-ogr.rb', line 359

def create_writer(path)
  raise RuntimeError.new "Path already exists: #{path}" if File.exists?(path)

  writer = get_writer path
  writer.set_output path
  writer
end

.gdal_versionObject


330
331
332
# File 'lib/ffi-ogr.rb', line 330

def gdal_version
  FFIOGR.GDALVersionInfo('RELEASE_NAME')
end

.get_available_driversObject Also known as: drivers


334
335
336
337
338
339
340
# File 'lib/ffi-ogr.rb', line 334

def get_available_drivers
  [].tap do |drivers|
    for i in 0...FFIOGR.OGRGetDriverCount
      drivers << FFIOGR.OGR_Dr_GetName(FFIOGR.OGRGetDriver(i))
    end
  end
end

.get_driver_by_extension(extension) ⇒ Object


367
368
369
370
371
372
373
374
375
376
377
# File 'lib/ffi-ogr.rb', line 367

def get_driver_by_extension(extension)
  driver = unless extension == 'kml'
    DRIVER_TYPES[extension]
  else
    drivers.include?('LIBKML') ? 'LIBKML' : 'KML'
  end

  raise RuntimeError.new "Could not find appropriate driver" if driver.nil?

  driver
end

.get_writer(source) ⇒ Object


353
354
355
356
357
# File 'lib/ffi-ogr.rb', line 353

def get_writer(source)
  extension = source.split('.').last
  driver = get_driver_by_extension extension
  Writer.new(driver)
end

.import_spatial_ref(sr_import, format = 'epsg') ⇒ Object Also known as: import_sr


390
391
392
# File 'lib/ffi-ogr.rb', line 390

def import_spatial_ref(sr_import, format = 'epsg')
  OGR::SpatialReference.import(sr_import, format)
end

.read(source) ⇒ Object


379
380
381
382
383
384
385
386
387
388
# File 'lib/ffi-ogr.rb', line 379

def read(source)
  case source
  when /http:|https:/
    HttpReader.new.read source
  else
    driver = get_driver_by_extension source.split('.').last
    raise RuntimeError.new "Could not determine file type" if driver.nil?
    Reader.new(driver).read source
  end
end

.string_to_pointer(str) ⇒ Object


349
350
351
# File 'lib/ffi-ogr.rb', line 349

def string_to_pointer(str)
  FFI::MemoryPointer.from_string(str)
end

.to_binary(data) ⇒ Object


343
344
345
346
347
# File 'lib/ffi-ogr.rb', line 343

def to_binary(data)
  buf = FFI::MemoryPointer.new(:char, value.size)
  buf.put_bytes(0, data)
  buf
end