Module: OGR::SpatialReferenceMixins::Exporters

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

Instance Method Summary collapse

Instance Method Details

#to_ermHash

Returns:

  • (Hash)

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ogr/spatial_reference_mixins/exporters.rb', line 8

def to_erm
  projection_name = FFI::MemoryPointer.new(:string, 32)
  datum_name = FFI::MemoryPointer.new(:string, 32)
  units = FFI::MemoryPointer.new(:string, 32)

  OGR::ErrorHandling.handle_ogr_err("Required parameters (name, datum name, units) are not defined") do
    FFI::OGR::SRSAPI.OSRExportToERM(@c_pointer, projection_name, datum_name, units)
  end

  {
    projection_name: projection_name.read_string,
    datum_name: datum_name.read_string,
    units: units.read_string
  }
end

#to_mapinfoArray<String>

Returns:

Raises:



26
27
28
29
30
31
32
# File 'lib/ogr/spatial_reference_mixins/exporters.rb', line 26

def to_mapinfo
  GDAL._cpl_read_and_free_string do |return_ptr_ptr|
    OGR::ErrorHandling.handle_ogr_err("Unable to export to MapInfo") do
      FFI::OGR::SRSAPI.OSRExportToMICoordSys(@c_pointer, return_ptr_ptr)
    end
  end
end

#to_pciHash

Returns:

  • (Hash)

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ogr/spatial_reference_mixins/exporters.rb', line 36

def to_pci
  proj_ptr_ptr = GDAL._pointer_pointer(:string)
  proj_ptr_ptr.autorelease = false
  units_ptr_ptr = GDAL._pointer_pointer(:string)
  units_ptr_ptr.autorelease = false
  prj_params_ptr_ptr = GDAL._pointer_pointer(:double)
  prj_params_ptr_ptr.autorelease = false

  OGR::ErrorHandling.handle_ogr_err("Unable to export to PCI") do
    FFI::OGR::SRSAPI.OSRExportToPCI(@c_pointer, proj_ptr_ptr, units_ptr_ptr, prj_params_ptr_ptr)
  end

  projection = proj_ptr_ptr.read_pointer.read_string
  units = units_ptr_ptr.read_pointer.read_string
  projection_parameters = prj_params_ptr_ptr.read_array_of_double(0)

  result = {
    projection: projection,
    units: units,
    projection_parameters: projection_parameters
  }

  FFI::CPL::VSI.VSIFree(proj_ptr_ptr)
  FFI::CPL::VSI.VSIFree(units_ptr_ptr)
  FFI::CPL::VSI.VSIFree(prj_params_ptr_ptr)

  result
end

#to_pretty_wkt(simplify: false) ⇒ String

Parameters:

  • simplify (Boolean) (defaults to: false)

    true strips off AXIS, AUTHORITY and EXTENSION nodes.

Returns:

Raises:



119
120
121
122
123
124
125
126
127
# File 'lib/ogr/spatial_reference_mixins/exporters.rb', line 119

def to_pretty_wkt(simplify: false)
  return +"" if @c_pointer.null?

  GDAL._cpl_read_and_free_string do |wkt_ptr_ptr|
    OGR::ErrorHandling.handle_ogr_err("Unable to export to pretty WKT") do
      FFI::OGR::SRSAPI.OSRExportToPrettyWkt(@c_pointer, wkt_ptr_ptr, simplify)
    end
  end
end

#to_proj4String

Returns:

Raises:



67
68
69
70
71
72
73
# File 'lib/ogr/spatial_reference_mixins/exporters.rb', line 67

def to_proj4
  GDAL._cpl_read_and_free_string do |proj4_ptr_ptr|
    OGR::ErrorHandling.handle_ogr_err("Unable to export to PROJ.4") do
      FFI::OGR::SRSAPI.OSRExportToProj4(@c_pointer, proj4_ptr_ptr)
    end
  end
end

#to_usgsHash

Returns:

  • (Hash)

Raises:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ogr/spatial_reference_mixins/exporters.rb', line 77

def to_usgs
  proj_sys_ptr = FFI::MemoryPointer.new(:long)
  zone_ptr = FFI::MemoryPointer.new(:long)
  datum_ptr = FFI::MemoryPointer.new(:long)
  prj_params_ptr_ptr = GDAL._pointer_pointer(:double)
  prj_params_ptr_ptr.autorelease = false

  OGR::ErrorHandling.handle_ogr_err("Unable to export to USGS GCTP") do
    FFI::OGR::SRSAPI.OSRExportToUSGS(@c_pointer, proj_sys_ptr, zone_ptr, prj_params_ptr_ptr, datum_ptr)
  end

  projection_system_code = proj_sy_ptrs.read_long
  zone = zon_ptre.read_long
  projection_parameters = prj_params_pt_ptrr.read_array_of_double(0)
  datum = datu_ptrm.read_long

  result = {
    projection_system_code: projection_system_code,
    zone: zone,
    projection_parameters: projection_parameters,
    datum: datum
  }

  FFI::CPL::VSI.VSIFree(prj_params_ptr_ptr)

  result
end

#to_wktString

Returns:

Raises:



107
108
109
110
111
112
113
# File 'lib/ogr/spatial_reference_mixins/exporters.rb', line 107

def to_wkt
  GDAL._cpl_read_and_free_string do |wkt_ptr_ptr|
    OGR::ErrorHandling.handle_ogr_err("Unable to export to WKT") do
      FFI::OGR::SRSAPI.OSRExportToWkt(@c_pointer, wkt_ptr_ptr)
    end
  end
end

#to_xmlString Also known as: to_gml

Returns:

Raises:



131
132
133
134
135
136
137
# File 'lib/ogr/spatial_reference_mixins/exporters.rb', line 131

def to_xml
  GDAL._cpl_read_and_free_string do |xml_ptr_ptr|
    OGR::ErrorHandling.handle_ogr_err("Unable to export to XML (GML)") do
      FFI::OGR::SRSAPI.OSRExportToXML(@c_pointer, xml_ptr_ptr, nil)
    end
  end
end