static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig) { RGeo_Proj4Data* self_data; projPJ pj; RGeo_Proj4Data* orig_data; char* str; // Clear out any existing value self_data = RGEO_PROJ4_DATA_PTR(self); pj = self_data->pj; if (pj) { pj_free(pj); self_data->pj = NULL; self_data->original_str = Qnil; } // Copy value from orig orig_data = RGEO_PROJ4_DATA_PTR(orig); if (!NIL_P(orig_data->original_str)) { self_data->pj = pj_init_plus(RSTRING_PTR(orig_data->original_str)); } else { str = pj_get_def(orig_data->pj, 0); self_data->pj = pj_init_plus(str); pj_dalloc(str); } self_data->original_str = orig_data->original_str; self_data->uses_radians = orig_data->uses_radians; return self; }
static VALUE cmethod_proj4_transform(VALUE module, VALUE from, VALUE to, VALUE x, VALUE y, VALUE z) { VALUE result; projPJ from_pj; projPJ to_pj; double xval, yval, zval; int err; result = Qnil; from_pj = RGEO_PROJ4_DATA_PTR(from)->pj; to_pj = RGEO_PROJ4_DATA_PTR(to)->pj; if (from_pj && to_pj) { xval = rb_num2dbl(x); yval = rb_num2dbl(y); zval = 0.0; if (!NIL_P(z)) { zval = rb_num2dbl(z); } err = pj_transform(from_pj, to_pj, 1, 1, &xval, &yval, NIL_P(z) ? NULL : &zval); if (!err && xval != HUGE_VAL && yval != HUGE_VAL && (NIL_P(z) || zval != HUGE_VAL)) { result = rb_ary_new2(NIL_P(z) ? 2 : 3); rb_ary_push(result, rb_float_new(xval)); rb_ary_push(result, rb_float_new(yval)); if (!NIL_P(z)) { rb_ary_push(result, rb_float_new(zval)); } } } return result; }
static VALUE method_proj4_is_geocentric(VALUE self) { VALUE result = Qnil; projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj; if (pj) { result = pj_is_geocent(pj) ? Qtrue : Qfalse; } return result; }
static VALUE method_proj4_canonical_str(VALUE self) { VALUE result = Qnil; projPJ pj = RGEO_PROJ4_DATA_PTR(self)->pj; if (pj) { char* str = pj_get_def(pj, 0); if (str) { result = rb_str_new2(str); pj_dalloc(str); } } return result; }
static VALUE method_proj4_get_geographic(VALUE self) { VALUE result = Qnil; RGeo_Proj4Data* new_data = ALLOC(RGeo_Proj4Data); if (new_data) { RGeo_Proj4Data* self_data = RGEO_PROJ4_DATA_PTR(self); new_data->pj = pj_latlong_from_proj(self_data->pj); new_data->original_str = Qnil; new_data->uses_radians = self_data->uses_radians; result = Data_Wrap_Struct(CLASS_OF(self), mark_proj4_func, destroy_proj4_func, new_data); } return result; }
static VALUE method_proj4_set_value(VALUE self, VALUE str, VALUE uses_radians) { Check_Type(str, T_STRING); // Clear out any existing value RGeo_Proj4Data* self_data = RGEO_PROJ4_DATA_PTR(self); projPJ pj = self_data->pj; if (pj) { pj_free(pj); self_data->pj = NULL; self_data->original_str = Qnil; } // Set new data self_data->pj = pj_init_plus(RSTRING_PTR(str)); self_data->original_str = str; self_data->uses_radians = RTEST(uses_radians) ? 1 : 0; return self; }
static VALUE method_proj4_is_valid(VALUE self) { return RGEO_PROJ4_DATA_PTR(self)->pj ? Qtrue : Qfalse; }
static VALUE method_proj4_uses_radians(VALUE self) { return RGEO_PROJ4_DATA_PTR(self)->uses_radians ? Qtrue : Qfalse; }
static VALUE method_proj4_original_str(VALUE self) { return RGEO_PROJ4_DATA_PTR(self)->original_str; }