1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Geotools library. |
5
|
|
|
* |
6
|
|
|
* (c) Antoine Corcy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace League\Geotools\CLI\Command\Convert; |
13
|
|
|
|
14
|
|
|
use League\Geotools\Convert\ConvertInterface; |
15
|
|
|
use League\Geotools\Coordinate\Coordinate; |
16
|
|
|
use League\Geotools\Coordinate\Ellipsoid; |
17
|
|
|
use League\Geotools\Geotools; |
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Input\InputOption; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Command-line convert:dm class |
25
|
|
|
* |
26
|
|
|
* @author Antoine Corcy <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class DM extends \Symfony\Component\Console\Command\Command |
29
|
|
|
{ |
30
|
8 |
|
protected function configure() |
31
|
|
|
{ |
32
|
8 |
|
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames(); |
33
|
|
|
|
34
|
|
|
$this |
35
|
8 |
|
->setName('convert:dm') |
36
|
8 |
|
->setDescription('Convert and format decimal degrees coordinates to decimal minutes coordinate') |
37
|
8 |
|
->addArgument('coordinate', InputArgument::REQUIRED, 'The "Lat,Long" coordinate') |
38
|
8 |
|
->addOption('format', null, InputOption::VALUE_REQUIRED, |
39
|
8 |
|
'If set, the format of the converted decimal minutes coordinate', ConvertInterface::DEFAULT_DM_FORMAT) |
40
|
8 |
|
->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED, |
41
|
8 |
|
'If set, the name of the ellipsoid to use', Ellipsoid::WGS84) |
42
|
8 |
|
->setHelp(<<<EOT |
43
|
|
|
<info>Available ellipsoids</info>: $availableEllipsoids |
44
|
|
|
|
45
|
|
|
<info>Example with an output format</info>: |
46
|
|
|
|
47
|
|
|
%command.full_name% "40.446195, -79.948862" <comment>--format="%P%D°%N %p%d°%n"</comment> |
48
|
|
|
|
49
|
|
|
<info>Example with FISCHER_1968 ellipsoid</info>: |
50
|
|
|
|
51
|
8 |
|
%command.full_name% "40.446195, -79.948862" <comment>--ellipsoid=FISCHER_1968</comment> |
52
|
|
|
EOT |
53
|
|
|
); |
54
|
8 |
|
} |
55
|
|
|
|
56
|
7 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
57
|
|
|
{ |
58
|
7 |
|
$ellipsoid = Ellipsoid::createFromName($input->getOption('ellipsoid')); |
59
|
5 |
|
$coordinate = new Coordinate($input->getArgument('coordinate'), $ellipsoid); |
60
|
4 |
|
$geotools = new Geotools; |
61
|
|
|
|
62
|
4 |
|
$output->writeln(sprintf( |
63
|
4 |
|
'<value>%s</value>', |
64
|
4 |
|
$geotools->convert($coordinate)->toDM($input->getOption('format')) |
65
|
|
|
)); |
66
|
4 |
|
} |
67
|
|
|
} |
68
|
|
|
|