Class: PROJ

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/simple-proj.rb,
lib/simple-proj.rb,
lib/simple-proj.rb,
ext/rb_proj.c

Overview

Marshalling

Defined Under Namespace

Modules: Common Classes: CRS, FACTORS

Constant Summary collapse

VERSION =
_info["version"]
ENDIAN =
( [1].pack("I") == [1].pack("N") ) ? :big : :little
WKT2_2015 =
INT2NUM(PJ_WKT2_2015)
WKT2_2015_SIMPLIFIED =
INT2NUM(PJ_WKT2_2015_SIMPLIFIED)
WKT2_2018 =
INT2NUM(PJ_WKT2_2018)
WKT2_2018_SIMPLIFIED =
INT2NUM(PJ_WKT2_2018_SIMPLIFIED)
WKT2_2019 =
INT2NUM(PJ_WKT2_2019)
WKT2_2019_SIMPLIFIED =
INT2NUM(PJ_WKT2_2019_SIMPLIFIED)
WKT1_GDAL =
INT2NUM(PJ_WKT1_GDAL)
WKT1_ESRI =
INT2NUM(PJ_WKT1_ESRI)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#ellipsoid_parameters, #id_auth_name, #id_code, #initialize_copy, #name, #to_epsg_code, #to_proj_string, #to_projjson, #to_projjson_as_hash, #to_wkt, #to_wkt2_2015, #to_wkt2_2015_simplified, #to_wkt2_2018, #to_wkt2_2018_simplified, #to_wkt_esri, #to_wkt_gdal

Constructor Details

#initialize(def1, def2 = nil) ⇒ Object

Constructs a transformation object with one or two arguments. The arguments should be PROJ::CRS objects or String objects one of

a proj-string,
a WKT string,
an object code (like “EPSG:4326”, “urn:ogc:def:crs:EPSG::4326”,
  “urn:ogc:def:coordinateOperation:EPSG::1671”),
an Object name. e.g “WGS 84”, “WGS 84 / UTM zone 31N”.
  In that case as uniqueness is not guaranteed,
  heuristics are applied to determine the appropriate best match.
a OGC URN combining references for compound coordinate reference
  systems (e.g “urn:ogc:def:crs,crs:EPSG::2393,crs:EPSG::5717” or
  custom abbreviated syntax “EPSG:2393+5717”),
a OGC URN combining references for concatenated operations (e.g.
  “urn:ogc:def:coordinateOperation,coordinateOperation:EPSG::3895,
  coordinateOperation:EPSG::1618”)
a PROJJSON string.
  The jsonschema is at https://proj.org/schemas/v0.4/projjson.schema.json (added in PROJ 6.2)
a compound CRS made from two object names separated with ” + “.
  e.g. “WGS 84 + EGM96 height” (added in 7.1)

If two arguments are given, the first is the source CRS definition and the second is the target CRS definition. If only one argument is given, the following two cases are possible.

a proj-string, which represents a transformation.
a CRS defintion, in which case the latlong coordinates are implicitly
  used as the source CRS definition.
a PROJ::CRS object

Examples:

# Transformation from EPSG:4326 to EPSG:3857
pj = PROJ.new("EPSG:4326", "EPSG:3857")

# Transformation from (lat,lon) to WEB Mercator.
pj = PROJ.new("+proj=webmerc")

# Transformation from (lat,lon) to EPSG:3857
pj = PROJ.new("EPSG:3857")

# Using PROJ::CRS objects
epsg_3857 = PROJ::CRS.new("EPSG:3857")
pj = PROJ.new(epsg_3857)
pj = PROJ.new("EPSG:4326", epsg_3857)
pj = PROJ.new(epsg_3857, "EPSG:4326")

Parameters:

  • def1 (String)

    proj-string or other CRS definition (see above description).

  • def2 (String, nil) (defaults to: nil)

    proj-string or other CRS definition (see above description).



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'ext/rb_proj.c', line 99

static VALUE
rb_proj_initialize (int argc, VALUE *argv, VALUE self)
{
  volatile VALUE vdef1, vdef2;
  Proj *proj, *crs;
  PJ *ref, *src;
  PJ_TYPE type;
  int errno;

  rb_scan_args(argc, argv, "11", (VALUE *)&vdef1, (VALUE *)&vdef2);

  Data_Get_Struct(self, Proj, proj);

  if ( NIL_P(vdef2) ) {
    if ( rb_obj_is_kind_of(vdef1, rb_cCrs) ) {
      Data_Get_Struct(vdef1, Proj, crs);
      vdef1 = rb_str_new2(proj_as_proj_string(PJ_DEFAULT_CTX, crs->ref, PJ_PROJ_5, NULL));
    }
    else {
      Check_Type(vdef1, T_STRING);
    }
    ref = proj_create(PJ_DEFAULT_CTX, StringValuePtr(vdef1));      
    if ( proj_is_crs(ref) ) {
      proj_destroy(ref);
      ref = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "+proj=latlong +type=crs", StringValuePtr(vdef1), NULL);    
      proj->ref = ref;
      proj->is_src_latlong = 2;      
    }
    else {
      proj->ref = ref;
      proj->is_src_latlong = 1;      
    }
  }
  else {
    if ( rb_obj_is_kind_of(vdef1, rb_cCrs) ) {
      Data_Get_Struct(vdef1, Proj, crs);
      vdef1 = rb_str_new2(proj_as_proj_string(PJ_DEFAULT_CTX, crs->ref, PJ_PROJ_5, NULL));
    }
    else {
      Check_Type(vdef1, T_STRING);
    }
    if ( rb_obj_is_kind_of(vdef2, rb_cCrs) ) {
      Data_Get_Struct(vdef2, Proj, crs);
      vdef2 = rb_str_new2(proj_as_proj_string(PJ_DEFAULT_CTX, crs->ref, PJ_PROJ_5, NULL));
    }
    else {
      Check_Type(vdef2, T_STRING);
    }
    ref = proj_create_crs_to_crs(PJ_DEFAULT_CTX, StringValuePtr(vdef1), StringValuePtr(vdef2), NULL);    
    proj->ref = ref;
    src = proj_get_source_crs(PJ_DEFAULT_CTX, ref);
    type = proj_get_type(src);
    if ( type == PJ_TYPE_GEOGRAPHIC_2D_CRS ||
         type == PJ_TYPE_GEOGRAPHIC_3D_CRS ) {
      proj->is_src_latlong = 2;      
    }
    else {
      proj->is_src_latlong = 0;      
    }
  }
  
  if ( ! ref ) {
    errno = proj_context_errno(PJ_DEFAULT_CTX);
    rb_raise(rb_eRuntimeError, "%s", proj_errno_string(errno));
  }
  
  return Qnil;
}

Class Method Details

._infoObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'ext/rb_proj.c', line 11

static VALUE
rb_proj_info (VALUE klass)
{
  volatile VALUE vout;
  PJ_INFO info;

  info = proj_info();

  vout = rb_hash_new();
  rb_hash_aset(vout, rb_str_new2("major"), INT2NUM(info.major));
  rb_hash_aset(vout, rb_str_new2("minor"), INT2NUM(info.minor));
  rb_hash_aset(vout, rb_str_new2("patch"), INT2NUM(info.patch));
  rb_hash_aset(vout, rb_str_new2("release"), rb_str_new2(info.release));
  rb_hash_aset(vout, rb_str_new2("version"), rb_str_new2(info.version));
  rb_hash_aset(vout, rb_str_new2("searchpath"), rb_str_new2(info.searchpath));

  return vout;
}

.infoOpenStruct

Returns PROJ info

Returns:

  • (OpenStruct)


13
14
15
# File 'lib/simple-proj.rb', line 13

def self.info
  return OpenStruct.new(_info)
end

Instance Method Details

#_dump_dataObject



168
169
170
# File 'lib/simple-proj.rb', line 168

def _dump_data 
  return to_wkt
end

#_load_data(wkt) ⇒ Object



172
173
174
# File 'lib/simple-proj.rb', line 172

def _load_data (wkt)
  initialize_copy self.class.new(wkt)
end

#angular_input?Boolean

Checks if a operation expects input in radians or not.

Returns:

  • (Boolean)


246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'ext/rb_proj.c', line 246

static VALUE
rb_proj_angular_input (VALUE self, VALUE direction)
{
  Proj *proj;

  Data_Get_Struct(self, Proj, proj);
  
  if ( rb_to_id(direction) == id_forward ) {
    return proj_angular_input(proj->ref, PJ_FWD) == 1 ? Qtrue : Qfalse;
  }
  else if ( rb_to_id(direction) == id_inverse ) {
    return proj_angular_input(proj->ref, PJ_INV) == 1 ? Qtrue : Qfalse;    
  }
  else {
    rb_raise(rb_eArgError, "invalid direction");
  }
}

#angular_output?Boolean

Checks if an operation returns output in radians or not.

Returns:

  • (Boolean)


270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'ext/rb_proj.c', line 270

static VALUE
rb_proj_angular_output (VALUE self, VALUE direction)
{
  Proj *proj;

  Data_Get_Struct(self, Proj, proj);
  
  if ( rb_to_id(direction) == id_forward ) {
    return proj_angular_output(proj->ref, PJ_FWD) == 1 ? Qtrue : Qfalse;
  }
  else if ( rb_to_id(direction) == id_inverse ) {
    return proj_angular_output(proj->ref, PJ_INV) == 1 ? Qtrue : Qfalse;    
  }
  else {
    rb_raise(rb_eArgError, "invalid direction");
  }
}

#definitionOpenStruct

Returns a definition of the object

Returns:

  • (OpenStruct)


55
56
57
# File 'lib/simple-proj.rb', line 55

def definition
  return pj_info.definition
end

#factors(lon, lat) ⇒ Object

Returns PROJ::FACTORS object



97
98
99
# File 'lib/simple-proj.rb', line 97

def factors (lon, lat)
  return FACTORS.read(_factors(lon, lat))
end

#forward(lon1, lat1, z1 = nil) ⇒ Object Also known as: forward_lonlat

Transforms coordinates forwardly from (lat1, lon1, z1) to (x1, y2, z2). The order of coordinates arguments should be longitude, latitude, and height. The input longitude and latitude should be in units ‘degrees’. If the returned coordinates are angles, they are converted in units ‘degrees`.

Examples:

x2, y2 = pj.forward(lon1, lat1)
x2, y2, z2 = pj.forward(lon1, lat1, z1)

Parameters:

  • lon1 (Numeric)

    longitude in degrees.

  • lat1 (Numeric)

    latitude in degrees.

  • z1 (Numeric, nil) (defaults to: nil)

    vertical coordinate.

Returns:

  • x2, y2[, z2]



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'ext/rb_proj.c', line 345

static VALUE
rb_proj_forward (int argc, VALUE *argv, VALUE self)
{
  volatile VALUE vlon, vlat, vz;
  Proj *proj;
  PJ_COORD data_in, data_out;
  int errno;

  rb_scan_args(argc, argv, "21", (VALUE*) &vlon, (VALUE*) &vlat, (VALUE*) &vz);

  Data_Get_Struct(self, Proj, proj);

  if ( ! proj->is_src_latlong ) {
    rb_raise(rb_eRuntimeError, "requires latlong src crs. use #transform_forward instead of #forward.");
  }

  if ( proj_angular_input(proj->ref, PJ_FWD) == 1 ) {
    data_in.lpz.lam = proj_torad(NUM2DBL(vlon));
    data_in.lpz.phi = proj_torad(NUM2DBL(vlat));
    data_in.lpz.z   = NIL_P(vz) ? 0.0 : NUM2DBL(vz);
  }
  else {
    data_in.xyz.x = NUM2DBL(vlon);
    data_in.xyz.y = NUM2DBL(vlat);
    data_in.xyz.z = NIL_P(vz) ? 0.0 : NUM2DBL(vz);    
  }

  data_out = proj_trans(proj->ref, PJ_FWD, data_in);

  if ( data_out.xyz.x == HUGE_VAL ) {
    errno = proj_context_errno(PJ_DEFAULT_CTX);
    rb_raise(rb_eRuntimeError, "%s", proj_errno_string(errno));
  }

  if (  proj_angular_output(proj->ref, PJ_FWD) == 1 ) {    
    if ( NIL_P(vz) ) {
      return rb_assoc_new(rb_float_new(proj_todeg(data_out.lpz.lam)), 
                          rb_float_new(proj_todeg(data_out.lpz.phi)));
    } else {
      return rb_ary_new3(3, rb_float_new(proj_todeg(data_out.lpz.lam)), 
                            rb_float_new(proj_todeg(data_out.lpz.phi)),
                            rb_float_new(data_out.lpz.z));
    }
  }
  else {
    if ( NIL_P(vz) ) {
      return rb_assoc_new(rb_float_new(data_out.xyz.x), 
                          rb_float_new(data_out.xyz.y));    
    } else {
      return rb_ary_new3(3, rb_float_new(data_out.xyz.x), 
                            rb_float_new(data_out.xyz.y),
                            rb_float_new(data_out.xyz.z));        
    }
  }
  
}

#forward(lon1, lat1, z1 = nil) ⇒ Object

Transforms coordinates forwardly from (lat1, lon1, z1) to (x1, y2, z2). The order of coordinates arguments should be longitude, latitude, and height. The input longitude and latitude should be in units ‘degrees’. If the returned coordinates are angles, they are treated as in units ‘radians`.

Examples:

x2, y2 = pj.forward(lon1, lat1)
x2, y2, z2 = pj.forward(lon1, lat1, z1)

Parameters:

  • lon1 (Numeric)

    longitude in degrees.

  • lat1 (Numeric)

    latitude in degrees.

  • z1 (Numeric, nil) (defaults to: nil)

    vertical coordinate.

Returns:

  • x2, y2[, z2]



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'ext/rb_proj.c', line 420

static VALUE
rb_proj_forward_bang (int argc, VALUE *argv, VALUE self)
{
  volatile VALUE vlon, vlat, vz;
  Proj *proj;
  PJ_COORD data_in, data_out;
  int errno;

  rb_scan_args(argc, argv, "21", (VALUE*) &vlon, (VALUE*) &vlat, (VALUE*) &vz);

  Data_Get_Struct(self, Proj, proj);

  if ( ! proj->is_src_latlong ) {
    rb_raise(rb_eRuntimeError, "requires latlong src crs. use #transform_forward instead of #forward.");
  }

  if ( proj_angular_input(proj->ref, PJ_FWD) == 1 ) {
    data_in.lpz.lam = proj_torad(NUM2DBL(vlon));
    data_in.lpz.phi = proj_torad(NUM2DBL(vlat));
    data_in.lpz.z   = NIL_P(vz) ? 0.0 : NUM2DBL(vz);
  }
  else {
    data_in.xyz.x = NUM2DBL(vlon);
    data_in.xyz.y = NUM2DBL(vlat);
    data_in.xyz.z = NIL_P(vz) ? 0.0 : NUM2DBL(vz);    
  }

  data_out = proj_trans(proj->ref, PJ_FWD, data_in);

  if ( data_out.xyz.x == HUGE_VAL ) {
    errno = proj_context_errno(PJ_DEFAULT_CTX);
    rb_raise(rb_eRuntimeError, "%s", proj_errno_string(errno));
  }

  if ( NIL_P(vz) ) {
    return rb_assoc_new(rb_float_new(data_out.xyz.x), 
                        rb_float_new(data_out.xyz.y));    
  } else {
    return rb_ary_new3(3, rb_float_new(data_out.xyz.x), 
                          rb_float_new(data_out.xyz.y),
                          rb_float_new(data_out.xyz.z));        
  }
  
}

#forward_latlon(lat, lon, z = nil) ⇒ Object

A variant of #forward which accept the axis order as (lat, lon).



22
23
24
# File 'lib/simple-proj.rb', line 22

def forward_latlon (lat, lon, z = nil)
  return forward(lon, lat, z)
end

#inverse(x1, y1, z1 = nil) ⇒ Object Also known as: inverse_lonlat

Transforms coordinates inversely from (x1, y1, z1) to (lon2, lat2, z2). The order of output coordinates is longitude, latitude and height. If the input coordinates are angles, they are treated as being in units ‘degrees`. The returned longitude and latitude are in units ’degrees’.

Examples:

lon2, lat2 = pj.inverse(x1, y1)
lon2, lat2, z2 = pj.inverse(x1, y1, z1)

Parameters:

  • x1 (Numeric)
  • y1 (Numeric)
  • z1 (Numeric, nil) (defaults to: nil)

Returns:

  • lon2, lat2, [, z2]



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
# File 'ext/rb_proj.c', line 483

static VALUE
rb_proj_inverse (int argc, VALUE *argv, VALUE self)
{
  volatile VALUE vx, vy, vz;
  Proj *proj;
  PJ_COORD data_in, data_out;
  int errno;

  rb_scan_args(argc, argv, "21", (VALUE *)&vx, (VALUE *)&vy, (VALUE *)&vz);
  Data_Get_Struct(self, Proj, proj);

  if ( ! proj->is_src_latlong ) {
    rb_raise(rb_eRuntimeError, "requires latlong src crs. use #transform_inverse instead of #inverse.");
  }

  if ( proj_angular_input(proj->ref, PJ_INV) == 1 ) {
    data_in.lpz.lam = proj_torad(NUM2DBL(vx));
    data_in.lpz.phi = proj_torad(NUM2DBL(vy));
    data_in.lpz.z   = NIL_P(vz) ? 0.0 : NUM2DBL(vz);
  }
  else {
    data_in.xyz.x = NUM2DBL(vx);
    data_in.xyz.y = NUM2DBL(vy);
    data_in.xyz.z = NIL_P(vz) ? 0.0 : NUM2DBL(vz);
  }

  data_out = proj_trans(proj->ref, PJ_INV, data_in);

  if ( data_out.lpz.lam == HUGE_VAL ) {
    errno = proj_errno(proj->ref);
    rb_raise(rb_eRuntimeError, "%s", proj_errno_string(errno));
  }

  if (  proj_angular_output(proj->ref, PJ_INV) == 1 ) {    
    if ( NIL_P(vz) ) {
      return rb_assoc_new(rb_float_new(proj_todeg(data_out.lpz.lam)), 
                          rb_float_new(proj_todeg(data_out.lpz.phi)));
    } else {
      return rb_ary_new3(3, rb_float_new(proj_todeg(data_out.lpz.lam)), 
                            rb_float_new(proj_todeg(data_out.lpz.phi)),
                            rb_float_new(data_out.lpz.z));
    }
  }
  else {
    if ( NIL_P(vz) ) {
      return rb_assoc_new(rb_float_new(data_out.xyz.x), 
                          rb_float_new(data_out.xyz.y));
    } else {
      return rb_ary_new3(3, rb_float_new(data_out.xyz.x), 
                            rb_float_new(data_out.xyz.y),
                            rb_float_new(data_out.xyz.z));
    }    
  }
}

#inverse(x1, y1, z1 = nil) ⇒ Object

Transforms coordinates inversely from (x1, y1, z1) to (lon2, lat2, z2). The order of output coordinates is longitude, latitude and height. If the input coordinates are angles, they are treated as being in units ‘radians`. The returned longitude and latitude are in units ’degrees’.

Examples:

lon2, lat2 = pj.inverse(x1, y1)
lon2, lat2, z2 = pj.inverse(x1, y1, z1)

Parameters:

  • x1 (Numeric)
  • y1 (Numeric)
  • z1 (Numeric, nil) (defaults to: nil)

Returns:

  • lon2, lat2, [, z2]



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'ext/rb_proj.c', line 556

static VALUE
rb_proj_inverse_bang (int argc, VALUE *argv, VALUE self)
{
  volatile VALUE vx, vy, vz;
  Proj *proj;
  PJ_COORD data_in, data_out;
  int errno;

  rb_scan_args(argc, argv, "21", (VALUE *)&vx, (VALUE *)&vy, (VALUE *)&vz);
  Data_Get_Struct(self, Proj, proj);

  if ( ! proj->is_src_latlong ) {
    rb_raise(rb_eRuntimeError, "requires latlong src crs. use #transform_inverse instead of #inverse.");
  }

  data_in.xyz.x = NUM2DBL(vx);
  data_in.xyz.y = NUM2DBL(vy);
  data_in.xyz.z = NIL_P(vz) ? 0.0 : NUM2DBL(vz);

  data_out = proj_trans(proj->ref, PJ_INV, data_in);

  if ( data_out.lpz.lam == HUGE_VAL ) {
    errno = proj_errno(proj->ref);
    rb_raise(rb_eRuntimeError, "%s", proj_errno_string(errno));
  }

  if (  proj_angular_output(proj->ref, PJ_INV) == 1 ) {    
    if ( NIL_P(vz) ) {
      return rb_assoc_new(rb_float_new(proj_todeg(data_out.lpz.lam)), 
                          rb_float_new(proj_todeg(data_out.lpz.phi)));
    } else {
      return rb_ary_new3(3, rb_float_new(proj_todeg(data_out.lpz.lam)), 
                            rb_float_new(proj_todeg(data_out.lpz.phi)),
                            rb_float_new(data_out.lpz.z));
    }
  }
  else {
    if ( NIL_P(vz) ) {
      return rb_assoc_new(rb_float_new(data_out.xyz.x), 
                          rb_float_new(data_out.xyz.y));
    } else {
      return rb_ary_new3(3, rb_float_new(data_out.xyz.x), 
                            rb_float_new(data_out.xyz.y),
                            rb_float_new(data_out.xyz.z));
    }    
  }
}

#inverse_latlon(x, y, z = nil) ⇒ Object

A variant of #inverse which return the output with the axis order in (lat, lon).



29
30
31
# File 'lib/simple-proj.rb', line 29

def inverse_latlon (x, y, z = nil)
  return inverse_latlon(x, y, z)
end

#normalize_for_visualizationself

Normalizes the axis order which is the one expected for visualization purposes. If the axis order of its source or target CRS is northing, easting, then an axis swap operation will be inserted.

Returns:

  • (self)


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'ext/rb_proj.c', line 175

static VALUE
rb_proj_normalize_for_visualization (VALUE self)
{
  Proj *proj;
  PJ *ref, *orig;
  int errno;

  Data_Get_Struct(self, Proj, proj);
  orig = proj->ref;

  ref = proj_normalize_for_visualization(PJ_DEFAULT_CTX, orig);
  if ( ! ref ) {
    errno = proj_context_errno(PJ_DEFAULT_CTX);
    rb_raise(rb_eRuntimeError, "%s", proj_errno_string(errno));
  }

  proj->ref = ref;

  proj_destroy(orig);
    
  return self;  
}

#pj_infoOpenStruct

Returns a internal information of the object

Returns:

  • (OpenStruct)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/simple-proj.rb', line 36

def pj_info
  info = _pj_info
  if info["id"] == "unknown"
    transform(0,0)
    info = _pj_info
    if info["id"] == "unknown"
      return OpenStruct.new(info)
    else
      return pj_info
    end
  else
    info["definition"] = info["definition"].strip.split(/\s+/).map{|s| "+"+s}.join(" ")
    return OpenStruct.new(info)
  end
end

#source_crsPROJ?

Returns source CRS as PROJ::CRS object.

Returns:



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'ext/rb_proj.c', line 203

static VALUE
rb_proj_source_crs (VALUE self)
{
  Proj *proj;
  PJ *crs;

  Data_Get_Struct(self, Proj, proj);
  crs = proj_get_source_crs(PJ_DEFAULT_CTX, proj->ref);

  if ( ! crs ) {
    return Qnil;
  }

  return rb_crs_new(crs);
}

#target_crsPROJ?

Returns target CRS as PROJ::CRS object.

Returns:



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'ext/rb_proj.c', line 224

static VALUE
rb_proj_target_crs (VALUE self)
{
  Proj *proj;
  PJ *crs;

  Data_Get_Struct(self, Proj, proj);
  crs = proj_get_target_crs(PJ_DEFAULT_CTX, proj->ref);

  if ( ! crs ) {
    return Qnil;
  }
  
  return rb_crs_new(crs);
}

#transform_forward(x1, y1, z1 = nil) ⇒ Object Also known as: transform_forward

Transforms coordinates forwardly from (x1, y1, z1) to (x1, y2, z2). The order of coordinates arguments are according to source and target CRSs.

Examples:

x2, y2 = pj.transform(x1, y1)
x2, y2, z2 = pj.transform(x1, y1, z1)

Parameters:

  • x1 (Numeric)
  • y1 (Numeric)
  • z1 (Numeric, nil) (defaults to: nil)

Returns:

  • x2, y2[, z2] (Numeric)



657
658
659
660
661
# File 'ext/rb_proj.c', line 657

static VALUE
rb_proj_transform_forward (int argc, VALUE *argv, VALUE self)
{
  return rb_proj_transform_i(argc, argv, self, PJ_FWD);
}

#transform_inverse(x1, y1, z1 = nil) ⇒ Object

Transforms coordinates inversely from (x1, y1, z1) to (x1, y2, z2). The order of coordinates arguments are according to source and target CRSs.

Examples:

x2, y2 = pj.transform_inverse(x1, y1)
x2, y2, z2 = pj.transform_inverse(x1, y1, z1)

Parameters:

  • x1 (Numeric)
  • y1 (Numeric)
  • z1 (Numeric) (defaults to: nil)

Returns:

  • x2, y2[, z2] (Numeric)



678
679
680
681
682
# File 'ext/rb_proj.c', line 678

static VALUE
rb_proj_transform_inverse (int argc, VALUE *argv, VALUE self)
{
  return rb_proj_transform_i(argc, argv, self, PJ_INV);
}