mapbox / mapbox/mapbox-scenekit

metersToDegreesForLat paremeter must be a latitude instead of the longitude

Open
#91 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
232
Forks
50
PR merge metrics
No merged PRs in 30d

Description

Compare this from Understanding terms in Length of Degree formula?:

  m1 = 111132.95255
  m2 = -559.84957
  m3 = 1.17514
  m4 = -0.00230
  p1 = 111412.87733
  p2 = -93.50412
  p3 = 0.11774
  p4 = -0.000165
m.per.deg <- function(lat) {
  m1 = 111132.92;     # latitude calculation term 1
  m2 = -559.82;       # latitude calculation term 2
  m3 = 1.175;         # latitude calculation term 3
  m4 = -0.0023;       # latitude calculation term 4
  p1 = 111412.84;     # longitude calculation term 1
  p2 = -93.5;         # longitude calculation term 2
  p3 = 0.118;         # longitude calculation term 3

  m1 = 111132.95255
  m2 = -559.84957
  m3 = 1.17514
  m4 = -0.00230
  p1 = 111412.87733
  p2 = -93.50412
  p3 = 0.11774
  p4 = -0.000165

  latlen = m1 + m2 * cos(2 * lat) + m3 * cos(4 * lat) + m4 * cos(6 * lat);
  longlen = p1 * cos(lat) + p2 * cos(3 * lat) + p3 * cos(5 * lat);
  return(cbind(M.approx=latlen, r.approx=longlen))
}

with this:

    static func metersToDegreesForLat(atLongitude longitude: CLLocationDegrees) -> CLLocationDistance {
        let a = cos(2 * Math.degreesToRadians(longitude))
        let b = cos(4 * Math.degreesToRadians(longitude))
        let c = cos(6 * Math.degreesToRadians(longitude))
        
        return 1.0 / fabs(111132.95255 - 559.84957 * a + 1.17514 * b - 0.00230 * c)
    }

    static func metersToDegreesForLon(atLatitude latitude: CLLocationDegrees) -> CLLocationDistance {
        let a = cos(Math.degreesToRadians(latitude))
        let b = cos(3 * Math.degreesToRadians(latitude))
        let c = cos(5 * Math.degreesToRadians(latitude))
        
        return 1.0 / fabs(111412.87733 * a - 93.50412 * b + 0.11774 * c)
    }

You can also look at the Geographic coordinate system wiki article:

On the WGS 84 spheroid, the length in meters of a degree of latitude at latitude ϕ (that is, the number of meters you would have to travel along a north–south line to move 1 degree in latitude, when at latitude ϕ), is about:

$111132.92 - 559.82\, \cos 2\phi + 1.175\, \cos 4\phi - 0.0023\, \cos 6\phi$

The returned measure of meters per degree latitude varies continuously with latitude.
Similarly, the length in meters of a degree of longitude can be calculated as

$111412.84\, \cos \phi - 93.5\, \cos 3\phi + 0.118\, \cos 5\phi$

(Those coefficients can be improved, but as they stand the distance they give is correct within a centimeter.)
The formulae both return units of meters per degree.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the two entry points shown in the issue, metersToDegreesForLat and metersToDegreesForLon, and compare their parameter labels with the latitude and longitude formulas cited. Done means the latitude calculation receives latitude, the longitude calculation receives longitude, and both continue returning meters-per-degree conversions.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.