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/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, 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.1.0'

Class Method Summary collapse

Class Method Details

.create_writer(path) ⇒ Object



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

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



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

def gdal_version
  FFIOGR.GDALVersionInfo('RELEASE_NAME')
end

.get_available_driversObject Also known as: drivers



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

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



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

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



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

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



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

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

.read(source) ⇒ Object



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

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



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

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

.to_binary(data) ⇒ Object



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

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