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_parametersArray

Gets a ellipsoid parameters of CRS definition of the object.

Returns:

  • (Array)

    Returns Array containing semi_major_axis(m), semi_minor(m), boolean whether the semi-minor value was computed, inverse flattening.



915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
# File 'ext/rb_proj.c', line 915

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)


791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'ext/rb_proj.c', line 791

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)


821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
# File 'ext/rb_proj.c', line 821

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



749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'ext/rb_proj.c', line 749

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)


772
773
774
775
776
777
778
779
780
# File 'ext/rb_proj.c', line 772

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)


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

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)


850
851
852
853
854
855
856
857
858
859
860
861
862
# File 'ext/rb_proj.c', line 850

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)


875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
# File 'ext/rb_proj.c', line 875

static VALUE
rb_proj_as_projjson (int argc, VALUE *argv, VALUE self)
{
  Proj *proj;
	volatile VALUE vopts;
  const char *options[4] = {NULL, NULL, NULL, NULL};
  const char *json = NULL;
	int i;

  Data_Get_Struct(self, Proj, proj);

	if ( argc == 0 ) {
    json = proj_as_projjson(PJ_DEFAULT_CTX, proj->ref, NULL);		
	}
	if ( argc > 3 ) {
		rb_raise(rb_eRuntimeError, "too much options");
	}
	else {
		for (i=0; i<argc; i++) {
	    Check_Type(argv[i], T_STRING);			
			options[i] = StringValuePtr(argv[i]);
		}
    json = proj_as_projjson(PJ_DEFAULT_CTX, proj->ref, options);				
	}

  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)


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

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)

    Returns String of WKT expression.



938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
# File 'ext/rb_proj.c', line 938

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



132
133
134
# File 'lib/simple-proj.rb', line 132

def to_wkt2_2015
  return to_wkt(WKT2_2015)
end

#to_wkt2_2015_simplifiedObject



136
137
138
# File 'lib/simple-proj.rb', line 136

def to_wkt2_2015_simplified
  return to_wkt(WKT2_2015_SIMPLIFIED)
end

#to_wkt2_2018Object



140
141
142
# File 'lib/simple-proj.rb', line 140

def to_wkt2_2018
  return to_wkt(WKT2_2018)
end

#to_wkt2_2018_simplifiedObject



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

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



156
157
158
# File 'lib/simple-proj.rb', line 156

def to_wkt_esri
  return to_wkt(WKT1_ESRI)
end

#to_wkt_gdalObject



152
153
154
# File 'lib/simple-proj.rb', line 152

def to_wkt_gdal
  return to_wkt(WKT1_GDAL)
end