Module: OGR::SpatialReferenceMixins::Importers

Included in:
OGR::SpatialReference
Defined in:
lib/ogr/spatial_reference_mixins/importers.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 8

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#import_from_epsg(code) ⇒ OGR::SpatialReference

Returns ‘self`, but updated with the EPSG code.

Parameters:

Returns:

Raises:



138
139
140
141
142
143
144
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 138

def import_from_epsg(code)
  OGR::ErrorHandling.handle_ogr_err("Unable to import from EPSG: #{code}") do
    FFI::OGR::SRSAPI.OSRImportFromEPSG(@c_pointer, code)
  end

  self
end

#import_from_epsga(code) ⇒ Object

Parameters:

Raises:



148
149
150
151
152
153
154
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 148

def import_from_epsga(code)
  OGR::ErrorHandling.handle_ogr_err("Unable to import from EPSGA: #{code}") do
    FFI::OGR::SRSAPI.OSRImportFromEPSGA(@c_pointer, code)
  end

  self
end

#import_from_erm(projection_name, datum_name, linear_unit_name) ⇒ Object

Parameters:

  • projection_name (String)

    I.e. “NUTM11” or “GEOGRAPHIC”.

  • datum_name (String)

    I.e. “NAD83”.

  • linear_unit_name (String)

    Plural form of linear units, i.e. “FEET”.

Raises:



266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 266

def import_from_erm(projection_name, datum_name, linear_unit_name)
  msg = "Unable to import from ERMapper: #{projection_name}, #{datum_name}, #{linear_unit_name}"

  OGR::ErrorHandling.handle_ogr_err(msg) do
    FFI::OGR::SRSAPI.OSRImportFromERM(
      @c_pointer,
      projection_name,
      datum_name,
      linear_unit_name
    )
  end

  self
end

#import_from_esri(esri_text) ⇒ Object

Parameters:

Raises:



182
183
184
185
186
187
188
189
190
191
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 182

def import_from_esri(esri_text)
  text_array = esri_text.split("\n")
  esri_ptr_ptr = GDAL._string_array_to_pointer(text_array)

  OGR::ErrorHandling.handle_ogr_err("Unable to import from ESRI: #{esri_text}") do
    FFI::OGR::SRSAPI.OSRImportFromESRI(@c_pointer, esri_ptr_ptr)
  end

  self
end

#import_from_mapinfo(coord_sys) ⇒ Object

Parameters:

  • coord_sys (String)

    The Mapinfo style CoordSys definition string.

Raises:



254
255
256
257
258
259
260
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 254

def import_from_mapinfo(coord_sys)
  OGR::ErrorHandling.handle_ogr_err("Unable to import from MapInfo: #{coord_sys}") do
    FFI::OGR::SRSAPI.OSRImportFromMICoordSys(@c_pointer, coord_sys)
  end

  self
end

#import_from_pci(proj, units, *proj_params) ⇒ Object

Parameters:

Raises:



197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 197

def import_from_pci(proj, units, *proj_params)
  if proj_params.empty?
    proj_ptr = nil
  else
    proj_ptr = FFI::MemoryPointer.new(:double, proj_params.size)
    proj_ptr.write_array_of_double(proj_params)
  end

  OGR::ErrorHandling.handle_ogr_err("Unable to import from PCI: #{proj}") do
    FFI::OGR::SRSAPI.OSRImportFromPCI(@c_pointer, proj, units, proj_ptr)
  end

  self
end

#import_from_proj4(proj4) ⇒ Object

Parameters:

Raises:



172
173
174
175
176
177
178
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 172

def import_from_proj4(proj4)
  OGR::ErrorHandling.handle_ogr_err("Unable to import from PROJ.4: #{proj4}") do
    FFI::OGR::SRSAPI.OSRImportFromProj4(@c_pointer, proj4)
  end

  self
end

#import_from_url(url) ⇒ Object

Parameters:

  • url (String)

    URL to fetch the spatial reference from.

Raises:



283
284
285
286
287
288
289
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 283

def import_from_url(url)
  OGR::ErrorHandling.handle_ogr_err("Unable to import from URL: #{url}") do
    FFI::OGR::SRSAPI.OSRImportFromUrl(@c_pointer, url)
  end

  self
end

#import_from_usgs(projection_system_code, zone, datum, *proj_params) ⇒ Object

Parameters:

Raises:



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 217

def import_from_usgs(projection_system_code, zone, datum, *proj_params)
  if proj_params.empty?
    proj_ptr = nil
  else
    proj_ptr = FFI::MemoryPointer.new(:double, proj_params.size)
    proj_ptr.write_array_of_double(proj_params)
  end

  msg = "Unable to import from USGS: #{projection_system_code}, #{zone}, #{datum}, #{proj_params}"

  OGR::ErrorHandling.handle_ogr_err(msg) do
    FFI::OGR::SRSAPI.OSRImportFromUSGS(
      @c_pointer,
      projection_system_code,
      zone,
      proj_ptr,
      datum
    )
  end

  self
end

#import_from_wkt(wkt) ⇒ Object

Parameters:

Raises:



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 158

def import_from_wkt(wkt)
  wkt_ptr = FFI::MemoryPointer.from_string(wkt)
  wkt_ptr_ptr = FFI::MemoryPointer.new(:pointer)
  wkt_ptr_ptr.write_pointer(wkt_ptr)

  OGR::ErrorHandling.handle_ogr_err("Unable to import from WKT: #{wkt}") do
    FFI::OGR::SRSAPI.OSRImportFromWkt(@c_pointer, wkt_ptr_ptr)
  end

  self
end

#import_from_xml(xml) ⇒ Object

Use for importing a GML coordinate system.

Parameters:

Raises:



244
245
246
247
248
249
250
# File 'lib/ogr/spatial_reference_mixins/importers.rb', line 244

def import_from_xml(xml)
  OGR::ErrorHandling.handle_ogr_err("Unable to import from XML: #{xml}") do
    FFI::OGR::SRSAPI.OSRImportFromXML(@c_pointer, xml)
  end

  self
end