Module: PROJ::Common

Included in:
PROJ, CRS
Defined in:
lib/simple-proj.rb,
ext/rb_proj.c

Instance Method Summary collapse

Instance Method Details

#ellipsoid_parametersObject



728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
# File 'ext/rb_proj.c', line 728

static VALUE
rb_proj_ellipsoid_get_parameters (VALUE self)
{
  Proj *proj;
  PJ *ellps;
  double a, b, invf;
  int computed;

  Data_Get_Struct(self, Proj, proj);
  ellps = proj_get_ellipsoid(PJ_DEFAULT_CTX, proj->ref);
  proj_ellipsoid_get_parameters(PJ_DEFAULT_CTX, ellps, &a, &b, &computed, &invf);
  return rb_ary_new3(4,
                     rb_float_new(a),
                     rb_float_new(b),
                     INT2NUM(computed),
                     rb_float_new(invf));
}

#id_auth_name(index = nil) ⇒ String?

Gets the authority name / codespace of an identifier of the object.

Parameters:

  • index (Integer) (defaults to: nil)

    index of the identifier (0 = first identifier)

Returns:

  • (String, nil)


633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# File 'ext/rb_proj.c', line 633

static VALUE
rb_proj_get_id_auth_name (int argc, VALUE *argv, VALUE self)
{
  volatile VALUE vidx;
  Proj *proj;
  const char *string;

  rb_scan_args(argc, argv, "01", (VALUE *)&vidx);

  Data_Get_Struct(self, Proj, proj);

  if ( NIL_P(vidx) ) {
    string = proj_get_id_auth_name(proj->ref, 0);
  }
  else {
    string = proj_get_id_auth_name(proj->ref, NUM2INT(vidx));
  }

  return (string) ? rb_str_new2(string) : Qnil;
}

#id_code(index = nil) ⇒ String?

Gets the code of an identifier of the object.

Parameters:

  • index (Integer) (defaults to: nil)

    index of the identifier (0 = first identifier)

Returns:

  • (String, nil)


663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'ext/rb_proj.c', line 663

static VALUE
rb_proj_get_id_code (int argc, VALUE *argv, VALUE self)
{
  volatile VALUE vidx;
  Proj *proj;
  const char *string;

  rb_scan_args(argc, argv, "01", (VALUE *)&vidx);

  Data_Get_Struct(self, Proj, proj);

  if ( NIL_P(vidx) ) {
    string = proj_get_id_code(proj->ref, 0);    
  }
  else {
    string = proj_get_id_code(proj->ref, NUM2INT(vidx));        
  }

  return (string) ? rb_str_new2(string) : Qnil;
}

#initialize_copyObject



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'ext/rb_proj.c', line 591

static VALUE
rb_proj_initialize_copy (VALUE self, VALUE obj)
{
  Proj *proj, *other;

  Data_Get_Struct(self, Proj, proj);

  if ( rb_obj_is_kind_of(obj, rb_cProj) || rb_obj_is_kind_of(obj, rb_cCrs) ) {
    Data_Get_Struct(obj, Proj, other);
    proj->ref = proj_clone(PJ_DEFAULT_CTX, other->ref);    
  }
  else {
    rb_raise(rb_eArgError, "invalid class of argument object");
  }

  return self;
}

#nameString

Gets the name of the object.

Returns:

  • (String)


614
615
616
617
618
619
620
621
622
# File 'ext/rb_proj.c', line 614

static VALUE
rb_proj_get_name (VALUE self)
{
  Proj *proj;

  Data_Get_Struct(self, Proj, proj);

  return rb_str_new2(proj_get_name(proj->ref));  
}

#to_epsg_codeString?

Gets a EPSG code of the object

Returns:

  • (String, nil)


108
109
110
111
112
113
114
115
116
# File 'lib/simple-proj.rb', line 108

def to_epsg_code
  auth = id_auth_name
  code = id_code
  if auth and code
    return auth + ":" + code
  else
    return nil
  end
end

#to_proj_stringString?

Gets a PROJ string representation of the object. This method may return nil if the object is not compatible with an export to the requested type.

Returns:

  • (String, nil)


714
715
716
717
718
719
720
721
722
723
724
725
726
# File 'ext/rb_proj.c', line 714

static VALUE
rb_proj_as_proj_string (VALUE self)
{
  Proj *proj;
  const char *string;

  Data_Get_Struct(self, Proj, proj);
  string = proj_as_proj_string(PJ_DEFAULT_CTX, proj->ref, PJ_PROJ_5, NULL);
  if ( ! string ) {
    return Qnil;
  }
  return rb_str_new2(string);
}

#to_projjsonString?

Gets a PROJJSON string representation of the object.

This method may return nil if the object is not compatible with an export to the requested type.

Returns:

  • (String, nil)


692
693
694
695
696
697
698
699
700
701
702
703
704
# File 'ext/rb_proj.c', line 692

static VALUE
rb_proj_as_projjson (VALUE self)
{
  Proj *proj;
  const char *json;

  Data_Get_Struct(self, Proj, proj);
  json = proj_as_projjson(PJ_DEFAULT_CTX, proj->ref, NULL);
  if ( ! json ) {
    return Qnil;
  }
  return rb_str_new2(json);
}

#to_projjson_as_hashHash?

Gets a Hash object parsed from the PROJJSON expression of the object

Returns:

  • (Hash, nil)


121
122
123
124
125
126
127
128
# File 'lib/simple-proj.rb', line 121

def to_projjson_as_hash
  json = to_projjson
  if json
    return JSON.parse(json)
  else
    return nil
  end      
end

#to_wktString

Gets a WKT expression of CRS definition of the object.

Returns:

  • (String)


751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'ext/rb_proj.c', line 751

static VALUE
rb_proj_as_wkt (int argc, VALUE *argv, VALUE self)
{
  volatile VALUE vidx;
  Proj *proj;
  const char *wkt;

  rb_scan_args(argc, argv, "01", (VALUE *)&vidx);

  Data_Get_Struct(self, Proj, proj);

  if ( NIL_P(vidx) ) {
    wkt = proj_as_wkt(PJ_DEFAULT_CTX, proj->ref, PJ_WKT2_2018, NULL);    
  }
  else {
    wkt = proj_as_wkt(PJ_DEFAULT_CTX, proj->ref, NUM2INT(vidx), NULL);        
  }

  if ( ! wkt ) {
    return Qnil;
  }
  else {
    return rb_str_new2(wkt);    
  }
}

#to_wkt2_2015Object



130
131
132
# File 'lib/simple-proj.rb', line 130

def to_wkt2_2015
  return to_wkt(WKT2_2015)
end

#to_wkt2_2015_simplifiedObject



134
135
136
# File 'lib/simple-proj.rb', line 134

def to_wkt2_2015_simplified
  return to_wkt(WKT2_2015_SIMPLIFIED)
end

#to_wkt2_2018Object



138
139
140
# File 'lib/simple-proj.rb', line 138

def to_wkt2_2018
  return to_wkt(WKT2_2018)
end

#to_wkt2_2018_simplifiedObject



142
143
144
145
146
147
148
# File 'lib/simple-proj.rb', line 142

def to_wkt2_2018_simplified
  if defined? WKT2_2018_SIMPLIFIED
    return to_wkt(WKT2_2018_SIMPLIFIED)
  else
    raise "WKT2_2018 not defined. Check PROJ version."
  end
end

#to_wkt_esriObject



154
155
156
# File 'lib/simple-proj.rb', line 154

def to_wkt_esri
  return to_wkt(WKT1_ESRI)
end

#to_wkt_gdalObject



150
151
152
# File 'lib/simple-proj.rb', line 150

def to_wkt_gdal
  return to_wkt(WKT1_GDAL)
end