setName('eclipse:convert-cloud-maps') // the short description shown while running "php bin/console list" ->setDescription('Convert cloud maps') // the full command description shown when running the command with // the "--help" option ->setHelp("This command allows you to create users..."); } /** * Execute command * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $this->createCloudMapColor($input, $output); $this->createCloudMapColorMercator($input, $output); // $this->createBigMap($input, $output); } /** * Create big tile * @param InputInterface $input * @param OutputInterface $output */ private function createBigMap(InputInterface $input, OutputInterface $output) { $fileName = __DIR__ . '/../../../files/bigTile.png'; $sourceFile = __DIR__ . '/../../../files/bigTile_4_0_0.jpg'; $srcImage = imagecreatefromjpeg($sourceFile); $image = imagecreatetruecolor(3600, 1800); $height = 4096; $width = 4096; for ($y = 0; $y < 1800; $y++) { $lat = 90 - $y / 10; $n = log(tan(M_PI / 4 + deg2rad($lat / 2))); $dy = $height / 2 - $width * $n / (2 * M_PI); $dy = round($dy); if ($dy < 0) { $dy = 0; } if ($dy > $height) { $dy = $height -1; } $output->writeln('Y: ' . $y); for ($x = 0; $x < 3600; $x++) { $dx = round($width / 3600 * $x); $color = imagecolorat($srcImage, $dx, $dy); imagesetpixel($image, $x, $y, $color); } } imagepng($image, $fileName); } /** * Create cloud map color * @param InputInterface $input * @param OutputInterface $output */ private function createCloudMapColor(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); /** @var CloudCoverageHelper $cloudCoverageHelper */ $cloudCoverageHelper = $container->get('app.cloud_coverage_helper'); $date = new \DateTime('2000-01-01'); for ($i = 0; $i <= 366; $i++) { $dateStr = $date->format('Y-m-d'); $MD = $date->format('m-d'); // Check if source file exists $srcFile = __DIR__ . '/../../../files/cloudMaps/default/cloudmap_' . $MD . '.png'; if (!file_exists($srcFile)) { $output->writeln('Skip ' . $MD . ' - File not found'); $date->add(new \DateInterval('P1D')); continue; } $fileName = __DIR__ . '/../../../files/cloudMaps/color/cloudmap_' . $MD . '.png'; if (file_exists($fileName)) { $date->add(new \DateInterval('P1D')); continue; } $output->writeln('Process cloudMapColor ' . $dateStr); $image = imagecreatetruecolor(3600, 1800); $draw = new \ImagickDraw(); for ($y = 0; $y <= 1800; $y++) { $output->writeln('Y: ' . $y); for ($x = 0; $x <= 3600; $x++) { $cloudCoverage = $cloudCoverageHelper->getCloudCoverageXY($x, $y, $dateStr); $rgb = $this->getColor($cloudCoverage); $color = imagecolorallocate($image, $rgb['r'], $rgb['g'], $rgb['b']); imagesetpixel($image, $x, $y, $color); } } imagepng($image, $fileName); $date->add(new \DateInterval('P1D')); } } /** * @param InputInterface $input * @param OutputInterface $output */ private function createCloudMapColorMercator(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); /** @var CloudCoverageHelper $cloudCoverageHelper */ $cloudCoverageHelper = $container->get('app.cloud_coverage_helper'); $date = new \DateTime('2000-01-01'); for ($i = 0; $i <= 366; $i++) { $dateStr = $date->format('Y-m-d'); $MD = $date->format('m-d'); // Check if source file exists $srcFile = __DIR__ . '/../../../files/cloudMaps/default/cloudmap_' . $MD . '.png'; if (!file_exists($srcFile)) { $output->writeln('Skip ' . $MD . ' - File not found'); $date->add(new \DateInterval('P1D')); continue; } $fileName = __DIR__ . '/../../../files/cloudMaps/color_mercator/cloudmap_' . $MD . '.png'; if (file_exists($fileName)) { $date->add(new \DateInterval('P1D')); continue; } $output->writeln('Process cloudMapColorMercator' . $dateStr); $image = imagecreatetruecolor(3600, 3600); for ($y = 0; $y <= 3600; $y++) { $output->writeln('Y: ' . $y); $n = ((1800 - $y) * (2 * M_PI)) / 3600; $lat = atan(exp($n)) * 2 - M_PI / 2; $dY = (90 - rad2deg($lat)) * 10; for ($x = 0; $x <= 3600; $x++) { $cloudCoverage = $cloudCoverageHelper->getCloudCoverageXY($x, $dY, $dateStr); $rgb = $this->getColor($cloudCoverage); $color = imagecolorallocate($image, $rgb['r'], $rgb['g'], $rgb['b']); imagesetpixel($image, $x, $y, $color); } } imagepng($image, $fileName); $date->add(new \DateInterval('P1D')); } die("D"); } /** * Get color * @param $cloudCoverage * @return array */ private function getColor($cloudCoverage) { if ($cloudCoverage < 0) { return array('r' => 0, 'g' => 0, 'b' => 0); } $colors = array( array( 'percent' => 0.0, 'r' => 115, 'g' => 166, 'b' => 244 ), array( 'percent' => 0.25, 'r' => 132, 'g' => 204, 'b' => 118 ), array( 'percent' => 0.50, 'r' => 237, 'g' => 231, 'b' => 120 ), array( 'percent' => 0.75, 'r' => 234, 'g' => 182, 'b' => 84 ), array( 'percent' => 1.0, 'r' => 226, 'g' => 104, 'b' => 104 ), ); $key = 0; foreach ($colors as $key => $color) { $percent = $color['percent']; if ($cloudCoverage <= $percent) { break; } } if ($key == 0) { $key++; } $color1 = $colors[$key - 1]; $color2 = $colors[$key]; $percent = ($cloudCoverage - $color1['percent']) / ($color2['percent'] - $color1['percent']); $r = $color1['r'] + $percent * ($color2['r'] - $color1['r']); $g = $color1['g'] + $percent * ($color2['g'] - $color1['g']); $b = $color1['b'] + $percent * ($color2['b'] - $color1['b']); return array( 'r' => $r, 'g' => $g, 'b' => $b, ); } }