Method: PROJ#inverse
- Defined in:
- ext/rb_proj.c
#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’.
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));
}
}
}
|