Class: Proj::Crs

Inherits:
PjObject show all
Defined in:
lib/proj/crs.rb

Overview

Represents a coordinate reference system.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PjObject

#accuracy, #angular_input?, #angular_output?, #area_of_use, #auth, #auth_name, #context, #context=, create, create_from_database, create_from_name, create_from_wkt, #definition, #degree_input?, #degree_output?, #deprecated?, #description, #equivalent_to?, #errno, #errorno, #factors, #geod_distance, #has_inverse?, #id, #id_code, #info, #initialize_copy, #lp_distance, #lpz_distance, #name, #non_deprecated, #proj_type, #remarks, #scope, #source_crs, #target_crs, #to_json, #to_proj_string, #to_ptr, #to_s, #to_wkt, #xy_distance, #xyz_distance

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.

Examples:

crs1 = Proj::Crs.new('EPSG:4326')
crs2 = Proj::Crs.new('urn:ogc:def:crs:EPSG::4326')
crs3 = Proj::Crs.new('+proj=longlat +datum=WGS84 +no_defs +type=crs')
crs4 = Proj::Crs.new(<<~EOS)
         GEOGCRS["WGS 84",
         DATUM["World Geodetic System 1984",
               ELLIPSOID["WGS 84",6378137,298.257223563,
                         LENGTHUNIT["meter",1]]],
         PRIMEM["Greenwich",0,
                ANGLEUNIT["degree",0.0174532925199433]],
         CS[ellipsoidal,2],
         AXIS["geodetic latitude (Lat)",north,
              ORDER[1],
              ANGLEUNIT["degree",0.0174532925199433]],
         AXIS["geodetic longitude (Lon)",east,
              ORDER[2],
              ANGLEUNIT["degree",0.0174532925199433]],
         USAGE[
             SCOPE["unknown"],
                 AREA["World"],
             BBOX[-90,-180,90,180]],
         ID["EPSG",4326]]
       EOS

Parameters:

  • value (String)

    . See above

  • context (Context) (defaults to: nil)

    . An optional Context that the Crs will use for calculations.



337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/proj/crs.rb', line 337

def initialize(value, context=nil)
  ptr = Api.proj_create(context || Context.current, value)

  if ptr.null?
    Error.check_object(self)
  end

  super(ptr, context)

  if Api.method_defined?(:proj_is_crs) && !Api.proj_is_crs(ptr)
    raise(Error, "Invalid crs definition. Proj created an instance of: #{self.proj_type}.")
  end
end

Class Method Details

.create_bound(context, base_crs:, hub_crs:, transformation:) ⇒ Crs

Returns a BoundCRS

Parameters:

Returns:



34
35
36
37
38
39
40
41
42
# File 'lib/proj/crs.rb', line 34

def self.create_bound(context, base_crs:, hub_crs:, transformation:)
  pointer = Api.proj_crs_create_bound_crs(context, base_crs, hub_crs, transformation)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_bound_to_wgs84(context, crs:, allow_intermediate_crs: "NEVER") ⇒ Crs

Returns a BoundCRS with a transformation to EPSG:4326 wrapping it

* ALWAYS
* IF_NO_DIRECT_TRANSFORMATION
* NEVER

Default is NEVER

Parameters:

  • context (Context)

    Context

  • crs (Crs)

    CRS to wrap

  • allow_intermediate_crs (String) (defaults to: "NEVER")

    Specifies if an intermediate CRS may be considered when computing the possible transformations. Allowed values are:

Returns:



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/proj/crs.rb', line 57

def self.create_bound_to_wgs84(context, crs:, allow_intermediate_crs: "NEVER")
  options = {"ALLOW_INTERMEDIATE_CRS": allow_intermediate_crs}
  options_ptr = create_options_pointer(options)

  pointer = Api.proj_crs_create_bound_crs_to_WGS84(context, crs, options_ptr)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_bound_vertical(context, vertical_crs:, hub_crs:, grid_name:) ⇒ Crs

Create a Bound Vertical CRS, with a transformation to a hub geographic 3D crs, such as EPSG:4979 or WGS84, using a grid

Parameters:

  • context (Context)

    Context

  • vertical_crs (Crs)

    A VerticalCRS

  • hub_crs (Crs)

    A Geographic 3D CRS

  • grid_name (String)

    Grid name (typically a .gtx file)

Returns:



114
115
116
117
118
119
120
121
122
# File 'lib/proj/crs.rb', line 114

def self.create_bound_vertical(context, vertical_crs:, hub_crs:, grid_name:)
  pointer = Api.proj_crs_create_bound_vertical_crs(context, vertical_crs, hub_crs, grid_name)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_compound(context, name:, horizontal_crs:, vertical_crs:) ⇒ Crs

Create a CompoundCRS.

Parameters:

  • context (Context)

    Context

  • name (String)

    Name of the GeographicCRS. Default is nil.

  • horizontal_crs (Crs)

    A horizontal CRS

  • vertical_crs (Crs)

    A vertical CRS

Returns:



166
167
168
169
170
171
172
173
174
# File 'lib/proj/crs.rb', line 166

def self.create_compound(context, name:, horizontal_crs:, vertical_crs:)
  pointer = Api.proj_create_compound_crs(context, name, horizontal_crs, vertical_crs)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_derived_geographic(context, name: nil, base_geographic_crs:, conversion:, coordinate_system:) ⇒ Crs

Create a DerivedGeograhicCRS

Parameters:

  • context (Context)

    Context

  • name (String) (defaults to: nil)

    Name of the GeographicCRS. Default is nil.

  • base_geographic_crs (Crs)

    Base Geographic CRS

  • conversion (Conversion)

    Conversion from the base Geographic to the DerivedGeograhicCRS

  • coordinate_system (CoordinateSystem)

    Ellipsoidal coordinate system

Returns:



273
274
275
276
277
278
279
280
281
# File 'lib/proj/crs.rb', line 273

def self.create_derived_geographic(context, name: nil, base_geographic_crs:, conversion:, coordinate_system:)
  pointer = Api.proj_create_derived_geographic_crs(context, name, base_geographic_crs, conversion, coordinate_system)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_engineering(context, name:) ⇒ Crs

Create a a EngineeringCRS

Parameters:

  • context (Context)

    Context

  • name (String)

    Name of the CRS. Default is nil.

Returns:



76
77
78
79
80
81
82
83
84
# File 'lib/proj/crs.rb', line 76

def self.create_engineering(context, name:)
  pointer = Api.proj_create_engineering_crs(context, name)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_geocentric(context, name:, datum_name:, ellipsoid_name:, semi_major_meter:, inv_flattening:, prime_meridian_name:, prime_meridian_offset:, angular_units:, angular_units_conv:, linear_units:, linear_units_conv:) ⇒ Crs

Create a GeographicCRS.

Parameters:

  • context (Context)

    Context

  • name (String)

    Name of the GeographicCRS. Default is nil.

  • datum_name (String)

    Name of the GeodeticReferenceFrame. Default is nil.

  • ellipsoid_name (String)

    Name of the Ellipsoid. Default is nil.

  • semi_major_meter (Float)

    Ellipsoid semi-major axis, in meters.

  • inv_flattening (Float)

    Ellipsoid inverse flattening. Or 0 for a sphere.

  • prime_meridian_name (String)

    Name of the PrimeMeridian. Default is nil.

  • prime_meridian_offset (Float)

    Offset of the prime meridian, expressed in the specified angular units.

  • angular_units (String)

    Name of the angular units. Or nil for degrees.

  • angular_units_conv (Float)

    Conversion factor from the angular unit to radians. Default is 0 if angular_units is nil

  • linear_units (String)

    Name of the angular units. Or nil for meters.

  • linear_units_conv (Float)

    Conversion factor from linear units to meters. Default is 0 if linear_units is nil

Returns:



235
236
237
238
239
240
241
242
243
# File 'lib/proj/crs.rb', line 235

def self.create_geocentric(context, name:, datum_name:, ellipsoid_name:, semi_major_meter:, inv_flattening:, prime_meridian_name:, prime_meridian_offset:, angular_units:, angular_units_conv:, linear_units:, linear_units_conv:)
  pointer = Api.proj_create_geocentric_crs(context, name, datum_name, ellipsoid_name, semi_major_meter, inv_flattening, prime_meridian_name, prime_meridian_offset, angular_units, angular_units_conv, linear_units, linear_units_conv)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_geocentric_from_datum(context, name:, datum:, linear_units:, linear_units_conv:) ⇒ Crs

Create a GeodeticCRS of geocentric type

Parameters:

  • context (Context)

    Context

  • name (String)

    Name of the GeographicCRS. Default is nil.

  • datum (Datum, DatumEnsemble)

    Datum or DatumEnsemble

  • linear_units (String)

    Name of the angular units. Or nil for meters.

  • linear_units_conv (Float)

    Conversion factor from linear units to meters. Default is 0 if linear_units is nil

Returns:



254
255
256
257
258
259
260
261
262
# File 'lib/proj/crs.rb', line 254

def self.create_geocentric_from_datum(context, name:, datum:, linear_units:, linear_units_conv:)
  pointer = Api.proj_create_geocentric_crs_from_datum(context, name, datum, linear_units, linear_units_conv)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_geographic(context, name:, datum_name:, ellipsoid_name:, semi_major_meter:, inv_flattening:, prime_meridian_name:, prime_meridian_offset:, pm_angular_units:, pm_angular_units_conv:, coordinate_system:) ⇒ Crs

Create a GeographicCRS.

Parameters:

  • context (Context)

    Context

  • name (String)

    Name of the GeographicCRS. Default is nil.

  • datum_name (String)

    Name of the GeodeticReferenceFrame. Default is nil.

  • ellipsoid_name (String)

    Name of the Ellipsoid. Default is nil.

  • semi_major_meter (Float)

    Ellipsoid semi-major axis, in meters.

  • inv_flattening (Float)

    Ellipsoid inverse flattening. Or 0 for a sphere.

  • prime_meridian_name (String)

    Name of the PrimeMeridian. Default is nil.

  • prime_meridian_offset (Float)

    Offset of the prime meridian, expressed in the specified angular units.

  • pm_angular_units (String)

    Name of the angular units. Or nil for degrees.

  • pm_angular_units_conv (Float)

    Conversion factor from the angular unit to radians. Default is 0 if pm_angular_units is nil

  • coordinate_system (CoordinateSystem)

    Ellipsoidal coordinate system

Returns:



191
192
193
194
195
196
197
198
199
# File 'lib/proj/crs.rb', line 191

def self.create_geographic(context, name:, datum_name:, ellipsoid_name:, semi_major_meter:, inv_flattening:, prime_meridian_name:, prime_meridian_offset:, pm_angular_units:, pm_angular_units_conv:, coordinate_system:)
  pointer = Api.proj_create_geographic_crs(context, name, datum_name, ellipsoid_name, semi_major_meter, inv_flattening, prime_meridian_name, prime_meridian_offset, pm_angular_units, pm_angular_units_conv, coordinate_system)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_geographic_from_datum(context, name:, datum:, coordinate_system:) ⇒ Crs

Create a GeographicCRS from a datum

Parameters:

  • context (Context)

    Context

  • name (String)

    Name of the GeographicCRS. Default is nil.

  • datum (Datum, DatumEnsemble)

    Datum or DatumEnsemble

  • coordinate_system (CoordinateSystem)

    Ellipsoidal coordinate system

Returns:



209
210
211
212
213
214
215
216
217
# File 'lib/proj/crs.rb', line 209

def self.create_geographic_from_datum(context, name:, datum:, coordinate_system:)
  pointer = Api.proj_create_geographic_crs_from_datum(context, name, datum, coordinate_system)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_projected(context, name: nil, geodetic_crs:, conversion:, coordinate_system:) ⇒ Crs

Create a ProjectedCRS.

Parameters:

  • context (Context)

    Context

  • name (String) (defaults to: nil)

    Name of the GeographicCRS. Default is nil.

  • geodetic_crs (Crs)

    Base GeodeticCRS

  • conversion (Conversion)

    Conversion

  • coordinate_system (CoordinateSystem)

    Cartesian coordinate system

Returns:



16
17
18
19
20
21
22
23
24
# File 'lib/proj/crs.rb', line 16

def self.create_projected(context, name: nil, geodetic_crs:, conversion:, coordinate_system:)
  pointer = Api.proj_create_projected_crs(context, name, geodetic_crs, conversion, coordinate_system)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_vertical(context, name:, datum_name:, linear_units:, linear_units_conv:) ⇒ Crs

Create a VerticalCRS. For additional functionality see Crs#create_vertical_ex

Parameters:

  • context (Context)

    Context

  • name (String)

    Name of the GeographicCRS. Default is nil.

  • datum_name (String)

    Name of the GeodeticReferenceFrame. Default is nil.

  • linear_units (String)

    Name of the angular units. Or nil for meters.

  • linear_units_conv (Float)

    Conversion factor from linear units to meters. Default is 0 if linear_units is nil

Returns:



95
96
97
98
99
100
101
102
103
# File 'lib/proj/crs.rb', line 95

def self.create_vertical(context, name:, datum_name:, linear_units:, linear_units_conv:)
  pointer = Api.proj_create_vertical_crs(context, name, datum_name, linear_units, linear_units_conv)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.create_vertical_ex(context, name: nil, datum_name: nil, datum_auth_name: nil, datum_code: nil, linear_units: nil, linear_units_conv: 0, geoid_model_name: nil, geoid_model_auth_name: nil, geoid_model_code: nil, geoid_geog_crs: nil, accuracy: nil) ⇒ Crs

Create a VerticalCRS. This is an extended version of Crs#create_vertical that adds the capability of defining a geoid model.

Parameters:

  • context (Context)

    Context

  • name (String) (defaults to: nil)

    Name of the GeographicCRS. Default is nil.

  • datum_name (String) (defaults to: nil)

    Name of the GeodeticReferenceFrame. Default is nil.

  • datum_auth_name (String) (defaults to: nil)

    Authority name of the VerticalReferenceFrame. Default is nil.

  • datum_code (String) (defaults to: nil)

    Code of the VerticalReferenceFrame. Default is nil.

  • linear_units (String) (defaults to: nil)

    Name of the angular units. Or nil for meters.

  • linear_units_conv (Float) (defaults to: 0)

    Conversion factor from linear units to meters. Default is 0 if linear_units is nil

  • geoid_model_name (String) (defaults to: nil)

    Geoid model name. Can be a name from the geoid_model name or a string “PROJ foo.gtx”. Default is nil.

  • geoid_model_auth_name (String) (defaults to: nil)

    Authority name of the transformation for the geoid model. Default is nil.

  • geoid_model_code (String) (defaults to: nil)

    Code of the transformation for the geoid model. Default is nil.

  • geoid_geog_crs (Crs) (defaults to: nil)

    Geographic CRS for the geoid transformation. Default is nil.

  • accuracy (Float) (defaults to: nil)

    Accuracy in meters. Default is nil

Returns:



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/proj/crs.rb', line 141

def self.create_vertical_ex(context, name: nil, datum_name: nil, datum_auth_name: nil, datum_code: nil,
                            linear_units: nil, linear_units_conv: 0,
                            geoid_model_name: nil, geoid_model_auth_name: nil, geoid_model_code: nil,
                            geoid_geog_crs: nil, accuracy: nil)

  options = {"ACCURACY": accuracy.nil? ? nil : accuracy.to_s}
  options_ptr = create_options_pointer(options)

  pointer = Api.proj_create_vertical_crs_ex(context, name, datum_name, datum_auth_name, datum_code, linear_units, linear_units_conv, geoid_model_name, geoid_model_auth_name, geoid_model_code, geoid_geog_crs, options_ptr)

  if pointer.null?
    Error.check_context(context)
  end

  self.create_object(pointer, context)
end

.query_geodetic_from_datum(context, auth_name: nil, datum_auth_name:, datum_code:, crs_type: nil) ⇒ PjObjects

Find GeodeticCRSes that use the specified datum

Parameters:

  • context (Context)

    Context

  • auth_name (String) (defaults to: nil)
    • Authority name. Default is nil.

  • datum_auth_name (String)

    Datum authority name

  • datum_code (String)

    Datum code

  • crs_type (String) (defaults to: nil)

    The CRS type. Default is nil. Allowed values are:

    • geographic 2D

    • geographic 3D

    • geocentric

Returns:



295
296
297
298
299
300
301
302
303
# File 'lib/proj/crs.rb', line 295

def self.query_geodetic_from_datum(context, auth_name: nil, datum_auth_name:, datum_code:, crs_type: nil)
  pointer = Api.proj_query_geodetic_crs_from_datum(context, auth_name, datum_auth_name, datum_code, crs_type)

  if pointer.null?
    Error.check_context(context)
  end

  PjObjects.new(pointer, context)
end

Instance Method Details

#alter_cs_angular_unit(angular_units: nil, angular_units_conv: 0, unit_auth_name: nil, unit_code: nil) ⇒ Crs

Return a copy of the CRS with its angular units changed

Parameters:

  • angular_units (String) (defaults to: nil)

    Name of the angular units. Or nil for degrees.

  • angular_units_conv (Float) (defaults to: 0)

    Conversion factor from the angular unit to radians. Default is 0 if angular_units is nil

  • unit_auth_name (String) (defaults to: nil)

    Unit authority name. Defaults to nil.

  • unit_code (String) (defaults to: nil)

    Unit code. Defaults to nil.

Returns:



567
568
569
570
571
572
573
574
575
# File 'lib/proj/crs.rb', line 567

def alter_cs_angular_unit(angular_units: nil, angular_units_conv: 0, unit_auth_name: nil, unit_code: nil)
  ptr = Api.proj_crs_alter_cs_angular_unit(self.context, self, angular_units, angular_units_conv, unit_auth_name, unit_code)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#alter_cs_linear_unit(linear_units: nil, linear_units_conv: 0, unit_auth_name: nil, unit_code: nil) ⇒ Crs

Return a copy of the CRS with its linear units changed. The CRS must be or contain a ProjectedCRS, VerticalCRS or a GeocentricCRS.

Parameters:

  • linear_units (String) (defaults to: nil)

    Name of the linear units. Or nil for meters.

  • linear_units_conv (Float) (defaults to: 0)

    Conversion factor from the linear unit to meters. Default is 0 if linear_units is nil

  • unit_auth_name (String) (defaults to: nil)

    Unit authority name. Defaults to nil.

  • unit_code (String) (defaults to: nil)

    Unit code. Defaults to nil.

Returns:



586
587
588
589
590
591
592
593
594
# File 'lib/proj/crs.rb', line 586

def alter_cs_linear_unit(linear_units: nil, linear_units_conv: 0, unit_auth_name: nil, unit_code: nil)
  ptr = Api.proj_crs_alter_cs_linear_unit(self.context, self, linear_units, linear_units_conv, unit_auth_name, unit_code)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#alter_geodetic_crs(new_geod_crs) ⇒ Crs

Return a copy of the CRS with its geodetic CRS changed.

* If the CRS is a GeodeticCRS then a clone of new_geod_crs is returned.
* If the CRS is a ProjectedCRS, then it replaces the base CRS with new_geod_crs.
* If the CRS is a CompoundCRS, then it replaces the GeodeticCRS part of the horizontal
    CRS with new_geod_crs.
* In other cases, it returns a clone of obj.

Parameters:

  • new_geod_crs (Crs)

    A GeodeticCRS

Returns:



549
550
551
552
553
554
555
556
557
# File 'lib/proj/crs.rb', line 549

def alter_geodetic_crs(new_geod_crs)
  ptr = Api.proj_crs_alter_geodetic_crs(self.context, self, new_geod_crs)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#alter_id(auth_name, code) ⇒ Crs

Return a copy of the CRS with its identifier changed

Parameters:

  • auth_name (String)

    The new authority name of the CRS

  • code (String)

    The new code of the CRS

Returns:



529
530
531
532
533
534
535
536
537
# File 'lib/proj/crs.rb', line 529

def alter_id(auth_name, code)
  ptr = Api.proj_alter_id(self.context, self, auth_name, code)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#alter_name(name) ⇒ Crs

Return a copy of the CRS with its name changed

Parameters:

  • name (String)

    The new name of the CRS

Returns:



513
514
515
516
517
518
519
520
521
# File 'lib/proj/crs.rb', line 513

def alter_name(name)
  ptr = Api.proj_alter_name(self.context, self, name)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#alter_parameters_linear_unit(linear_units: nil, linear_units_conv: 0, unit_auth_name: nil, unit_code: nil, convert_to_new_unit:) ⇒ Crs

Return a copy of the CRS with its linear units changed. The CRS must be or contain a ProjectedCRS, VerticalCRS or a GeocentricCRS.

Parameters:

  • linear_units (String) (defaults to: nil)

    Name of the linear units. Or nil for meters.

  • linear_units_conv (Float) (defaults to: 0)

    Conversion factor from the linear unit to meters. Default is 0 if linear_units is nil

  • unit_auth_name (String) (defaults to: nil)

    Unit authority name. Defaults to nil.

  • unit_code (String) (defaults to: nil)

    Unit code. Defaults to nil.

  • convert_to_new_unit (Boolean)

    If true then existing values will be converted from their current unit to the new unit. If false then their values will be left unchanged and the unit overridden (so the resulting CRS will not be equivalent to the original one for reprojection purposes).

Returns:



609
610
611
612
613
614
615
616
617
618
619
# File 'lib/proj/crs.rb', line 609

def alter_parameters_linear_unit(linear_units: nil, linear_units_conv: 0, unit_auth_name: nil, unit_code: nil, convert_to_new_unit:)
  ptr = Api.proj_crs_alter_parameters_linear_unit(self.context, self, linear_units, linear_units_conv,
                                                  unit_auth_name, unit_code,
                                                  convert_to_new_unit ? 1 : 0)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#coordinate_operationPjObject

Return the Conversion of a DerivedCRS (such as a ProjectedCRS), or the Transformation from the baseCRS to the hubCRS of a BoundCRS.

Returns:



456
457
458
459
460
461
462
# File 'lib/proj/crs.rb', line 456

def coordinate_operation
  ptr = Api.proj_crs_get_coordoperation(self.context, self)
  if ptr.null?
    Error.check_object(self)
  end
  self.class.create_object(ptr, self.context)
end

#coordinate_systemCoordinateSystem

Returns the coordinate system of a SingleCRS.

Returns:



429
430
431
432
# File 'lib/proj/crs.rb', line 429

def coordinate_system
  pointer = Api.proj_crs_get_coordinate_system(self.context, self)
  CoordinateSystem.new(pointer, self.context)
end

#datumDatum

Returns the datum of a SingleCRS.



384
385
386
387
388
389
390
391
392
# File 'lib/proj/crs.rb', line 384

def datum
  ptr = Api.proj_crs_get_datum(self.context, self)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, self.context)
end

#datum_ensembleDatumEnsemble

Returns the datum ensemble of a SingleCRS.



421
422
423
424
# File 'lib/proj/crs.rb', line 421

def datum_ensemble
  pointer = Api.proj_crs_get_datum_ensemble(self.context, self)
  self.class.create_object(pointer, self.context)
end

#datum_forcedDatum

Returns a datum for a SingleCRS. If the SingleCRS has a datum, then this datum is returned. Otherwise, the SingleCRS has a datum ensemble, and this datum ensemble is returned as a regular datum instead of a datum ensemble.



401
402
403
404
# File 'lib/proj/crs.rb', line 401

def datum_forced
  pointer = Api.proj_crs_get_datum_forced(self.context, self)
  self.class.create_object(pointer, self.context)
end

#demote_to_2d(name: nil) ⇒ Crs

Create a 2D CRS from an this 3D CRS.

Parameters:

  • name (String) (defaults to: nil)

    CRS name. If nil then the name of this CRS will be used.

Returns:



642
643
644
645
646
647
648
649
650
# File 'lib/proj/crs.rb', line 642

def demote_to_2d(name: nil)
  ptr = Api.proj_crs_demote_to_2D(self.context, name, self)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#derived?Boolean

Returns whether a CRS is a Derived CRS

Returns:

  • (Boolean)
    • True if the CRS is derived



447
448
449
450
# File 'lib/proj/crs.rb', line 447

def derived?
  result = Api.proj_crs_is_derived(self.context, self)
  result == 1 ? true : false
end

#ellipsoidPjObject

Returns the ellipsoid



439
440
441
442
# File 'lib/proj/crs.rb', line 439

def ellipsoid
  pointer = Api.proj_get_ellipsoid(self.context, self)
  self.class.create_object(pointer, self.context)
end

#geodetic_crsCrs

Get the geodeticCRS / geographicCRS from a CRS.

Examples:

crs = Proj::Crs.new('EPSG:4326')
geodetic = crs.geodetic_crs
assert_equal(:PJ_TYPE_GEOGRAPHIC_2D_CRS, geodetic.proj_type)
assert_equal('+proj=longlat +datum=WGS84 +no_defs +type=crs', geodetic.to_proj_string)

Returns:

See Also:



362
363
364
365
# File 'lib/proj/crs.rb', line 362

def geodetic_crs
  pointer = Api.proj_crs_get_geodetic_crs(self.context, self)
  self.class.create_object(pointer, self.context)
end

#horizontal_datumCrs

Get the horizontal datum from a CRS.



411
412
413
414
# File 'lib/proj/crs.rb', line 411

def horizontal_datum
  pointer = Api.proj_crs_get_horizontal_datum(self.context, self)
  self.class.create_object(pointer, self.context)
end

#identify(auth_name) ⇒ Array

Returns a list of matching reference CRS, and the percentage (0-100) of confidence in the match.

Parameters:

  • auth_name (String)
    • Authority name, or nil for all authorities

Returns:

  • (Array)
    • Array of CRS objects sorted by decreasing confidence.



487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/proj/crs.rb', line 487

def identify(auth_name)
  confidences_out_ptr = FFI::MemoryPointer.new(:pointer)
  pointer = Api.proj_identify(self.context, self, auth_name, nil, confidences_out_ptr)
  objects = PjObjects.new(pointer, self.context)

  # Get confidences and free the list
  confidences_ptr = confidences_out_ptr.read_pointer
  confidences = confidences_ptr.read_array_of_type(:int, :read_int, objects.count)
  Api.proj_int_list_destroy(confidences_ptr)

  return objects, confidences
end

#point_motion_operation?Boolean

Returns whether a CRS has an associated PointMotionOperation

Returns:

  • (Boolean)


467
468
469
470
# File 'lib/proj/crs.rb', line 467

def point_motion_operation?
  result = Api.proj_crs_get_coordoperation(self.context, self)
  result == 1 ? true : false
end

#prime_meridianPjObject

Returns the prime meridian



477
478
479
480
# File 'lib/proj/crs.rb', line 477

def prime_meridian
  pointer = Api.proj_get_prime_meridian(self.context, self)
  self.class.create_object(pointer, self.context)
end

#projected_3d(name: nil, geog_3d_crs: nil) ⇒ Crs

Create a projected 3D CRS from this projected 2D CRS.

This CRS’s name is replaced by the name parameter and its base geographic CRS is replaced by geog_3D_crs. The vertical axis of geog_3D_crs (ellipsoidal height) will be added as the 3rd axis of the resulting projected 3D CRS.

Normally, the passed geog_3D_crs should be the 3D counterpart of the original 2D base geographic CRS of projected_2D_crs, but such no check is done.

It is also possible to invoke this function with a nil geog_3D_crs. In this case the existing base geographic of this CRS will be automatically promoted to 3D by assuming a 3rd axis being an ellipsoidal height, oriented upwards, and with metre units. This is equivalent to using Crs#promote_to_3d

Parameters:

  • name (String) (defaults to: nil)

    CRS name. If nil then the name of this CRS will be used.

  • geog_3d_crs (Crs) (defaults to: nil)

    Base geographic 3D CRS for the new CRS. Defaults to nil.

Returns:



670
671
672
673
674
675
676
677
678
# File 'lib/proj/crs.rb', line 670

def projected_3d(name: nil, geog_3d_crs: nil)
  ptr = Api.proj_crs_create_projected_3D_crs_from_2D(self.context, name, self, geog_3d_crs)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#promote_to_3d(name: nil) ⇒ Crs

Create a 3D CRS from this 2D CRS. The new axis will be ellipsoidal height, oriented upwards, and with metre units.

Parameters:

  • name (String) (defaults to: nil)

    CRS name. If nil then the name of this CRS will be used.

Returns:



627
628
629
630
631
632
633
634
635
# File 'lib/proj/crs.rb', line 627

def promote_to_3d(name: nil)
  ptr = Api.proj_crs_promote_to_3D(self.context, name, self)

  if ptr.null?
    Error.check_object(self)
  end

  self.class.create_object(ptr, context)
end

#sub_crs(index) ⇒ Crs

Get a CRS component from a CompoundCRS.

Parameters:

  • index (Integer)

    Index of the CRS component (typically 0 = horizontal, 1 = vertical)

Returns:

See Also:



374
375
376
377
# File 'lib/proj/crs.rb', line 374

def sub_crs(index)
  pointer = Api.proj_crs_get_sub_crs(self.context, self, index)
  self.class.create_object(pointer, self.context)
end