ConvertCoordinateFormat.mjs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @author j433866 [j433866@gmail.com]
  3. * @copyright Crown Copyright 2019
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation.mjs";
  7. import {FORMATS, convertCoordinates} from "../lib/ConvertCoordinates.mjs";
  8. /**
  9. * Convert co-ordinate format operation
  10. */
  11. class ConvertCoordinateFormat extends Operation {
  12. /**
  13. * ConvertCoordinateFormat constructor
  14. */
  15. constructor() {
  16. super();
  17. this.name = "Convert co-ordinate format";
  18. this.module = "Hashing";
  19. this.description = "Converts geographical coordinates between different formats.<br><br>Supported formats:<ul><li>Degrees Minutes Seconds (DMS)</li><li>Degrees Decimal Minutes (DDM)</li><li>Decimal Degrees (DD)</li><li>Geohash</li><li>Military Grid Reference System (MGRS)</li><li>Ordnance Survey National Grid (OSNG)</li><li>Universal Transverse Mercator (UTM)</li></ul><br>The operation can try to detect the input co-ordinate format and delimiter automatically, but this may not always work correctly.";
  20. this.infoURL = "https://wikipedia.org/wiki/Geographic_coordinate_conversion";
  21. this.inputType = "string";
  22. this.outputType = "string";
  23. this.args = [
  24. {
  25. "name": "Input Format",
  26. "type": "option",
  27. "value": ["Auto"].concat(FORMATS)
  28. },
  29. {
  30. "name": "Input Delimiter",
  31. "type": "option",
  32. "value": [
  33. "Auto",
  34. "Direction Preceding",
  35. "Direction Following",
  36. "\\n",
  37. "Comma",
  38. "Semi-colon",
  39. "Colon"
  40. ]
  41. },
  42. {
  43. "name": "Output Format",
  44. "type": "option",
  45. "value": FORMATS
  46. },
  47. {
  48. "name": "Output Delimiter",
  49. "type": "option",
  50. "value": [
  51. "Space",
  52. "\\n",
  53. "Comma",
  54. "Semi-colon",
  55. "Colon"
  56. ]
  57. },
  58. {
  59. "name": "Include Compass Directions",
  60. "type": "option",
  61. "value": [
  62. "None",
  63. "Before",
  64. "After"
  65. ]
  66. },
  67. {
  68. "name": "Precision",
  69. "type": "number",
  70. "value": 3
  71. }
  72. ];
  73. }
  74. /**
  75. * @param {string} input
  76. * @param {Object[]} args
  77. * @returns {string}
  78. */
  79. run(input, args) {
  80. if (input.replace(/[\s+]/g, "") !== "") {
  81. const [inFormat, inDelim, outFormat, outDelim, incDirection, precision] = args;
  82. const result = convertCoordinates(input, inFormat, inDelim, outFormat, outDelim, incDirection, precision);
  83. return result;
  84. } else {
  85. return input;
  86. }
  87. }
  88. }
  89. export default ConvertCoordinateFormat;