diff options
| author | Charles Karney <charles@karney.com> | 2018-07-11 09:49:22 -0400 |
|---|---|---|
| committer | Charles Karney <charles@karney.com> | 2018-07-11 09:49:22 -0400 |
| commit | 3e03508e043123dbdc3ebb00ce6c67f12c8f8c47 (patch) | |
| tree | c45bf751a6b49539b0b615afe93c821fa94a0d2a | |
| parent | 81bfa7551ffb3f0406760f566c50b84370c3d020 (diff) | |
| download | PROJ-3e03508e043123dbdc3ebb00ce6c67f12c8f8c47.tar.gz PROJ-3e03508e043123dbdc3ebb00ce6c67f12c8f8c47.zip | |
Fix #1074. Fix unit conversion factors for geod.
Previously, unit conversion using atof(unit_list[i].to_meter) which
gives the wrong answer with, e.g., "1/10". Now it directly uses
unit_list[i].factor (e.g., 0.1).
Also fix all the conversion factors for the US Surveyor units so that
they are the closest doubles. E.g., the conversion factors for US
feet are
factor rel error
old 0.304800609601219 6e-16
12/39.37 1e-16
now 1200/3937.0 5e-17
Maybe someone should check the Indian units (but it's possible that
India and Pakistan have different standards).
| -rw-r--r-- | src/geod_set.c | 2 | ||||
| -rw-r--r-- | src/pj_units.c | 16 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/geod_set.c b/src/geod_set.c index 479f18da..dacb0c73 100644 --- a/src/geod_set.c +++ b/src/geod_set.c @@ -37,7 +37,7 @@ geod_set(int argc, char **argv) { for (i = 0; (s = unit_list[i].id) && strcmp(name, s) ; ++i) ; if (!s) emess(1,"%s unknown unit conversion id", name); - fr_meter = 1. / (to_meter = atof(unit_list[i].to_meter)); + fr_meter = 1. / (to_meter = unit_list[i].factor); } else to_meter = fr_meter = 1.; geod_f = es/(1 + sqrt(1 - es)); diff --git a/src/pj_units.c b/src/pj_units.c index 59ff1ebe..e8421dea 100644 --- a/src/pj_units.c +++ b/src/pj_units.c @@ -12,12 +12,12 @@ ** numerator/denomenator values (e.g. 1/1000) */ C_NAMESPACE_VAR const struct PJ_UNITS pj_units[] = { - {"km", "1000.", "Kilometer", 1000.0}, - {"m", "1.", "Meter", 1.0}, + {"km", "1000", "Kilometer", 1000.0}, + {"m", "1", "Meter", 1.0}, {"dm", "1/10", "Decimeter", 0.1}, {"cm", "1/100", "Centimeter", 0.01}, {"mm", "1/1000", "Millimeter", 0.001}, - {"kmi", "1852.0", "International Nautical Mile", 1852.0}, + {"kmi", "1852", "International Nautical Mile", 1852.0}, {"in", "0.0254", "International Inch", 0.0254}, {"ft", "0.3048", "International Foot", 0.3048}, {"yd", "0.9144", "International Yard", 0.9144}, @@ -25,11 +25,11 @@ pj_units[] = { {"fath", "1.8288", "International Fathom", 1.8288}, {"ch", "20.1168", "International Chain", 20.1168}, {"link", "0.201168", "International Link", 0.201168}, - {"us-in", "1./39.37", "U.S. Surveyor's Inch", 0.0254}, - {"us-ft", "0.304800609601219", "U.S. Surveyor's Foot", 0.304800609601219}, - {"us-yd", "0.914401828803658", "U.S. Surveyor's Yard", 0.914401828803658}, - {"us-ch", "20.11684023368047", "U.S. Surveyor's Chain", 20.11684023368047}, - {"us-mi", "1609.347218694437", "U.S. Surveyor's Statute Mile", 1609.347218694437}, + {"us-in", "1/39.37", "U.S. Surveyor's Inch", 100/3937.0}, + {"us-ft", "12/39.37", "U.S. Surveyor's Foot", 1200/3937.0}, + {"us-yd", "36/39.37", "U.S. Surveyor's Yard", 3600/3937.0}, + {"us-ch", "792/39.37", "U.S. Surveyor's Chain", 79200/3937.0}, + {"us-mi", "63360/39.37", "U.S. Surveyor's Statute Mile", 6336000/3937.0}, {"ind-yd", "0.91439523", "Indian Yard", 0.91439523}, {"ind-ft", "0.30479841", "Indian Foot", 0.30479841}, {"ind-ch", "20.11669506", "Indian Chain", 20.11669506}, |
