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



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

def encode_with(coder) # :nodoc:
  coder["wkt"] = to_wkt
end

#eql?(other) ⇒ 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)


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

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

#hashObject

Standard hash code



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

def hash
  @hash ||= to_wkt.hash
end

#init_with(coder) ⇒ Object

:nodoc:

Raises:

  • (TypeError)


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

def init_with(coder) # :nodoc:
  temp = CS.create_from_wkt(coder.type == :scalar ? coder.scalar : coder["wkt"])

  raise TypeError, "Bad YAML data" unless temp.instance_of?(self.class)

  temp.instance_variables.each do |iv|
    instance_variable_set(iv, temp.instance_variable_get(iv))
  end
end

#inspectObject

Standard object inspection output



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

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

#marshal_dumpObject

Marshal support



202
203
204
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 202

def marshal_dump # :nodoc:
  to_wkt
end

#marshal_load(data) ⇒ Object

:nodoc:

Raises:

  • (TypeError)


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

def marshal_load(data) # :nodoc:
  data = data["wkt"] if data.is_a?(Hash)
  temp = CS.create_from_wkt(data)

  raise TypeError, "Bad Marshal data" unless temp.instance_of?(self.class)

  temp.instance_variables.each do |iv|
    instance_variable_set(iv, temp.instance_variable_get(iv))
  end
end

#to_sObject

Returns the default WKT representation.



173
174
175
# File 'lib/rgeo/coord_sys/cs/entities.rb', line 173

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.


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

def to_wkt(standard_brackets: false)
  open, close = brackets(standard_brackets)
  content = wkt_content(standard_brackets).map { |obj| ",#{obj}" }.join
  authority =
    if defined?(@authority) && @authority
      ",AUTHORITY#{open}#{@authority.inspect},#{@authority_code.inspect}#{close}"
    else
      ""
    end
  extensions =
    if defined?(@extensions) && @extensions
      @extensions.map { |k, v| ",EXTENSION#{open}#{k.inspect},#{v.inspect}#{close}" }.join
    else
      ""
    end
  "#{wkt_typename}#{open}#{@name.inspect}#{content}#{extensions}#{authority}#{close}"
end