Class: Proj::Crs
Overview
Represents a coordinate reference system.
Instance Method Summary collapse
-
#area ⇒ Area
Return the area of use of an object.
-
#axis_count ⇒ Integer
Returns the number of axis of the coordinate system.
-
#axis_info ⇒ Array<Hash>
Returns information on an axis.
-
#coordinate_system ⇒ Crs
Returns the coordinate system of a SingleCRS.
-
#crs_type ⇒ :PJ_COORDINATE_SYSTEM_TYPE
Returns the type of the coordinate system.
-
#datum ⇒ Crs
Returns the datum of a SingleCRS.
-
#ellipsoid ⇒ PjObject
Get the ellipsoid from a CRS or a GeodeticReferenceFrame.
-
#geodetic_crs ⇒ Crs
Get the geodeticCRS / geographicCRS from a CRS.
-
#horizontal_datum ⇒ Crs
Get the horizontal datum from a CRS.
-
#initialize(value, context = nil) ⇒ Crs
constructor
To create a coordinate system, you can use CRS codes, well-known text (WKT) strings or old-style Proj4 strings (which are deprecated).
-
#inspect ⇒ String
A nicely printed out description.
-
#operation ⇒ PjObject
Return the Conversion of a DerivedCRS (such as a ProjectedCRS), or the Transformation from the baseCRS to the hubCRS of a BoundCRS.
-
#prime_meridian ⇒ PjObject
Get the prime meridian of a CRS or a GeodeticReferenceFrame.
-
#sub_crs(index) ⇒ Crs
Get a CRS component from a CompoundCRS.
Methods inherited from PjObject
#accuracy, #auth, #auth_code, #auth_name, #context, #definition, #description, finalize, #has_inverse?, #id, #info, #name, #proj_type, #to_json, #to_proj_string, #to_ptr, #to_wkt
Constructor Details
#initialize(value, context = nil) ⇒ Crs
To create a coordinate system, you can use CRS codes, well-known text (WKT) strings or old-style Proj4 strings (which are deprecated).
Notice when using the old-style Proj4 string, the addition of the “+type=crs” value.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/proj/crs.rb', line 39 def initialize(value, context=nil) pointer = Api.proj_create(context || Context.current, value) if pointer.null? Error.check end super(pointer, context) if Api.method_defined?(:proj_is_crs) && !Api.proj_is_crs(pointer) raise(Error, "Invalid crs definition. Proj created an instance of: #{self.proj_type}.") end end |
Instance Method Details
#area ⇒ Area
Return the area of use of an object.
143 144 145 |
# File 'lib/proj/crs.rb', line 143 def area @area ||= Area.for_object(self) end |
#axis_count ⇒ Integer
Returns the number of axis of the coordinate system.
91 92 93 94 95 96 97 |
# File 'lib/proj/crs.rb', line 91 def axis_count result = Api.proj_cs_get_axis_count(self.context, self.coordinate_system) if result == -1 Error.check end result end |
#axis_info ⇒ Array<Hash>
Returns information on an axis.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/proj/crs.rb', line 102 def axis_info self.axis_count.times.map do |index| p_name = FFI::MemoryPointer.new(:pointer) p_abbreviation = FFI::MemoryPointer.new(:pointer) p_direction = FFI::MemoryPointer.new(:pointer) p_unit_conv_factor = FFI::MemoryPointer.new(:double) p_unit_name = FFI::MemoryPointer.new(:pointer) p_unit_auth_name = FFI::MemoryPointer.new(:pointer) p_unit_code = FFI::MemoryPointer.new(:pointer) result = Api.proj_cs_get_axis_info(self.context, self.coordinate_system, index, p_name, p_abbreviation, p_direction, p_unit_conv_factor, p_unit_name, p_unit_auth_name, p_unit_code) unless result Error.check end {:name => p_name.read_pointer.read_string, :abbreviation => p_abbreviation.read_pointer.read_string_to_null, :direction => p_direction.read_pointer.read_string_to_null, :unit_conv_factor => p_unit_conv_factor.read_double, :unit_name => p_unit_name.read_pointer.read_string_to_null, :unit_auth_name => p_unit_auth_name.read_pointer.read_string_to_null, :unit_code => p_unit_code.read_pointer.read_string_to_null} end end |
#coordinate_system ⇒ Crs
Returns the coordinate system of a SingleCRS.
84 85 86 |
# File 'lib/proj/crs.rb', line 84 def coordinate_system PjObject.new(Api.proj_crs_get_coordinate_system(self.context, self)) end |
#crs_type ⇒ :PJ_COORDINATE_SYSTEM_TYPE
Returns the type of the coordinate system.
132 133 134 135 136 137 138 |
# File 'lib/proj/crs.rb', line 132 def crs_type result = Api.proj_cs_get_type(self.context, self.coordinate_system) if result == :PJ_CS_TYPE_UNKNOWN Error.check end result end |
#datum ⇒ Crs
Returns the datum of a SingleCRS.
70 71 72 |
# File 'lib/proj/crs.rb', line 70 def datum PjObject.new(Api.proj_crs_get_datum(self.context, self)) end |
#ellipsoid ⇒ PjObject
Get the ellipsoid from a CRS or a GeodeticReferenceFrame.
150 151 152 |
# File 'lib/proj/crs.rb', line 150 def ellipsoid PjObject.new(Api.proj_get_ellipsoid(self.context, self)) end |
#geodetic_crs ⇒ Crs
Get the geodeticCRS / geographicCRS from a CRS.
56 57 58 |
# File 'lib/proj/crs.rb', line 56 def geodetic_crs PjObject.new(Api.proj_crs_get_geodetic_crs(self.context, self)) end |
#horizontal_datum ⇒ Crs
Get the horizontal datum from a CRS.
77 78 79 |
# File 'lib/proj/crs.rb', line 77 def horizontal_datum PjObject.new(Api.proj_crs_get_horizontal_datum(self.context, self)) end |
#inspect ⇒ String
A nicely printed out description
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/proj/crs.rb', line 176 def inspect result = StringIO.new result.set_encoding('UTF-8') result << <<~EOS <#{self.class.name}>: #{self.auth(0)} #{self.description} Axis Info [#{self.crs_type}]: EOS self.axis_info.each do |axis_info| result << "- #{axis_info[:abbreviation]}[#{axis_info[:direction]}]: #{axis_info[:name]} (#{axis_info[:unit_name]})" << "\n" end result << <<~EOS Area of Use: - name: #{self.area.name} - bounds: (#{self.area.west_lon_degree}, #{self.area.south_lat_degree}, #{self.area.east_lon_degree}, #{self.area.north_lat_degree}) Coordinate operation: - name: ? - method: ? Datum: #{self.datum.name} - Ellipsoid: #{self.ellipsoid.name} - Prime Meridian: #{self.prime_meridian.name} EOS result.string end |
#operation ⇒ PjObject
Return the Conversion of a DerivedCRS (such as a ProjectedCRS), or the Transformation from the baseCRS to the hubCRS of a BoundCRS.
158 159 160 161 162 163 164 |
# File 'lib/proj/crs.rb', line 158 def operation pointer = Api.proj_crs_get_coordoperation(self.context, self) if pointer.null? Error.check end PjObject.new(pointer) end |