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:



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 182

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



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

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.

Returns:

  • (Boolean)


151
152
153
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 151

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

#hashObject

Standard hash code



158
159
160
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 158

def hash
  @hash ||= to_wkt.hash
end

#init_with(coder_) ⇒ Object

:nodoc:



221
222
223
224
225
226
227
228
229
230
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 221

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



144
145
146
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 144

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

#marshal_dumpObject

Marshal support



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

def marshal_dump # :nodoc:
  to_wkt
end

#marshal_load(data_) ⇒ Object

:nodoc:



203
204
205
206
207
208
209
210
211
212
213
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 203

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.



164
165
166
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 164

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.



174
175
176
177
178
179
180
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 174

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