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\Vertex; |
13
|
|
|
|
14
|
|
|
use League\Geotools\Coordinate\Coordinate; |
15
|
|
|
use League\Geotools\Coordinate\Ellipsoid; |
16
|
|
|
use League\Geotools\Geotools; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Command-line vertex:final-bearing class |
24
|
|
|
* |
25
|
|
|
* @author Antoine Corcy <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class FinalBearing extends \Symfony\Component\Console\Command\Command |
28
|
|
|
{ |
29
|
6 |
|
protected function configure() |
30
|
|
|
{ |
31
|
6 |
|
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames(); |
32
|
|
|
|
33
|
|
|
$this |
34
|
6 |
|
->setName('vertex:final-bearing') |
35
|
6 |
|
->setDescription('Compute the final bearing in degrees between 2 coordinates') |
36
|
6 |
|
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate') |
37
|
6 |
|
->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate') |
38
|
6 |
|
->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED, |
39
|
6 |
|
'If set, the name of the ellipsoid to use', Ellipsoid::WGS84) |
40
|
6 |
|
->setHelp(<<<EOT |
41
|
6 |
|
<info>Available ellipsoids</info>: $availableEllipsoids |
42
|
|
|
|
43
|
|
|
<info>Example with GRS_1980 ellipsoid</info>: |
44
|
|
|
|
45
|
|
|
%command.full_name% "40° 26.7717, -79° 56.93172" "30°16′57″N 029°48′32″W" <comment>--ellipsoid=GRS_1980</comment> |
46
|
|
|
EOT |
47
|
|
|
); |
48
|
6 |
|
} |
49
|
|
|
|
50
|
5 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
51
|
|
|
{ |
52
|
5 |
|
$ellipsoid = Ellipsoid::createFromName($input->getOption('ellipsoid')); |
53
|
3 |
|
$from = new Coordinate($input->getArgument('origin'), $ellipsoid); |
54
|
2 |
|
$to = new Coordinate($input->getArgument('destination'), $ellipsoid); |
55
|
|
|
|
56
|
2 |
|
$geotools = new Geotools; |
57
|
|
|
|
58
|
2 |
|
$output->writeln(sprintf( |
59
|
2 |
|
'<value>%s</value>', |
60
|
2 |
|
$geotools->vertex()->setFrom($from)->setTo($to)->finalBearing() |
61
|
|
|
)); |
62
|
2 |
|
return 0; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|