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

#encode_with(coder) ⇒ Object

Psych support


211
212
213
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 211

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)

153
154
155
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 153

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

#hashObject

Standard hash code


160
161
162
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 160

def hash
  @hash ||= to_wkt.hash
end

#init_with(coder) ⇒ Object

:nodoc:


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

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


146
147
148
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 146

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

#marshal_dumpObject

Marshal support


193
194
195
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 193

def marshal_dump # :nodoc:
  to_wkt
end

#marshal_load(data) ⇒ Object

:nodoc:


197
198
199
200
201
202
203
204
205
206
207
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 197

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.


166
167
168
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 166

def to_s
  to_wkt
end

#to_wkt(standard_brackets = false) ⇒ Object

Return the WKT representation.

:standard_brackets

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

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 175

def to_wkt(standard_brackets = false)
  open, close = brackets(standard_brackets)
  content = wkt_content(standard_brackets).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