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, #area_of_use, #auth, #auth_name, #context, #context=, create, create_from_database, create_from_name, create_from_wkt, #definition, #deprecated?, #description, #destroy, #domains, #equivalent_to?, #errorno, #factors, #geod_direct, #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

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.



349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/proj/crs.rb', line 349

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:



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

def self.create_bound(context, base_crs:, hub_crs:, transformation:)
  Error.validate_context!(context)
  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:



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

def self.create_bound_to_wgs84(context, crs:, allow_intermediate_crs: "NEVER")
  Error.validate_context!(context)
  options = Options.new("ALLOW_INTERMEDIATE_CRS": allow_intermediate_crs)

  pointer = Api.proj_crs_create_bound_crs_to_wgs84(context, crs, options)

  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:



118
119
120
121
122
123
124
125
126
127
# File 'lib/proj/crs.rb', line 118

def self.create_bound_vertical(context, vertical_crs:, hub_crs:, grid_name:)
  Error.validate_context!(context)
  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:



171
172
173
174
175
176
177
178
179
180
# File 'lib/proj/crs.rb', line 171

def self.create_compound(context, name:, horizontal_crs:, vertical_crs:)
  Error.validate_context!(context)
  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:



283
284
285
286
287
288
289
290
291
292
# File 'lib/proj/crs.rb', line 283

def self.create_derived_geographic(context, name: nil, base_geographic_crs:, conversion:, coordinate_system:)
  Error.validate_context!(context)
  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:



78
79
80
81
82
83
84
85
86
87
# File 'lib/proj/crs.rb', line 78

def self.create_engineering(context, name:)
  Error.validate_context!(context)
  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:



243
244
245
246
247
248
249
250
251
252
# File 'lib/proj/crs.rb', line 243

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:)
  Error.validate_context!(context)
  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:



263
264
265
266
267
268
269
270
271
272
# File 'lib/proj/crs.rb', line 263

def self.create_geocentric_from_datum(context, name:, datum:, linear_units:, linear_units_conv:)
  Error.validate_context!(context)
  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:



197
198
199
200
201
202
203
204
205
206
# File 'lib/proj/crs.rb', line 197

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:)
  Error.validate_context!(context)
  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:



216
217
218
219
220
221
222
223
224
225
# File 'lib/proj/crs.rb', line 216

def self.create_geographic_from_datum(context, name:, datum:, coordinate_system:)
  Error.validate_context!(context)
  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
25
# File 'lib/proj/crs.rb', line 16

def self.create_projected(context, name: nil, geodetic_crs:, conversion:, coordinate_system:)
  Error.validate_context!(context)
  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:



98
99
100
101
102
103
104
105
106
107
# File 'lib/proj/crs.rb', line 98

def self.create_vertical(context, name:, datum_name:, linear_units:, linear_units_conv:)
  Error.validate_context!(context)
  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:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/proj/crs.rb', line 146

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)
  Error.validate_context!(context)

  options = Options.new("ACCURACY": accuracy.nil? ? nil : accuracy.to_s)

  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)

  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:



306
307
308
309
310
311
312
313
314
315
# File 'lib/proj/crs.rb', line 306

def self.query_geodetic_from_datum(context, auth_name: nil, datum_auth_name:, datum_code:, crs_type: nil)
  Error.validate_context!(context)
  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:



575
576
577
578
579
580
581
582
583
# File 'lib/proj/crs.rb', line 575

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:



594
595
596
597
598
599
600
601
602
# File 'lib/proj/crs.rb', line 594

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:



557
558
559
560
561
562
563
564
565
# File 'lib/proj/crs.rb', line 557

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:



537
538
539
540
541
542
543
544
545
# File 'lib/proj/crs.rb', line 537

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:



521
522
523
524
525
526
527
528
529
# File 'lib/proj/crs.rb', line 521

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:



617
618
619
620
621
622
623
624
625
626
627
# File 'lib/proj/crs.rb', line 617

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:



472
473
474
475
476
477
478
# File 'lib/proj/crs.rb', line 472

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:



441
442
443
444
# File 'lib/proj/crs.rb', line 441

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.



396
397
398
399
400
401
402
403
404
# File 'lib/proj/crs.rb', line 396

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.



433
434
435
436
# File 'lib/proj/crs.rb', line 433

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.



413
414
415
416
# File 'lib/proj/crs.rb', line 413

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:



650
651
652
653
654
655
656
657
658
# File 'lib/proj/crs.rb', line 650

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)


459
460
461
462
463
464
465
466
# File 'lib/proj/crs.rb', line 459

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

#ellipsoidPjObject

Returns the ellipsoid



451
452
453
454
# File 'lib/proj/crs.rb', line 451

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:



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

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.



423
424
425
426
# File 'lib/proj/crs.rb', line 423

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.



503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/proj/crs.rb', line 503

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)


483
484
485
486
# File 'lib/proj/crs.rb', line 483

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

#prime_meridianPjObject

Returns the prime meridian



493
494
495
496
# File 'lib/proj/crs.rb', line 493

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:



678
679
680
681
682
683
684
685
686
# File 'lib/proj/crs.rb', line 678

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:



635
636
637
638
639
640
641
642
643
# File 'lib/proj/crs.rb', line 635

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:



386
387
388
389
# File 'lib/proj/crs.rb', line 386

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