Class: RGeo::CoordSys::CRSToCRS

Inherits:
Object
  • Object
show all
Defined in:
lib/rgeo/coord_sys/crs_to_crs.rb,
ext/proj4_c_impl/main.c

Overview

This is a Ruby wrapper around a proj crs_to_crs A crs_to_crs transformation object is a pipeline between two known coordinate reference systems. proj.org/development/reference/functions.html#c.proj_create_crs_to_crs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._create(from, to) ⇒ Object



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'ext/proj4_c_impl/main.c', line 388

static VALUE cmethod_crs_to_crs_create(VALUE klass, VALUE from, VALUE to)
{
  VALUE result;
  RGeo_Proj4Data *from_data;
  RGeo_Proj4Data *to_data;
  result = Qnil;
  PJ *from_pj;
  PJ *to_pj;
  PJ *gis_pj;
  PJ *crs_to_crs;
  RGeo_CRSToCRSData* data;

  TypedData_Get_Struct(from, RGeo_Proj4Data, &rgeo_proj4_data_type, from_data);
  TypedData_Get_Struct(to, RGeo_Proj4Data, &rgeo_proj4_data_type, to_data);
  from_pj = from_data->pj;
  to_pj = to_data->pj;
  crs_to_crs = proj_create_crs_to_crs_from_pj(PJ_DEFAULT_CTX, from_pj, to_pj, 0, NULL);

  // necessary to use proj_normalize_for_visualization so that we
  // do not have to worry about the order of coordinates in every
  // coord system
  gis_pj = proj_normalize_for_visualization(PJ_DEFAULT_CTX, crs_to_crs);
  if(gis_pj){
    proj_destroy(crs_to_crs);
    crs_to_crs = gis_pj;
  }
  data = ALLOC(RGeo_CRSToCRSData);
  if (data){
    data->crs_to_crs = crs_to_crs;
    result = TypedData_Wrap_Struct(klass, &rgeo_crs_to_crs_data_type, data);
  }
  return result;
}

.create(from, to) ⇒ Object



16
17
18
# File 'lib/rgeo/coord_sys/crs_to_crs.rb', line 16

def create(from, to)
  _create(from, to)
end

Instance Method Details

#_transform_coords(x, y, z) ⇒ Object



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
# File 'ext/proj4_c_impl/main.c', line 423

static VALUE method_crs_to_crs_transform(VALUE self, VALUE x, VALUE y, VALUE z)
{
  VALUE result;
  RGeo_CRSToCRSData *crs_to_crs_data;
  PJ *crs_to_crs_pj;
  double xval, yval, zval;
  PJ_COORD input;
  PJ_COORD output;

  result = Qnil;
  TypedData_Get_Struct(self, RGeo_CRSToCRSData, &rgeo_crs_to_crs_data_type, crs_to_crs_data);
  crs_to_crs_pj = crs_to_crs_data->crs_to_crs;
  if(crs_to_crs_pj){
    xval = rb_num2dbl(x);
    yval = rb_num2dbl(y);
    zval = NIL_P(z) ? 0.0 : rb_num2dbl(z);

    input = proj_coord(xval, yval, zval, HUGE_VAL);
    output = proj_trans(crs_to_crs_pj, PJ_FWD, input);

    result = rb_ary_new2(NIL_P(z) ? 2 : 3);
    rb_ary_push(result, DBL2NUM(output.xyz.x));
    rb_ary_push(result, DBL2NUM(output.xyz.y));
    if(!NIL_P(z)){
      rb_ary_push(result, DBL2NUM(output.xyz.z));
    }
  }
  return result;
}

#transform_coords(x, y, z) ⇒ Object

transform the coordinates from the initial CRS to the destination CRS



11
12
13
# File 'lib/rgeo/coord_sys/crs_to_crs.rb', line 11

def transform_coords(x, y, z)
  _transform_coords(x, y, z)
end