|
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\Geohash; |
|
13
|
|
|
|
|
14
|
|
|
use League\Geotools\Coordinate\Coordinate; |
|
15
|
|
|
use League\Geotools\Geohash\Geohash; |
|
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 geohash:encode class |
|
24
|
|
|
* |
|
25
|
|
|
* @author Antoine Corcy <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class Encode extends \Symfony\Component\Console\Command\Command |
|
28
|
|
|
{ |
|
29
|
6 |
|
protected function configure() |
|
30
|
|
|
{ |
|
31
|
|
|
$this |
|
32
|
6 |
|
->setName('geohash:encode') |
|
33
|
6 |
|
->setDescription('Encode a coordinate to a geo hash string, the length is 12 by default') |
|
34
|
6 |
|
->addArgument('coordinate', InputArgument::REQUIRED, 'The "Lat,Long" coordinate to encode') |
|
35
|
6 |
|
->addOption('length', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_OPTIONAL, |
|
36
|
6 |
|
sprintf('If set, the length between %s and %s of the encoded coordinate', Geohash::MIN_LENGTH, |
|
37
|
6 |
|
Geohash::MAX_LENGTH), 12) |
|
38
|
6 |
|
->setHelp(<<<EOT |
|
39
|
6 |
|
<info>Example</info>: %command.full_name% "40° 26.7717, -79° 56.93172" <comment>--length=3</comment> |
|
40
|
|
|
EOT |
|
41
|
|
|
); |
|
42
|
6 |
|
} |
|
43
|
|
|
|
|
44
|
5 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
45
|
|
|
{ |
|
46
|
5 |
|
$coordinate = new Coordinate($input->getArgument('coordinate')); |
|
47
|
4 |
|
$geotools = new Geotools; |
|
48
|
|
|
|
|
49
|
4 |
|
$output->writeln(sprintf( |
|
50
|
4 |
|
'<value>%s</value>', |
|
51
|
4 |
|
$geotools->geohash()->encode($coordinate, $input->getOption('length'))->getGeohash() |
|
52
|
|
|
)); |
|
53
|
2 |
|
return 0; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|