From b2b9b664e7ed96c4894c0705448fe43b4ef76001 Mon Sep 17 00:00:00 2001 From: Peter Wilczynski Date: Wed, 3 Feb 2016 17:28:51 -0500 Subject: [PATCH 1/8] Update build and export lltoutm --- dist/mgrs.js | 9 +++++---- mgrs.js | 2 +- publish.sh | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dist/mgrs.js b/dist/mgrs.js index 2e1ada5..e754197 100644 --- a/dist/mgrs.js +++ b/dist/mgrs.js @@ -38,7 +38,7 @@ var Z = 90; // Z * @param {object} ll Object literal with lat and lon properties on a * WGS84 ellipsoid. * @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for - * 100 m, 4 for 1000 m or 5 for 10000 m). Optional, default is 5. + * 100 m, 2 for 1000 m or 1 for 10000 m). Optional, default is 5. * @return {string} the MGRS string for the given location and accuracy. */ exports.forward = function(ll, accuracy) { @@ -105,7 +105,7 @@ function radToDeg(rad) { * northing, zoneNumber and zoneLetter properties, and an optional * accuracy property in digits. Returns null if the conversion failed. */ -function LLtoUTM(ll) { +exports.LLtoUTM = function(ll) { var Lat = ll.lat; var Long = ll.lon; var a = 6378137.0; //ellip.radius; @@ -360,8 +360,9 @@ function getLetterDesignator(lat) { * @return {string} MGRS string for the given UTM location. */ function encode(utm, accuracy) { - var seasting = "" + utm.easting, - snorthing = "" + utm.northing; + // prepend with leading zeroes + var seasting = "00000" + utm.easting, + snorthing = "00000" + utm.northing; return utm.zoneNumber + utm.zoneLetter + get100kID(utm.easting, utm.northing, utm.zoneNumber) + seasting.substr(seasting.length - 5, accuracy) + snorthing.substr(snorthing.length - 5, accuracy); } diff --git a/mgrs.js b/mgrs.js index 6d5b768..345a0d3 100644 --- a/mgrs.js +++ b/mgrs.js @@ -104,7 +104,7 @@ function radToDeg(rad) { * northing, zoneNumber and zoneLetter properties, and an optional * accuracy property in digits. Returns null if the conversion failed. */ -function LLtoUTM(ll) { +exports.LLtoUTM = function(ll) { var Lat = ll.lat; var Long = ll.lon; var a = 6378137.0; //ellip.radius; diff --git a/publish.sh b/publish.sh index b96e6d0..9fa41b7 100755 --- a/publish.sh +++ b/publish.sh @@ -11,7 +11,7 @@ git commit -m "build $VERSION" # Tag and push git tag $VERSION -git push --tags git@github.com:proj4js/mgrs.git $VERSION +git push --tags git@github.com:pwilczynski/mgrs.git $VERSION # Publish npm publish From 330e9b96faa15a8c9e40ad7af0d73f230f16b96a Mon Sep 17 00:00:00 2001 From: Peter Wilczynski Date: Wed, 3 Feb 2016 17:39:42 -0500 Subject: [PATCH 2/8] change dist --- dist/mgrs.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dist/mgrs.js b/dist/mgrs.js index e754197..4c2a8d3 100644 --- a/dist/mgrs.js +++ b/dist/mgrs.js @@ -38,7 +38,7 @@ var Z = 90; // Z * @param {object} ll Object literal with lat and lon properties on a * WGS84 ellipsoid. * @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for - * 100 m, 2 for 1000 m or 1 for 10000 m). Optional, default is 5. + * 100 m, 4 for 1000 m or 1 for 10000 m). Optional, default is 5. * @return {string} the MGRS string for the given location and accuracy. */ exports.forward = function(ll, accuracy) { @@ -360,9 +360,8 @@ function getLetterDesignator(lat) { * @return {string} MGRS string for the given UTM location. */ function encode(utm, accuracy) { - // prepend with leading zeroes - var seasting = "00000" + utm.easting, - snorthing = "00000" + utm.northing; + var seasting = "" + utm.easting, + snorthing = "" + utm.northing; return utm.zoneNumber + utm.zoneLetter + get100kID(utm.easting, utm.northing, utm.zoneNumber) + seasting.substr(seasting.length - 5, accuracy) + snorthing.substr(snorthing.length - 5, accuracy); } From 08dfea480302a706529ed52c63773f8b1bac93ab Mon Sep 17 00:00:00 2001 From: Peter Wilczynski Date: Wed, 3 Feb 2016 17:42:22 -0500 Subject: [PATCH 3/8] fix dist for rea --- dist/mgrs.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dist/mgrs.js b/dist/mgrs.js index 4c2a8d3..e754197 100644 --- a/dist/mgrs.js +++ b/dist/mgrs.js @@ -38,7 +38,7 @@ var Z = 90; // Z * @param {object} ll Object literal with lat and lon properties on a * WGS84 ellipsoid. * @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for - * 100 m, 4 for 1000 m or 1 for 10000 m). Optional, default is 5. + * 100 m, 2 for 1000 m or 1 for 10000 m). Optional, default is 5. * @return {string} the MGRS string for the given location and accuracy. */ exports.forward = function(ll, accuracy) { @@ -360,8 +360,9 @@ function getLetterDesignator(lat) { * @return {string} MGRS string for the given UTM location. */ function encode(utm, accuracy) { - var seasting = "" + utm.easting, - snorthing = "" + utm.northing; + // prepend with leading zeroes + var seasting = "00000" + utm.easting, + snorthing = "00000" + utm.northing; return utm.zoneNumber + utm.zoneLetter + get100kID(utm.easting, utm.northing, utm.zoneNumber) + seasting.substr(seasting.length - 5, accuracy) + snorthing.substr(snorthing.length - 5, accuracy); } From 9cab88de01dabecb427577e936481cacac577e08 Mon Sep 17 00:00:00 2001 From: Peter Wilczynski Date: Wed, 3 Feb 2016 17:52:22 -0500 Subject: [PATCH 4/8] upate package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3134f9b..1e3c875 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mgrs", - "version": "0.0.4-alpha", + "version": "0.0.4-pwilczynski", "description": "Utility for converting between WGS84 lat/lng and MGRS coordinates", "main": "mgrs.js", "scripts": { From 5e4b2a344aeb16ddb344c8574bf8ff7935458a76 Mon Sep 17 00:00:00 2001 From: Peter Wilczynski Date: Thu, 4 Feb 2016 10:27:26 -0500 Subject: [PATCH 5/8] Add exports and untility feature for zoneBounds --- mgrs.js | 98 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 28 deletions(-) diff --git a/mgrs.js b/mgrs.js index 345a0d3..39bac63 100644 --- a/mgrs.js +++ b/mgrs.js @@ -31,6 +31,9 @@ var O = 79; // O var V = 86; // V var Z = 90; // Z +var ZDLS = "CDEFGHJKLMNPQRSTUVWX"; +exports.ZDLS = ZDLS; + /** * Conversion of lat/lon to MGRS. * @@ -93,6 +96,35 @@ function radToDeg(rad) { return (180.0 * (rad / Math.PI)); } +exports.lonZone = function(ll) { + var Lat = ll.lat; + var Long = ll.lon; + ZoneNumber = Math.floor((Long + 180) / 6) + 1; + + //Make sure the longitude 180.00 is in Zone 60 + if (Long == 180) { + ZoneNumber = 60; + } + + // Special zone for Norway + if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) { + ZoneNumber = 32; + } + + // Special zones for Svalbard + if (Lat >= 72.0 && Lat < 84.0) { + if (Long >= 0.0 && Long < 9.0) + ZoneNumber = 31; + else if (Long >= 9.0 && Long < 21.0) + ZoneNumber = 33; + else if (Long >= 21.0 && Long < 33.0) + ZoneNumber = 35; + else if (Long >= 33.0 && Long < 42.0) + ZoneNumber = 37; + } + return ZoneNumber; +} + /** * Converts a set of Longitude and Latitude co-ordinates to UTM * using the WGS84 ellipsoid. @@ -116,35 +148,8 @@ exports.LLtoUTM = function(ll) { var LatRad = degToRad(Lat); var LongRad = degToRad(Long); var LongOriginRad; - var ZoneNumber; // (int) - ZoneNumber = Math.floor((Long + 180) / 6) + 1; - - //Make sure the longitude 180.00 is in Zone 60 - if (Long === 180) { - ZoneNumber = 60; - } - - // Special zone for Norway - if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) { - ZoneNumber = 32; - } - - // Special zones for Svalbard - if (Lat >= 72.0 && Lat < 84.0) { - if (Long >= 0.0 && Long < 9.0) { - ZoneNumber = 31; - } - else if (Long >= 9.0 && Long < 21.0) { - ZoneNumber = 33; - } - else if (Long >= 21.0 && Long < 33.0) { - ZoneNumber = 35; - } - else if (Long >= 33.0 && Long < 42.0) { - ZoneNumber = 37; - } - } + var ZoneNumber = lonZone(ll); LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin // in middle of @@ -273,6 +278,10 @@ function UTMtoLL(utm) { return result; } +exports.latZone = function(lat) { + return getLetterDesignator(lat); +} + /** * Calculates the MGRS letter designator for the given latitude. * @@ -740,3 +749,36 @@ function getMinNorthing(zoneLetter) { } } + +exports.zoneBounds = function(zoneNumber, zoneLetter) { + var latIndex = ZDLS.indexOf(zoneLetter); + var minLon = (zoneNumber - 1) * 6.0 - 180.0; + var minLat = latIndex * 8.0 - 80.0; + var latRange = 8.0; + var lonRange = 6.0; + if (zoneLetter == 'X') { + latRange = 12.0; + if (zoneNumber == 31) { + lonRange = 9.0; + } else if (zoneNumber == 37) { + minLon -= 3.0; + lonRange = 9.0; + } else if (zoneNumber == 33 || zoneNumber == 35) { + lonRange = 12.0; + minLon -= 3.0; + } + } else if (zoneLetter == 'V') { // Norway special case areas. + if (zoneNumber == 31) { + lonRange = 3.0; + } else if (zoneNumber == 32) { + minLon -= 3.0; + lonRange = 9.0; + } + } + return { + minLon: minLon, + minLat: minLat, + lonRange: lonRange, + latRange: latRange + } +} From 1d972cbf5f9bac1168865b68c771337173464488 Mon Sep 17 00:00:00 2001 From: Peter Wilczynski Date: Thu, 4 Feb 2016 10:31:35 -0500 Subject: [PATCH 6/8] fix up tests --- dist/mgrs.js | 109 +++++++++++++++++++++++++++++++++++++-------------- mgrs.js | 59 ++++++++++++++++------------ 2 files changed, 114 insertions(+), 54 deletions(-) diff --git a/dist/mgrs.js b/dist/mgrs.js index e754197..e0eda66 100644 --- a/dist/mgrs.js +++ b/dist/mgrs.js @@ -32,6 +32,9 @@ var O = 79; // O var V = 86; // V var Z = 90; // Z +var ZDLS = "CDEFGHJKLMNPQRSTUVWX"; +exports.ZDLS = ZDLS; + /** * Conversion of lat/lon to MGRS. * @@ -94,6 +97,39 @@ function radToDeg(rad) { return (180.0 * (rad / Math.PI)); } +function lonZone(ll) { + var Lat = ll.lat; + var Long = ll.lon; + ZoneNumber = Math.floor((Long + 180) / 6) + 1; + + //Make sure the longitude 180.00 is in Zone 60 + if (Long == 180) { + ZoneNumber = 60; + } + + // Special zone for Norway + if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) { + ZoneNumber = 32; + } + + // Special zones for Svalbard + if (Lat >= 72.0 && Lat < 84.0) { + if (Long >= 0.0 && Long < 9.0) + ZoneNumber = 31; + else if (Long >= 9.0 && Long < 21.0) + ZoneNumber = 33; + else if (Long >= 21.0 && Long < 33.0) + ZoneNumber = 35; + else if (Long >= 33.0 && Long < 42.0) + ZoneNumber = 37; + } + return ZoneNumber; +} + +exports.lonZone = function(ll) { + return lonZone(ll); +} + /** * Converts a set of Longitude and Latitude co-ordinates to UTM * using the WGS84 ellipsoid. @@ -105,7 +141,8 @@ function radToDeg(rad) { * northing, zoneNumber and zoneLetter properties, and an optional * accuracy property in digits. Returns null if the conversion failed. */ -exports.LLtoUTM = function(ll) { + +function LLtoUTM(ll) { var Lat = ll.lat; var Long = ll.lon; var a = 6378137.0; //ellip.radius; @@ -117,35 +154,8 @@ exports.LLtoUTM = function(ll) { var LatRad = degToRad(Lat); var LongRad = degToRad(Long); var LongOriginRad; - var ZoneNumber; // (int) - ZoneNumber = Math.floor((Long + 180) / 6) + 1; - - //Make sure the longitude 180.00 is in Zone 60 - if (Long === 180) { - ZoneNumber = 60; - } - - // Special zone for Norway - if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) { - ZoneNumber = 32; - } - - // Special zones for Svalbard - if (Lat >= 72.0 && Lat < 84.0) { - if (Long >= 0.0 && Long < 9.0) { - ZoneNumber = 31; - } - else if (Long >= 9.0 && Long < 21.0) { - ZoneNumber = 33; - } - else if (Long >= 21.0 && Long < 33.0) { - ZoneNumber = 35; - } - else if (Long >= 33.0 && Long < 42.0) { - ZoneNumber = 37; - } - } + var ZoneNumber = lonZone(ll); LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin // in middle of @@ -177,6 +187,10 @@ exports.LLtoUTM = function(ll) { }; } +exports.LLtoUTM = function(ll) { + return LLtoUTM(ll); +} + /** * Converts UTM coords to lat/long, using the WGS84 ellipsoid. This is a convenience * class where the Zone can be specified as a single string eg."60N" which @@ -274,6 +288,10 @@ function UTMtoLL(utm) { return result; } +exports.latZone = function(lat) { + return getLetterDesignator(lat); +} + /** * Calculates the MGRS letter designator for the given latitude. * @@ -742,5 +760,38 @@ function getMinNorthing(zoneLetter) { } +exports.zoneBounds = function(zoneNumber, zoneLetter) { + var latIndex = ZDLS.indexOf(zoneLetter); + var minLon = (zoneNumber - 1) * 6.0 - 180.0; + var minLat = latIndex * 8.0 - 80.0; + var latRange = 8.0; + var lonRange = 6.0; + if (zoneLetter == 'X') { + latRange = 12.0; + if (zoneNumber == 31) { + lonRange = 9.0; + } else if (zoneNumber == 37) { + minLon -= 3.0; + lonRange = 9.0; + } else if (zoneNumber == 33 || zoneNumber == 35) { + lonRange = 12.0; + minLon -= 3.0; + } + } else if (zoneLetter == 'V') { // Norway special case areas. + if (zoneNumber == 31) { + lonRange = 3.0; + } else if (zoneNumber == 32) { + minLon -= 3.0; + lonRange = 9.0; + } + } + return { + minLon: minLon, + minLat: minLat, + lonRange: lonRange, + latRange: latRange + } +} + },{}]},{},[1])(1) }); diff --git a/mgrs.js b/mgrs.js index 39bac63..351ba7b 100644 --- a/mgrs.js +++ b/mgrs.js @@ -96,33 +96,37 @@ function radToDeg(rad) { return (180.0 * (rad / Math.PI)); } -exports.lonZone = function(ll) { - var Lat = ll.lat; - var Long = ll.lon; - ZoneNumber = Math.floor((Long + 180) / 6) + 1; +function lonZone(ll) { + var Lat = ll.lat; + var Long = ll.lon; + ZoneNumber = Math.floor((Long + 180) / 6) + 1; - //Make sure the longitude 180.00 is in Zone 60 - if (Long == 180) { - ZoneNumber = 60; - } + //Make sure the longitude 180.00 is in Zone 60 + if (Long == 180) { + ZoneNumber = 60; + } - // Special zone for Norway - if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) { - ZoneNumber = 32; - } + // Special zone for Norway + if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) { + ZoneNumber = 32; + } - // Special zones for Svalbard - if (Lat >= 72.0 && Lat < 84.0) { - if (Long >= 0.0 && Long < 9.0) - ZoneNumber = 31; - else if (Long >= 9.0 && Long < 21.0) - ZoneNumber = 33; - else if (Long >= 21.0 && Long < 33.0) - ZoneNumber = 35; - else if (Long >= 33.0 && Long < 42.0) - ZoneNumber = 37; - } - return ZoneNumber; + // Special zones for Svalbard + if (Lat >= 72.0 && Lat < 84.0) { + if (Long >= 0.0 && Long < 9.0) + ZoneNumber = 31; + else if (Long >= 9.0 && Long < 21.0) + ZoneNumber = 33; + else if (Long >= 21.0 && Long < 33.0) + ZoneNumber = 35; + else if (Long >= 33.0 && Long < 42.0) + ZoneNumber = 37; + } + return ZoneNumber; +} + +exports.lonZone = function(ll) { + return lonZone(ll); } /** @@ -136,7 +140,8 @@ exports.lonZone = function(ll) { * northing, zoneNumber and zoneLetter properties, and an optional * accuracy property in digits. Returns null if the conversion failed. */ -exports.LLtoUTM = function(ll) { + +function LLtoUTM(ll) { var Lat = ll.lat; var Long = ll.lon; var a = 6378137.0; //ellip.radius; @@ -181,6 +186,10 @@ exports.LLtoUTM = function(ll) { }; } +exports.LLtoUTM = function(ll) { + return LLtoUTM(ll); +} + /** * Converts UTM coords to lat/long, using the WGS84 ellipsoid. This is a convenience * class where the Zone can be specified as a single string eg."60N" which From 14dcf57c82acaf5d194a8b33b52c8d68e1ed1960 Mon Sep 17 00:00:00 2001 From: Peter Wilczynski Date: Thu, 4 Feb 2016 14:29:15 -0500 Subject: [PATCH 7/8] propagate typings --- dist/mgrs.js | 4 ++-- mgrs.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/mgrs.js b/dist/mgrs.js index e0eda66..72b1b24 100644 --- a/dist/mgrs.js +++ b/dist/mgrs.js @@ -288,8 +288,8 @@ function UTMtoLL(utm) { return result; } -exports.latZone = function(lat) { - return getLetterDesignator(lat); +exports.latZone = function(ll) { + return getLetterDesignator(ll.lat); } /** diff --git a/mgrs.js b/mgrs.js index 351ba7b..790ad1f 100644 --- a/mgrs.js +++ b/mgrs.js @@ -287,8 +287,8 @@ function UTMtoLL(utm) { return result; } -exports.latZone = function(lat) { - return getLetterDesignator(lat); +exports.latZone = function(ll) { + return getLetterDesignator(ll.lat); } /** From 2dbe24f24897ed61d5c3e61d21bd43202e3642c5 Mon Sep 17 00:00:00 2001 From: Peter Wilczynski Date: Tue, 9 Feb 2016 16:12:56 -0500 Subject: [PATCH 8/8] final export of utmtoll --- dist/mgrs.js | 4 ++++ mgrs.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/dist/mgrs.js b/dist/mgrs.js index 72b1b24..b2e1a5e 100644 --- a/dist/mgrs.js +++ b/dist/mgrs.js @@ -288,6 +288,10 @@ function UTMtoLL(utm) { return result; } +exports.UTMtoLL = function(utm) { + return UTMtoLL(utm); +} + exports.latZone = function(ll) { return getLetterDesignator(ll.lat); } diff --git a/mgrs.js b/mgrs.js index 790ad1f..c522a96 100644 --- a/mgrs.js +++ b/mgrs.js @@ -287,6 +287,10 @@ function UTMtoLL(utm) { return result; } +exports.UTMtoLL = function(utm) { + return UTMtoLL(utm); +} + exports.latZone = function(ll) { return getLetterDesignator(ll.lat); }