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("         GEOGCRS[\"WGS 84\",\n         DATUM[\"World Geodetic System 1984\",\n               ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n                         LENGTHUNIT[\"meter\",1]]],\n         PRIMEM[\"Greenwich\",0,\n                ANGLEUNIT[\"degree\",0.0174532925199433]],\n         CS[ellipsoidal,2],\n         AXIS[\"geodetic latitude (Lat)\",north,\n              ORDER[1],\n              ANGLEUNIT[\"degree\",0.0174532925199433]],\n         AXIS[\"geodetic longitude (Lon)\",east,\n              ORDER[2],\n              ANGLEUNIT[\"degree\",0.0174532925199433]],\n         USAGE[\n             SCOPE[\"unknown\"],\n                 AREA[\"World\"],\n             BBOX[-90,-180,90,180]],\n         ID[\"EPSG\",4326]]\n       EOS\n")

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