Method: Proj::Crs#initialize

Defined in:
lib/proj/crs.rb

#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:

  • . See above

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