Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect earth radius constants #9793

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/geo/geo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// constants
var TAU = 2 * Math.PI;
var EQUATORIAL_RADIUS = 6356752.314245179;
var POLAR_RADIUS = 6378137.0;
const EQUATORIAL_RADIUS = 6.3781370E6;
const POLAR_RADIUS = 6.3567523E6;


export function geoLatToMeters(dLat) {
Expand Down
4 changes: 2 additions & 2 deletions test/spec/actions/split.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,8 @@ describe('iD.actionSplit', function () {

graph = iD.actionSplit('b', ['~'])(graph);

expect(graph.entity('-').nodes).to.eql(['b', 'c']);
expect(graph.entity('~').nodes).to.eql(['a', 'b']);
expect(graph.entity('~').nodes).to.eql(['b', 'c']);
expect(graph.entity('-').nodes).to.eql(['a', 'b']);
expect(graph.entity('=').nodes).to.eql(['a', 'b', 'c', 'a']);
expect(graph.parentRelations(graph.entity('='))).to.have.length(0);
});
Expand Down
64 changes: 32 additions & 32 deletions test/spec/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ describe('iD.geo - geography', function() {
expect(iD.geoLatToMeters(0)).to.eql(0);
});
it('1 degree latitude is approx 111 km', function() {
expect(iD.geoLatToMeters(1)).to.be.closeTo(111319, 10);
expect(iD.geoLatToMeters(1)).to.be.closeTo(110946, 10);
});
it('-1 degree latitude is approx -111 km', function() {
expect(iD.geoLatToMeters(-1)).to.be.closeTo(-111319, 10);
expect(iD.geoLatToMeters(-1)).to.be.closeTo(-110946, 10);
});
});

Expand All @@ -17,21 +17,21 @@ describe('iD.geo - geography', function() {
expect(iD.geoLonToMeters(0, 0)).to.eql(0);
});
it('distance of 1 degree longitude varies with latitude', function() {
expect(iD.geoLonToMeters(1, 0)).to.be.closeTo(110946, 10);
expect(iD.geoLonToMeters(1, 15)).to.be.closeTo(107165, 10);
expect(iD.geoLonToMeters(1, 30)).to.be.closeTo(96082, 10);
expect(iD.geoLonToMeters(1, 45)).to.be.closeTo(78450, 10);
expect(iD.geoLonToMeters(1, 60)).to.be.closeTo(55473, 10);
expect(iD.geoLonToMeters(1, 75)).to.be.closeTo(28715, 10);
expect(iD.geoLonToMeters(1, 0)).to.be.closeTo(111319, 10);
expect(iD.geoLonToMeters(1, 15)).to.be.closeTo(107526, 10);
expect(iD.geoLonToMeters(1, 30)).to.be.closeTo(96405, 10);
expect(iD.geoLonToMeters(1, 45)).to.be.closeTo(78714, 10);
expect(iD.geoLonToMeters(1, 60)).to.be.closeTo(55659, 10);
expect(iD.geoLonToMeters(1, 75)).to.be.closeTo(28811, 10);
expect(iD.geoLonToMeters(1, 90)).to.eql(0);
});
it('distance of -1 degree longitude varies with latitude', function() {
expect(iD.geoLonToMeters(-1, -0)).to.be.closeTo(-110946, 10);
expect(iD.geoLonToMeters(-1, -15)).to.be.closeTo(-107165, 10);
expect(iD.geoLonToMeters(-1, -30)).to.be.closeTo(-96082, 10);
expect(iD.geoLonToMeters(-1, -45)).to.be.closeTo(-78450, 10);
expect(iD.geoLonToMeters(-1, -60)).to.be.closeTo(-55473, 10);
expect(iD.geoLonToMeters(-1, -75)).to.be.closeTo(-28715, 10);
expect(iD.geoLonToMeters(-1, -0)).to.be.closeTo(-111319, 10);
expect(iD.geoLonToMeters(-1, -15)).to.be.closeTo(-107526, 10);
expect(iD.geoLonToMeters(-1, -30)).to.be.closeTo(-96405, 10);
expect(iD.geoLonToMeters(-1, -45)).to.be.closeTo(-78714, 10);
expect(iD.geoLonToMeters(-1, -60)).to.be.closeTo(-55659, 10);
expect(iD.geoLonToMeters(-1, -75)).to.be.closeTo(-28811, 10);
expect(iD.geoLonToMeters(-1, -90)).to.eql(0);
});
});
Expand All @@ -41,10 +41,10 @@ describe('iD.geo - geography', function() {
expect(iD.geoMetersToLat(0)).to.eql(0);
});
it('111 km is approx 1 degree latitude', function() {
expect(iD.geoMetersToLat(111319)).to.be.closeTo(1, 0.0001);
expect(iD.geoMetersToLat(110946)).to.be.closeTo(1, 0.0001);
});
it('-111 km is approx -1 degree latitude', function() {
expect(iD.geoMetersToLat(-111319)).to.be.closeTo(-1, 0.0001);
expect(iD.geoMetersToLat(-110946)).to.be.closeTo(-1, 0.0001);
});
});

Expand All @@ -53,21 +53,21 @@ describe('iD.geo - geography', function() {
expect(iD.geoMetersToLon(0, 0)).to.eql(0);
});
it('distance of 1 degree longitude varies with latitude', function() {
expect(iD.geoMetersToLon(110946, 0)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(107165, 15)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(96082, 30)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(78450, 45)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(55473, 60)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(28715, 75)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(111319, 0)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(107526, 15)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(96405, 30)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(78714, 45)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(55659, 60)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(28811, 75)).to.be.closeTo(1, 1e-4);
expect(iD.geoMetersToLon(1, 90)).to.eql(0);
});
it('distance of -1 degree longitude varies with latitude', function() {
expect(iD.geoMetersToLon(-110946, -0)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-107165, -15)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-96082, -30)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-78450, -45)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-55473, -60)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-28715, -75)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-111319, -0)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-107526, -15)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-96405, -30)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-78714, -45)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-55659, -60)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-28811, -75)).to.be.closeTo(-1, 1e-4);
expect(iD.geoMetersToLon(-1, -90)).to.eql(0);
});
});
Expand Down Expand Up @@ -107,22 +107,22 @@ describe('iD.geo - geography', function() {
it('a straight 1 degree line at the equator is approximately 111 km', function() {
var a = [0, 0];
var b = [1, 0];
expect(iD.geoSphericalDistance(a, b)).to.be.closeTo(110946, 10);
expect(iD.geoSphericalDistance(a, b)).to.be.closeTo(111319, 10);
});
it('a pythagorean triangle is (nearly) right', function() {
var a = [0, 0];
var b = [4, 3];
expect(iD.geoSphericalDistance(a, b)).to.be.closeTo(555282, 10);
expect(iD.geoSphericalDistance(a, b)).to.be.closeTo(555804, 10);
});
it('east-west distances at high latitude are shorter', function() {
var a = [0, 60];
var b = [1, 60];
expect(iD.geoSphericalDistance(a, b)).to.be.closeTo(55473, 10);
expect(iD.geoSphericalDistance(a, b)).to.be.closeTo(55659, 10);
});
it('north-south distances at high latitude are not shorter', function() {
var a = [0, 60];
var b = [0, 61];
expect(iD.geoSphericalDistance(a, b)).to.be.closeTo(111319, 10);
expect(iD.geoSphericalDistance(a, b)).to.be.closeTo(110946, 10);
});
});

Expand Down