Class: RGeo::CoordSys::CS::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rgeo/coord_sys/cs/entities.rb

Overview

This is a base class for all OGC coordinate system objects. This includes both interfaces and data types from the OGC Coordinate Transformation spec.

This is a non-instantiable abstract class.

Instance Method Summary collapse

Instance Method Details

#_to_wkt(open_, close_) ⇒ Object

:nodoc:


226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 226

def _to_wkt(open_, close_)  # :nodoc:
  content_ = _wkt_content(open_, close_).map{ |obj_| ",#{obj_}" }.join
  if defined?(@authority) && @authority
    authority_ = ",AUTHORITY#{open_}#{@authority.inspect},#{@authority_code.inspect}#{close_}"
  else
    authority_ = ''
  end
  if defined?(@extensions) && @extensions
    extensions_ = @extensions.map{ |k_, v_| ",EXTENSION#{open_}#{k_.inspect},#{v_.inspect}#{close_}" }.join
  else
    extensions_ = ''
  end
  "#{_wkt_typename}#{open_}#{@name.inspect}#{content_}#{extensions_}#{authority_}#{close_}"
end

#encode_with(coder_) ⇒ Object

Psych support


263
264
265
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 263

def encode_with(coder_)  # :nodoc:
  coder_['wkt'] = to_wkt
end

#eql?(rhs_) ⇒ Boolean Also known as: ==

Tests for equality. Two objects are defined as equal if they have the same type (class) and the same WKT representation.


191
192
193
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 191

def eql?(rhs_)
  rhs_.class == self.class && rhs_.to_wkt == self.to_wkt
end

#hashObject

Standard hash code


199
200
201
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 199

def hash
  @hash ||= self.to_wkt.hash
end

#init_with(coder_) ⇒ Object

:nodoc:


267
268
269
270
271
272
273
274
275
276
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 267

def init_with(coder_)  # :nodoc:
  temp_ = CS.create_from_wkt(coder_.type == :scalar ? coder_.scalar : coder_['wkt'] )
  if temp_.class == self.class
    temp_.instance_variables.each do |iv_|
      instance_variable_set(iv_, temp_.instance_variable_get(iv_))
    end
  else
    raise ::TypeError, 'Bad YAML data'
  end
end

#inspectObject

Standard object inspection output


183
184
185
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 183

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} #{to_wkt}>"
end

#marshal_dumpObject

Marshal support


244
245
246
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 244

def marshal_dump  # :nodoc:
  to_wkt
end

#marshal_load(data_) ⇒ Object

:nodoc:


248
249
250
251
252
253
254
255
256
257
258
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 248

def marshal_load(data_)  # :nodoc:
  data_ = data_['wkt'] if data_.is_a?(::Hash)
  temp_ = CS.create_from_wkt(data_)
  if temp_.class == self.class
    temp_.instance_variables.each do |iv_|
      instance_variable_set(iv_, temp_.instance_variable_get(iv_))
    end
  else
    raise ::TypeError, 'Bad Marshal data'
  end
end

#to_sObject

Returns the default WKT representation.


206
207
208
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 206

def to_s
  to_wkt
end

#to_wkt(opts_ = {}) ⇒ Object

Computes the WKT representation. Options include:

:standard_brackets

If set to true, outputs parentheses rather than square brackets. Default is false.


217
218
219
220
221
222
223
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 217

def to_wkt(opts_={})
  if opts_[:standard_brackets]
    @standard_wkt ||= _to_wkt('(', ')')
  else
    @square_wkt ||= _to_wkt('[', ']')
  end
end