2019-01-14 12:49:57 +01:00
/ * *
* @ author j433866 [ j433866 @ gmail . com ]
* @ copyright Crown Copyright 2019
* @ license Apache - 2.0
* /
2019-07-09 13:23:59 +02:00
import Operation from "../Operation.mjs" ;
import { FORMATS , convertCoordinates } from "../lib/ConvertCoordinates.mjs" ;
2019-01-14 12:49:57 +01:00
/ * *
* Convert co - ordinate format operation
* /
class ConvertCoordinateFormat extends Operation {
/ * *
* ConvertCoordinateFormat constructor
* /
constructor ( ) {
super ( ) ;
this . name = "Convert co-ordinate format" ;
this . module = "Hashing" ;
2019-01-18 18:14:25 +01:00
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." ;
2019-01-14 12:49:57 +01:00
this . infoURL = "https://wikipedia.org/wiki/Geographic_coordinate_conversion" ;
this . inputType = "string" ;
this . outputType = "string" ;
this . args = [
{
"name" : "Input Format" ,
"type" : "option" ,
"value" : [ "Auto" ] . concat ( FORMATS )
} ,
{
"name" : "Input Delimiter" ,
"type" : "option" ,
"value" : [
"Auto" ,
2019-01-14 15:58:41 +01:00
"Direction Preceding" ,
2019-01-14 12:49:57 +01:00
"Direction Following" ,
"\\n" ,
"Comma" ,
"Semi-colon" ,
"Colon"
]
} ,
{
"name" : "Output Format" ,
"type" : "option" ,
"value" : FORMATS
} ,
{
"name" : "Output Delimiter" ,
"type" : "option" ,
"value" : [
"Space" ,
"\\n" ,
"Comma" ,
"Semi-colon" ,
"Colon"
]
} ,
2019-01-15 16:55:49 +01:00
{
"name" : "Include Compass Directions" ,
"type" : "option" ,
"value" : [
"None" ,
"Before" ,
"After"
]
} ,
2019-01-14 12:49:57 +01:00
{
"name" : "Precision" ,
"type" : "number" ,
"value" : 3
}
] ;
}
/ * *
* @ param { string } input
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
2019-01-16 17:57:58 +01:00
if ( input . replace ( /[\s+]/g , "" ) !== "" ) {
const [ inFormat , inDelim , outFormat , outDelim , incDirection , precision ] = args ;
2019-01-18 18:14:25 +01:00
const result = convertCoordinates ( input , inFormat , inDelim , outFormat , outDelim , incDirection , precision ) ;
return result ;
2019-01-16 17:57:58 +01:00
} else {
return input ;
}
2019-01-14 12:49:57 +01:00
}
}
export default ConvertCoordinateFormat ;