-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathVincenty.php
More file actions
77 lines (64 loc) · 2.79 KB
/
Vincenty.php
File metadata and controls
77 lines (64 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* This file is part of the Geotools library.
*
* (c) Antoine Corcy <contact@sbin.dk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\Geotools\CLI\Command\Distance;
use League\Geotools\Coordinate\Coordinate;
use League\Geotools\Coordinate\Ellipsoid;
use League\Geotools\Geotools;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Command-line distance:vincenty class
*
* @author Antoine Corcy <contact@sbin.dk>
*/
class Vincenty extends \Symfony\Component\Console\Command\Command
{
protected function configure(): void
{
$availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();
$this
->setName('distance:vincenty')
->setDescription('Compute the distance between 2 coordinates using the vincenty algorithm, in meters by default')
->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate')
->addOption('km', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in kilometers')
->addOption('mi', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in miles')
->addOption('ft', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in feet')
->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED,
'If set, the name of the ellipsoid to use', Ellipsoid::WGS84)
->setHelp(<<<EOT
<info>Available ellipsoids</info>: $availableEllipsoids
<info>Example with WGS72 ellipsoid and output in miles</info>:
%command.full_name% "40° 26.7717, -79° 56.93172" "30°16′57″N 029°48′32″W" <comment>--ellipsoid=WGS72 --mi</comment>
EOT
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ellipsoid = Ellipsoid::createFromName($input->getOption('ellipsoid'));
$from = new Coordinate($input->getArgument('origin'), $ellipsoid);
$to = new Coordinate($input->getArgument('destination'), $ellipsoid);
$geotools = new Geotools;
$distance = $geotools->distance()->setFrom($from)->setTo($to);
if ($input->getOption('km')) {
$distance->in('km');
}
if ($input->getOption('mi')) {
$distance->in('mi');
}
if ($input->getOption('ft')) {
$distance->in('ft');
}
$output->writeln(sprintf('<value>%s</value>', $distance->vincenty()));
return 0;
}
}