Class: OGR::HttpReader

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-ogr/http_reader.rb

Constant Summary collapse

TF_MAP =
{
  true => 1,
  false => 0,
  1 => true,
  0 => false
}

Instance Method Summary collapse

Instance Method Details

#read(url, writeable = false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ffi-ogr/http_reader.rb', line 15

def read(url, writeable=false)
  file_extension = url.split('.').last
  driver = OGR::DRIVER_TYPES[file_extension]

  if driver.nil?
    unless url =~ /FeatureServer/
      raise RuntimeError.new "File type not supported."
    else
      # ? assume Esri Feature Service ?
      file_extension = 'json'
      driver = OGR::DRIVER_TYPES[file_extension]
    end
  end

  http_data = Faraday.get(url).body
  ogr_driver = OGR::FFIOGR::OGRGetDriverByName driver
  data_source = OGR::FFIOGR::OGR_Dr_Open ogr_driver, http_data, TF_MAP[writeable]
  OGR::Tools.cast_data_source data_source
end