Class: CocinaDisplay::Geospatial::Point

Inherits:
Coordinates show all
Defined in:
lib/cocina_display/geospatial.rb

Overview

A single geospatial point with latitude and longitude.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Coordinates

from_cocina, from_structured_values, parse

Constructor Details

#initialize(point) ⇒ Point

Construct a Point from a single Geo::Coord point.

Parameters:

  • point (Geo::Coord)


104
105
106
# File 'lib/cocina_display/geospatial.rb', line 104

def initialize(point)
  @point = point
end

Instance Attribute Details

#pointObject (readonly)

Returns the value of attribute point.



89
90
91
# File 'lib/cocina_display/geospatial.rb', line 89

def point
  @point
end

Class Method Details

.from_coords(lat:, lng:) ⇒ Point?

Construct a Point from latitude and longitude string values.

Parameters:

  • lat (String)

    latitude

  • lng (String)

    longitude

Returns:

  • (Point, nil)

    nil if parsing fails



95
96
97
98
99
100
# File 'lib/cocina_display/geospatial.rb', line 95

def self.from_coords(lat:, lng:)
  point = Geo::Coord.parse("#{lat}, #{lng}")
  return unless point

  new(point)
end

Instance Method Details

#as_envelopenil

Note:

This is impossible for a single point; we always return nil.

Format using the CQL ENVELOPE representation.

Returns:

  • (nil)


129
130
131
# File 'lib/cocina_display/geospatial.rb', line 129

def as_envelope
  nil
end

#as_pointString

Note:

Limits decimals to 6 places.

Format as a comma-separated latitude,longitude pair.

Examples:

“34.0522,-118.2437”

Returns:

  • (String)


137
138
139
# File 'lib/cocina_display/geospatial.rb', line 137

def as_point
  "%.6f,%.6f" % [point.lat, point.lng]
end

#as_wktString

Note:

Limits decimals to 6 places.

Format using the Well-Known Text (WKT) representation.

Examples:

“POINT(34.0522 -118.2437)”

Returns:

  • (String)

See Also:



122
123
124
# File 'lib/cocina_display/geospatial.rb', line 122

def as_wkt
  "POINT(%.6f %.6f)" % [point.lat, point.lng]
end

#to_sString

Note:

This format adapts the “Annex D” human representation style.

Format for display in DMS format, adapted from ISO 6709 standard.

Examples:

“34°03′08″N 118°14′37″W”

Returns:

  • (String)

See Also:



113
114
115
# File 'lib/cocina_display/geospatial.rb', line 113

def to_s
  format_point(point).join(" ")
end