Skip to content

Commit

Permalink
Fixed using radians instead of degrees
Browse files Browse the repository at this point in the history
This commit mainly fixes #3. Anyway, complete changelist:

- Fixed using radians instead of degrees for lon and lat parameters.
- Fixed using degrees instead of radians for GeogAngularUnitSizeGeoKey.
- Did a little refactoring, mainly merged angular and linear (miscalled, actually all) units.
  • Loading branch information
matafokka committed May 26, 2022
1 parent dca6bb9 commit d2105ea
Show file tree
Hide file tree
Showing 23 changed files with 856 additions and 715 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion EPSG/CRSWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const forEach = require("./forEachEntryInEPSG.js");
forEach(`
SELECT crs.coord_ref_sys_code AS id,
crs.coord_ref_sys_kind AS type,
coord_sys_code,
crs.datum_code AS datum,
crs.cmpd_horizcrs_code AS basecrs,
coord_sys_code AS cs
Expand Down
14 changes: 10 additions & 4 deletions EPSG/ConversionsWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const methods = require("./data/Methods.js")
const parameters = require("./data/MethodParameters.js");
const LinearUnits = require("./data/LinearUnits.js");
const Units = require("./data/Units.js");
const toDeg = require("./data/toDeg.js");
const forEach = require("./forEachEntryInEPSG.js");

Expand All @@ -26,12 +26,18 @@ forEach(`
let paramDef = parameters[param.f1.toString()], value = param.f2, uomCode = param.f3.toString();
if (!paramDef)
continue;
if (uomCode in LinearUnits)
value *= LinearUnits[uomCode].m;
else

if (uomCode in Units) {
let {m} = Units[uomCode];
if (paramDef.includes("lat") || paramDef.includes("lon"))
m *= 180 / Math.PI; // Radians are angular base units
value *= m;
} else
value = toDeg(value, param.f3);

if (value === null)
return;

method += ` +${paramDef}=${value}`
}

Expand Down
6 changes: 3 additions & 3 deletions EPSG/EllipsoidalCSWorker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* This script generates ellipsoidal CS from epsg.io. Can be used standalone or in a worker. */

const multipliers = require("./data/toDegreeMultipliers.js");
const Units = require("./data/Units.js");
const forEach = require("./forEachEntryInEPSG.js");

forEach(`
Expand Down Expand Up @@ -59,9 +59,9 @@ forEach(`
if (uom === "deg" || uom === "degree" || uom === "degrees") // Can't just find deg because there're degree with hemisphere and dec degree
m = 1;
else if (uom.includes("grad") || uom.includes("gon"))
m = multipliers["9105"];
m = Units["9105"].m * 180 / Math.PI;
else if (uom.includes("rad")) // grad handled by previous case
m = multipliers["9101"];
m = Units["9101"].m * 180 / Math.PI;
else
return;

Expand Down
4 changes: 2 additions & 2 deletions EPSG/EllipsoidsWorker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This script generates ellipsoids from epsg database. Can be used standalone or in a worker. */

const forEach = require("./forEachEntryInEPSG.js");
const LinearUnits = require("./data/LinearUnits.js");
const Units = require("./data/Units.js");
const names = require("./data/EllipsoidsNamesToProj.js");

forEach(`
Expand Down Expand Up @@ -33,7 +33,7 @@ forEach(`
ellipsoidString = "+ellps=" + ellipsoidString + " ";

// Get axes
let uom = LinearUnits[result.uom.toString()];
let uom = Units[result.uom.toString()];
if (!uom)
return undefined;
uom = uom.m;
Expand Down
6 changes: 3 additions & 3 deletions EPSG/LinearUnitsWorker.js → EPSG/UnitsWorker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This script generates linear units from epsg.io. Can be used standalone or in a worker. */
/* This script generates units from EPSG database. Can be used standalone or in a worker. */

const BaseUnits = require("./data/KnownBaseUnits.js");
const forEach = require("./forEachEntryInEPSG.js");
Expand Down Expand Up @@ -30,8 +30,8 @@ forEach(`
t: baseUnit,
};

}, "LinearUnits", `/**
* Maps EPSG linear units to their multipliers to convert to meters (or standard base values, see below). Proj4 parameter is "+to_meter".
}, "Units", `/**
* Maps EPSG units to their multipliers to convert to meters (or standard base values, see below). Proj4 parameter is "+to_meter".
*
* Some of these units for some reason represents speed, angular speed and time. They're converted to m/s, rad/s and s respectively. Moreover, there's unity and unity/s where length is dimensionless. I guess, they should be treated as meters when projecting.
*
Expand Down
2 changes: 1 addition & 1 deletion EPSG/data/CRS.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion EPSG/data/EllipsoidalCS.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* x, y - value to multiply x or y coordinates by to convert them to degrees. If it's not present, multiplication is not needed.
* @type {Object}
*/
module.exports = {"6403":{"axis":"ne","x":0.9,"y":0.9},"6404":{"axis":"neu","x":1,"y":1},"6421":{"axis":"neu","x":0.9,"y":0.9},"6422":{"axis":"ne","x":1,"y":1},"6423":{"axis":"neu","x":1,"y":1},"6424":{"axis":"en","x":1,"y":1},"6425":{"axis":"en","x":0.9,"y":0.9},"6426":{"axis":"enu","x":1,"y":1},"6427":{"axis":"enu","x":0.9,"y":0.9},"6428":{"axis":"ne","x":57.29577951308232,"y":57.29577951308232},"6429":{"axis":"en","x":57.29577951308232,"y":57.29577951308232},"6430":{"axis":"neu","x":57.29577951308232,"y":57.29577951308232},"6431":{"axis":"enu","x":57.29577951308232,"y":57.29577951308232}}
module.exports = {"6403":{"axis":"ne","x":0.8999999999999991,"y":0.8999999999999991},"6404":{"axis":"neu","x":1,"y":1},"6421":{"axis":"neu","x":0.8999999999999991,"y":0.8999999999999991},"6422":{"axis":"ne","x":1,"y":1},"6423":{"axis":"neu","x":1,"y":1},"6424":{"axis":"en","x":1,"y":1},"6425":{"axis":"en","x":0.8999999999999991,"y":0.8999999999999991},"6426":{"axis":"enu","x":1,"y":1},"6427":{"axis":"enu","x":0.8999999999999991,"y":0.8999999999999991},"6428":{"axis":"ne","x":57.29577951308232,"y":57.29577951308232},"6429":{"axis":"en","x":57.29577951308232,"y":57.29577951308232},"6430":{"axis":"neu","x":57.29577951308232,"y":57.29577951308232},"6431":{"axis":"enu","x":57.29577951308232,"y":57.29577951308232}}
2 changes: 1 addition & 1 deletion EPSG/data/GeogGeodeticDatumGeoKey.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion EPSG/data/GeogPrimeMeridianGeoKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* Maps EPSG prime meridians to their longitudes. Proj4 parameter is "+pm".
* @type {Object}
*/
module.exports = {"8901":0,"8902":-24.35611111111111,"8903":2.33722917,"8904":-74.20916666666666,"8905":-4.0875,"8906":12.473333333333333,"8907":7.495833333333334,"8908":107.57194444444444,"8909":-17.066666666666666,"8910":4.4975,"8911":18.13277777777778,"8912":40.037499999999994,"8913":10.779166666666667,"8914":2.7208333333333337}
module.exports = {"8901":0,"8902":-24.35611111111111,"8903":2.337229169999998,"8904":-74.20916666666666,"8905":-4.0875,"8906":12.473333333333333,"8907":7.495833333333334,"8908":107.57194444444444,"8909":-17.066666666666666,"8910":4.4975,"8911":18.13277777777778,"8912":40.037499999999994,"8913":10.779166666666667,"8914":2.7208333333333337}
2 changes: 1 addition & 1 deletion EPSG/data/ProjectionGeoKey.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions EPSG/data/toDeg.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const multipliers = require("./toDegreeMultipliers.js");
const Units = require("./Units.js");

/**
* Retuns sign from given hemisphere
* Returns sign from given hemisphere
* @param hemisphere {"n"|"s"|"e"|"w"} Hemisphere letter, case insensitive
* @return Sign from given hemisphere
*/
function signFromHemisphere(hemisphere) {
let h = hemisphere.toLowerCase();
Expand All @@ -19,8 +20,8 @@ function signFromHemisphere(hemisphere) {
*/
module.exports = function (value, code) {
let codeStr = code.toString();
if (codeStr in multipliers)
return value * multipliers[codeStr];
if (codeStr in Units)
return value * Units[codeStr].m * 180 / Math.PI;

// Messed up shit
if (code === 9110) {
Expand Down
18 changes: 0 additions & 18 deletions EPSG/data/toDegreeMultipliers.js

This file was deleted.

8 changes: 4 additions & 4 deletions EPSG/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const {Worker} = require('worker_threads');
const baseDir = "./EPSG/";
const options = {workerData: require("../dbConnectionParams.js")};

// Fetch linear units first because all other entities depends on it
// Fetch units first because all other entities depends on it
fetchLinearUnits();

function fetchLinearUnits() {
let linearUnitsWorker = new Worker(baseDir + "LinearUnitsWorker.js", options);
linearUnitsWorker.on("exit", () => {
new Worker(baseDir + "ConversionsWorker.js", options); // Conversions depends only on linear units, everything else depends on each other
let unitsWorker = new Worker(baseDir + "UnitsWorker.js", options);
unitsWorker.on("exit", () => {
new Worker(baseDir + "ConversionsWorker.js", options); // Conversions depends only on units, everything else depends on each other
fetchBasicEntities();
});
}
Expand Down
4 changes: 1 addition & 3 deletions geotiff-geokeys-to-proj4.iml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/docs" />
</content>
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
Expand Down
Loading

0 comments on commit d2105ea

Please sign in to comment.