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\Distance; |
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 distance:vincenty class |
24
|
|
|
* |
25
|
|
|
* @author Antoine Corcy <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class Vincenty extends \Symfony\Component\Console\Command\Command |
28
|
|
|
{ |
29
|
9 |
|
protected function configure() |
30
|
|
|
{ |
31
|
9 |
|
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames(); |
32
|
|
|
|
33
|
9 |
|
$this |
34
|
9 |
|
->setName('distance:vincenty') |
35
|
9 |
|
->setDescription('Compute the distance between 2 coordinates using the vincenty algorithm, in meters by default') |
36
|
9 |
|
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate') |
37
|
9 |
|
->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate') |
38
|
9 |
|
->addOption('km', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in kilometers') |
39
|
9 |
|
->addOption('mi', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in miles') |
40
|
9 |
|
->addOption('ft', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in feet') |
41
|
9 |
|
->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED, |
42
|
9 |
|
'If set, the name of the ellipsoid to use', Ellipsoid::WGS84) |
43
|
9 |
|
->setHelp(<<<EOT |
44
|
|
|
<info>Available ellipsoids</info>: $availableEllipsoids |
45
|
|
|
|
46
|
|
|
<info>Example with WGS72 ellipsoid and output in miles</info>: |
47
|
|
|
|
48
|
9 |
|
%command.full_name% "40° 26.7717, -79° 56.93172" "30°16′57″N 029°48′32″W" <comment>--ellipsoid=WGS72 --mi</comment> |
49
|
|
|
EOT |
50
|
9 |
|
); |
51
|
9 |
|
} |
52
|
|
|
|
53
|
8 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
54
|
|
|
{ |
55
|
8 |
|
$ellipsoid = Ellipsoid::createFromName($input->getOption('ellipsoid')); |
56
|
6 |
|
$from = new Coordinate($input->getArgument('origin'), $ellipsoid); |
57
|
5 |
|
$to = new Coordinate($input->getArgument('destination'), $ellipsoid); |
58
|
|
|
|
59
|
5 |
|
$geotools = new Geotools; |
60
|
5 |
|
$distance = $geotools->distance()->setFrom($from)->setTo($to); |
61
|
|
|
|
62
|
5 |
|
if ($input->getOption('km')) { |
63
|
1 |
|
$distance->in('km'); |
64
|
1 |
|
} |
65
|
|
|
|
66
|
5 |
|
if ($input->getOption('mi')) { |
67
|
1 |
|
$distance->in('mi'); |
68
|
1 |
|
} |
69
|
|
|
|
70
|
5 |
|
if ($input->getOption('ft')) { |
71
|
2 |
|
$distance->in('ft'); |
72
|
2 |
|
} |
73
|
|
|
|
74
|
5 |
|
$output->writeln(sprintf('<value>%s</value>', $distance->vincenty())); |
75
|
5 |
|
} |
76
|
|
|
} |
77
|
|
|
|