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:

  • ctx (Context)

    Context

  • base_crs (CRS)

    Base CRS

  • hub_crs (CRS)

    HUB CRS

  • transformation (Transformation)

Returns:

  • (CRS)


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:

  • ctx (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:

  • (CRS)


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:

  • ctx (Context)

    Context

  • vertical_crs (CRS)

    A VerticalCRS

  • hub_geographic_3d_crs (CRS)

    A Geographic 3D CRS

  • grid_name (String)

    Grid name (typically a .gtx file)

Returns:

  • (CRS)


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:

  • ctx (Context)

    Context

  • name (String)

    Name of the GeographicCRS. Default is nil.

  • horizontal_crs (CRS)

    A horizontal CRS

  • vertical_crs (CRS)

    A vertical CRS

Returns:

  • (CRS)


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:

  • ctx (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:

  • (CRS)


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:

  • ctx (Context)

    Context

  • name (String)

    Name of the CRS. Default is nil.

Returns:

  • (CRS)


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:, ellps_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:

  • ctx (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 (Double)

    Ellipsoid semi-major axis, in meters.

  • inv_flattening (Double)

    Ellipsoid inverse flattening. Or 0 for a sphere.

  • prime_meridian_name (String)

    Name of the PrimeMeridian. Default is nil.

  • prime_meridian_offset (Double)

    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 (Double)

    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 (Double)

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

Returns:

  • (CRS)


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

def self.create_geocentric(context, name:, datum_name:, ellps_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, ellps_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:

  • ctx (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 (Double)

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

Returns:

  • (CRS)


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:, ellps_name:, semi_major_meter:, inv_flattening:, prime_meridian_name:, prime_meridian_offset:, pm_angular_units:, pm_units_conv:, coordinate_system:) ⇒ CRS

Create a GeographicCRS.

Parameters:

  • ctx (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 (Double)

    Ellipsoid semi-major axis, in meters.

  • inv_flattening (Double)

    Ellipsoid inverse flattening. Or 0 for a sphere.

  • prime_meridian_name (String)

    Name of the PrimeMeridian. Default is nil.

  • prime_meridian_offset (Double)

    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 (Double)

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

  • coordinate_system (CoordinateSystem)

    Ellipsoidal coordinate system

Returns:

  • (CRS)


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

def self.create_geographic(context, name:, datum_name:, ellps_name:, semi_major_meter:, inv_flattening:, prime_meridian_name:, prime_meridian_offset:, pm_angular_units:, pm_units_conv:, coordinate_system:)
  pointer = Api.proj_create_geographic_crs(context, name, datum_name, ellps_name, semi_major_meter, inv_flattening, prime_meridian_name, prime_meridian_offset, pm_angular_units, pm_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:

  • ctx (Context)

    Context

  • name (String)

    Name of the GeographicCRS. Default is nil.

  • datum (Datum | DatumEnsemble)

    Datum or DatumEnsemble

  • coordinate_system (CoordinateSystem)

    Ellipsoidal coordinate system

Returns:

  • (CRS)


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:

  • ctx (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:

  • (CRS)


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:

  • ctx (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 (Double)

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

Returns:

  • (CRS)


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:

  • ctx (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 (Double) (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 (Double) (defaults to: nil)

    Accuracy in meters. Default is nil

Returns:

  • (CRS)


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:

  • ctx (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 (Double) (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:

  • (CRS)


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

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 (Double) (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:

  • (CRS)


578
579
580
581
582
583
584
585
586
# File 'lib/proj/crs.rb', line 578

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:

  • (CRS)


541
542
543
544
545
546
547
548
549
# File 'lib/proj/crs.rb', line 541

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:

  • name (String)

    The new authority name of the CRS

  • code (String)

    The new code of the CRS

Returns:

  • (CRS)


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

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:

  • (CRS)


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

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 (Double) (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:

  • (CRS)


601
602
603
604
605
606
607
608
609
610
611
# File 'lib/proj/crs.rb', line 601

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:

  • (CRS)


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

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:

  • (CRS)

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.



479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/proj/crs.rb', line 479

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

#prime_meridianPjObject

Returns the prime meridian



469
470
471
472
# File 'lib/proj/crs.rb', line 469

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)

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

Returns:

  • (CRS)


662
663
664
665
666
667
668
669
670
# File 'lib/proj/crs.rb', line 662

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:

  • (CRS)


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

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:

  • (CRS)

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