struct

Geo::Coord

Inherits Comparable / Struct / Value / Object

A Coord is a point in geographical coordinates: latitude and longitude.

Constants

DIRECTIVES = {/%(#{FLOATUFLAGS})?lats/ => ->(m : Regex::MatchData) do "%<lats>#{m[1]? || "0."}f" end, "%latm" => "%<latm>i", /%(#{INTFLAGS})?latds/ => ->(m : Regex::MatchData) do "%<latds>#{m[1]}i" end, "%latd" => "%<latd>i", "%lath" => "%<lath>s", /%(#{FLOATFLAGS})?lat/ => ->(m : Regex::MatchData) do "%<lat>#{m[1]}f" end, /%(#{FLOATUFLAGS})?lngs/ => ->(m : Regex::MatchData) do "%<lngs>#{m[1]? || "0."}f" end, "%lngm" => "%<lngm>i", /%(#{INTFLAGS})?lngds/ => ->(m : Regex::MatchData) do "%<lngds>#{m[1]}i" end, "%lngd" => "%<lngd>i", "%lngh" => "%<lngh>s", /%(#{FLOATFLAGS})?lng/ => ->(m : Regex::MatchData) do "%<lng>#{m[1]}f" end}
FLOATFLAGS = /\+?#{FLOATUFLAGS}?/
FLOATUFLAGS = /0\.\d+/
INTFLAGS = /\+?/

Constructors

new(lat : Number, lng : Number)
Source

Instance methods

<=>(other : Geo::Coord)

The comparison operator. Returns 0 if the two objects are equal, a negative number if this object is considered less than other, a positive number if this object is considered greater than other, or nil if the two objects are not comparable.

Subclasses define this method to provide class-specific ordering.

The comparison operator is usually used to sort values:

# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]

# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]
Source
astronomical_dawn(date : Time, location : Time::Location | Nil = nil) : Time
Source
astronomical_dawn?(date : Time, location : Time::Location | Nil = nil) : Time | Nil
Source
astronomical_dusk(date : Time, location : Time::Location | Nil = nil) : Time
Source
astronomical_dusk?(date : Time, location : Time::Location | Nil = nil) : Time | Nil
Source
bearing(to : Geo::Coord, final = false) : Float64

Calculates initial and final bearings between two points using great-circle distance formulas

Source
between?(p1 : Geo::Coord, p2 : Geo::Coord)
Source
civil_dawn(date : Time, location : Time::Location | Nil = nil) : Time
Source
civil_dawn?(date : Time, location : Time::Location | Nil = nil) : Time | Nil
Source
civil_dusk(date : Time, location : Time::Location | Nil = nil) : Time
Source
civil_dusk?(date : Time, location : Time::Location | Nil = nil) : Time | Nil
Source
daylight_length(date : Time, location : Time::Location | Nil = nil) : Time::Span
Source
destination(distance : Number, bearing : Number, unit : Symbol = :kilometers) : Geo::Coord

Calculates the location of a destination point

Source
distance(other : Geo::Coord) : Haversine::Distance

Calculates distance to other. Haversine formula is used.

Source
geohash(precision = 12)

Returns a geohash representing coordinates.

Source
latd

Returns latitude degrees

Source
latds
Source
lath

Returns latitude hemisphere

Source
latm

Returns latitude minutes

Source
lats

Returns latitude seconds

Source
lngd

Returns longitude degrees

Source
lngds
Source
lngh

Returns longitude hemisphere

Source
lngm

Returns longitude minutes

Source
lngs

Returns longitude seconds

Source
nautical_dawn(date : Time, location : Time::Location | Nil = nil) : Time
Source
nautical_dawn?(date : Time, location : Time::Location | Nil = nil) : Time | Nil
Source
nautical_dusk(date : Time, location : Time::Location | Nil = nil) : Time
Source
nautical_dusk?(date : Time, location : Time::Location | Nil = nil) : Time | Nil
Source
solar_noon(date : Time, location : Time::Location | Nil = nil) : Time
Source
strfcoord(formatstr) : String

Formats coordinates according to directives in formatstr.

Each directive starts with % and can contain some modifiers before its name.

Acceptable modifiers:

  • unsigned integers: none;
  • signed integers: + for mandatory sign printing;
  • floats: same as integers and number of digits modifier, like 0.3.

List of directives:

  • %lat - Full latitude, floating point, signed
  • %latds - Latitude degrees, integer, signed
  • %latd - Latitude degrees, integer, unsigned
  • %latm - Latitude minutes, integer, unsigned
  • %lats - Latitude seconds, floating point, unsigned
  • %lath - Latitude hemisphere, "N" or "S"
  • %lng - Full longitude, floating point, signed
  • %lngds - Longitude degrees, integer, signed
  • %lngd - Longitude degrees, integer, unsigned
  • %lngm - Longitude minutes, integer, unsigned
  • lngs - Longitude seconds, floating point, unsigned
  • `%lngh`` - Longitude hemisphere, "E" or "W"

Examples:

g = Geo::Coord.new(50.004444, 36.231389)
g.strfcoord('%+lat, %+lng')
# => "+50.004444, +36.231389"
g.strfcoord("%latd°%latm'%lath -- %lngd°%lngm'%lngh")
# => "50°0'N -- 36°13'E"

strfcoord handles seconds rounding implicitly:

pos = Geo::Coord.new(0.033333, 91.333333)
pos.strfcoord('%latd %latm %0.5lats') # => "0 1 59.99880"
pos.strfcoord('%latd %latm %lats')  # => "0 2 0"
Source
sun_events(date : Time, location : Time::Location | Nil = nil)
Source
sun_times
Source
sunrise(date : Time, location : Time::Location | Nil = nil) : Time
Source
sunrise?(date : Time, location : Time::Location | Nil = nil) : Time | Nil
Source
sunset(date : Time, location : Time::Location | Nil = nil) : Time
Source
sunset?(date : Time, location : Time::Location | Nil = nil) : Time | Nil
Source
to_ewkb(bytes : Bytes = Bytes.new(23), byte_format : IO::ByteFormat = IO::ByteFormat::BigEndian) : Bytes
Source
to_ewkt(io : IO, output_type = true, output_parentheses = true) : Nil
Source
to_ewkt
Source
to_geojson
Source
to_s(io)

Returns a string representing coordinates.

g.to_s             # => "50°0'16\"N 36°13'53\"E"
g.to_s(dms: false) # => "50.004444,36.231389"
Source
to_wkb(bytes : Bytes = Bytes.new(21), byte_format : IO::ByteFormat = IO::ByteFormat::BigEndian) : Bytes
Source
to_wkt(io : IO, output_type = true, output_parentheses = true) : Nil
Source
to_wkt
Source

Nested types