123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace GeoserverBundle\Command;
- use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Process\Process;
- use Symfony\Component\Process\Exception\ProcessFailedException;
- class GeoserverCommand extends ContainerAwareCommand
- {
- protected function configure()
- {
- $this
- ->setName('geoserver:test')
- ->setDescription('Geoserver test connection data')
- ->setHelp('This command allows test geoserver')
- ->setDefinition(array(
-
- ))
- ;
- }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $this->output = $output;
-
- if(!$this->getContainer()->getParameter('geoserver_service')) {
- $output->writeln(sprintf('<error>Geoserver Service false</error>',array()));
- return;
- }
- $path = $this->getContainer()->getParameter('geoserver_path_shapes');
- $host = $this->getContainer()->getParameter('geoserver_host');
- $port = $this->getContainer()->getParameter('geoserver_port');
- $user = $this->getContainer()->getParameter('geoserver_user');
- $pass = $this->getContainer()->getParameter('geoserver_pass');
- $this->output->writeln("<question>## CONFIG ##</question>");
- $this->output->writeln("geoserver_path_shapes: <info>$path</info>");
- $this->output->writeln("geoserver_host: <info>$host</info>");
- $this->output->writeln("geoserver_port: <info>$port</info>");
- $this->output->writeln("geoserver_user: <info>$user</info>");
- $this->output->writeln("geoserver_pass: <info>$pass</info>");
-
- $geoserver = $this->getContainer()->get('geoserver.api');
- $rest = $geoserver->getUrlRest();
-
- $this->output->writeln("");
- $this->output->writeln("<question>## URLS ##</question>");
- $this->output->writeln("REST: <info>$rest</info>");
- foreach(array("onuRxPower","onuRxPowerLabel","onuTxPower","onuTxPowerLabel","onuStatus","ponRxPowerLabel") as $k => $style) {
- $data = $geoserver->existResource($rest."/styles/{$style}.json");
- if($data) {
- $this->output->writeln("Style $style: <info>OK</info>");
- } else {
- $this->output->writeln("## Style $style: <error>Not found</error> ##");
- }
- }
-
-
- $file_name = "onu_stats_demo";
- $dir = "$path/demo";
-
- $this->output->writeln("");
- $this->output->writeln("<question>## TEST SERVICE ##</question>");
- if(!is_dir($dir)) {
- mkdir($dir, 0777, true);
- chown($dir, "www-data");
- chmod($dir, 0777);
- }
- $file = dirname(dirname(__FILE__))."/Resources/stats_demo.json";
- if(file_exists($file)) {
- copy($file, $dir."/".$file_name.".json");
- }
-
- $process = new Process("ogr2ogr -f 'ESRI Shapefile' {$dir}/{$file_name}.shp {$dir}/{$file_name}.json");
- $process->run();
- if (!$process->isSuccessful()) {throw new ProcessFailedException($process);}
- echo $process->getOutput();
- $this->output->writeln("Demo $dir");
- foreach(array("dbf","json","prj","shp","shx") as $k => $ext) {
- if(file_exists($dir."/".$file_name.".".$ext)) {
- chown($dir."/".$file_name.".".$ext, "www-data");
- $this->output->writeln("File {$file_name}.{$ext}: <info>OK</info>");
- } else {
- $this->output->writeln("File {$file_name}.{$ext}: <error>Not found</error>");
- }
- }
- $workspace = "demo";
- $this->output->writeln("<info>Create workspace demo</info>");
- $geoserver->createWorkspace($workspace);
- $this->output->writeln("<info>Update shapes in demo</info>");
- $geoserver->updateShape($workspace);
-
- $styles = array();
- foreach(array("onuRxPower","onuRxPowerLabel","onuTxPower","onuTxPowerLabel","onuStatus") as $k => $style)
- {
- $styles[] = "<style><name>{$style}</name><atom:link rel='alternate' href='{$rest}/styles/{$style}.xml' type='application/xml'/></style>";
- }
-
- $stylesXml = "<layer><styles class='linked-hash-set'>".implode("",$styles)."</styles></layer>";
-
- $rest = "layers/{$file_name}.xml";
- $this->output->writeln("<info>Set styles on shape demo</info>");
- $geoserver->putData($rest, $stylesXml);
-
- $this->output->writeln("");
- $url = $geoserver->getUrlWms("demo")."?service=WMS&version=1.1.0&request=GetMap&layers=demo:onu_stats_demo&styles=&bbox=-61.7008896,-33.1212889,-61.21277504,-32.01828173&width=339&height=768&srs=EPSG:4326&format=application/openlayers";
- $this->output->writeln("<question>## $url ##</question>");
- $this->output->writeln("<info>Fin</info>");
- // curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain" -d "file:/var/www/shapes/demo/" "http://geoserver.fd3.flowdat.com/geoserver/rest/workspaces/demo/datastores/shapefiles/external.shp?configure=all"
- }
- }
|