Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "mapscanner.h"
- #include "scanner.h"
- #include <QtCore/QtMath>
- #include <QEventLoop>
- //Для z=17 4820 326.97
- //Для z=18 2415 161.09
- //https://static-maps.yandex.ru/1.x/?ll=30.3607,59.9280982&size=256,256&z=17&l=sat&pt=37.620070,55.753630,~30.3607,59.9280982,pmblm99,~30.3607,59.9280692,pmorm99
- //https://maps.googleapis.com/maps/api/staticmap?center=59.9280982,30.3661&zoom=17&maptype=satellite&size=256x256&markers=color:red%7C59.9280982,30.3661&scale=2key=
- //http://dev.virtualearth.net/REST/V1/Imagery/Map/Aerial/59.9280982%2C30.3661/17?mapSize=256,256&imagerySet=AerialWithLabels&format=png&pushpin=59.9280982,30.3661;60;&key=Ah12kIOAYzmW3ONiCcYEImWIp2xL8pwMXEvlOjhzjLRhjBBOCgBygJe4PHOY_aKU
- #define _CRT_SECURE_NO_WARNINGS
- double eps = sqrt(pow(6378, 2) - pow(6356, 2)) / (6378);
- double Delta = 0.002746368;
- int number = 0;
- bool bag = true;
- int CountWidth = -1;
- int CountHeight = 0;
- int n, m;
- int j = 0, i = 0;
- MapScanner::MapScanner(QWidget *parent)
- : QDialog(parent), m_renderPixmap(2048, 2048)
- {
- ui.setupUi(this);
- m_View->setGeometry(1000, 500, ui.SizeX->text().toFloat(), ui.SizeY->text().toFloat());
- m_Timer = new QTimer();
- connect(ui.MyButton, &QPushButton::clicked, [&]()
- {
- PushCoordinates();
- StartProgramm();
- });
- m_Timer->setSingleShot(true);
- connect(m_Timer, &QTimer::timeout, [&]()
- {
- DownloadMap();
- SaveImages();
- Work();
- });
- }
- MapScanner::~MapScanner()
- {
- }
- void MapScanner::Work()
- {
- double w = ui.EarthWidth->text().toDouble();
- double w2 = ui.EarthWidth2->text().toDouble();
- double k = ui.EarthHeight->text().toDouble();
- double k2 = ui.EarthHeight2->text().toDouble();
- double kRad = k / 180 * M_PI;
- double kdelta = Delta*(0.5*cos(kRad)*(pow(eps, 2)* (cos(2 * kRad) - 1) + 2)) / (1);
- if (i < m)
- {
- if (j < n)
- {
- if (i % 2 == 0)
- {
- w = RightStep(w, w2);
- j++;
- bag = true;
- }
- else
- {
- w = LeftStep(w, w2);
- j++;
- bag = false;
- }
- }
- else
- {
- k = DownStep(w, w2, k, k2, kdelta);
- i++;
- j = 0;
- }
- m_Timer->start(2500);
- }
- else
- {
- m_Timer->stop();
- m_View->close();
- }
- }
- double MapScanner::RightStep(double a, double b)
- {
- a += Delta;
- ui.EarthWidth->setText(QString::number(a));
- number++;
- CountWidth++;
- return a;
- }
- double MapScanner::LeftStep(double a, double b)
- {
- a -= Delta;
- ui.EarthWidth->setText(QString::number(a));
- number++;
- CountWidth--;
- return a;
- }
- double MapScanner::DownStep(double w, double w2,double a, double b,double delta)
- {
- a -= delta;
- ui.EarthHeight->setText(QString::number(a));
- if (bag)
- {
- w -= 2 * Delta;
- ui.EarthWidth->setText(QString::number(w));
- }
- else
- {
- w += 2 * Delta;
- ui.EarthWidth->setText(QString::number(w));
- }
- number++;
- CountHeight++;
- return a;
- }
- int MapScanner::CountI(double a, double b)
- {
- int l = ((abs(a - b)) + 2 * Delta*(ui.LineSize->text().toDouble()) / 326.97) / Delta;
- return l;
- }
- int MapScanner::CountJ(double a, double b)
- {
- double kRad = a / 180 * M_PI;
- double delta = Delta*(0.5*cos(kRad)*(pow(eps, 2)* (cos(2 * kRad) - 1) + 2)) / (1);
- int l = (abs(a - b) + 2 * delta*(ui.LineSize->text().toDouble()) / 326.97) / Delta;
- return l;
- }
- void MapScanner::StartProgramm()
- {
- double w = ui.EarthWidth->text().toDouble();
- double w2 = ui.EarthWidth2->text().toDouble();
- n = CountI(w, w2);
- double k = ui.EarthHeight->text().toDouble();
- double k2 = ui.EarthHeight2->text().toDouble();
- m = CountJ(k, k2);
- QPixmap pix(2048, 2048);
- pix.save(ui.SavePath->text() + "newfile.png");
- m_Timer->start(1);
- }
- void MapScanner::SaveImages()
- {
- QPixmap pic(m_View->size());
- m_View->show();
- m_View->render(&pic);
- pic.save(ui.SavePath->text() + "img" + QString::number(number) + ".png");
- m_renderPixmap.load(ui.SavePath->text() + "newfile.png"); // создаём картинку
- QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
- p.drawPixmap(256 * CountWidth, 256 * CountHeight, QPixmap(ui.SavePath->text() + "img" + QString::number(number) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
- p.end(); // завершаем работу рисовалки
- m_renderPixmap.save(ui.SavePath->text() + "newfile.png", "PNG"); // сохраняем файл
- }
- void MapScanner::PushCoordinates()
- {
- m_MassivHeight.push_back(ui.EarthHeight->text().toDouble());
- m_MassivWidth.push_back(ui.EarthWidth->text().toDouble());
- m_MassivHeight.push_back(ui.EarthHeight2->text().toDouble());
- m_MassivWidth.push_back(ui.EarthWidth2->text().toDouble());
- }
- void MapScanner::DownloadMap()
- {
- int c = 0;
- c = CheckDot(ui.EarthHeight->text().toDouble(), ui.EarthWidth->text().toDouble());
- QUrl UrlYandex;
- QUrl UrlGoodle;
- QUrl UrlBing;
- if (c != -1)
- {
- //UrlYandex = "https://static-maps.yandex.ru/1.x/?ll=" + ui.EarthWidth->text() + ',' + ui.EarthHeight->text() + "&size=" + ui.SizeX->text() + ',' + ui.SizeY->text() + "&z=17&l=sat&pt=37.620070,55.753630,pmwtm1~37.64,55.76363,pmwtm99";
- UrlYandex = "https://static-maps.yandex.ru/1.x/?ll=" + ui.EarthWidth->text() + ',' + ui.EarthHeight->text() + "&size=" + ui.SizeX->text() + ',' + ui.SizeY->text() + "&z=17&l=sat&pt=37.620070,55.753630,~" + QString::number(m_MassivWidth[c]) + "," + QString::number(m_MassivHeight[c]) + ",pmblm";
- UrlGoodle = "https://maps.googleapis.com/maps/api/staticmap?center=" + ui.EarthHeight->text() + ',' + ui.EarthWidth->text() + "&zoom=17&maptype=satellite&size=" + ui.SizeX->text() + 'x' + ui.SizeY->text() + "&scale=2key=";
- UrlBing = "http://dev.virtualearth.net/REST/V1/Imagery/Map/Aerial/" + ui.EarthHeight->text() + "%2C" + ui.EarthWidth->text() + "/17?mapSize=" + ui.SizeX->text() + ',' + ui.SizeY->text() + "&imagerySet=AerialWithLabels&format=png&key=Ah12kIOAYzmW3ONiCcYEImWIp2xL8pwMXEvlOjhzjLRhjBBOCgBygJe4PHOY_aKU";
- }
- else
- {
- UrlYandex = "https://static-maps.yandex.ru/1.x/?ll=" + ui.EarthWidth->text() + ',' + ui.EarthHeight->text() + "&size=" + ui.SizeX->text() + ',' + ui.SizeY->text() + "&z=17&l=sat&pt=37.620070,55.753630,pmwtm1~37.64,55.76363,pmwtm99";
- UrlGoodle = "https://maps.googleapis.com/maps/api/staticmap?center=" + ui.EarthHeight->text() + ',' + ui.EarthWidth->text() + "&zoom=17&maptype=satellite&size=" + ui.SizeX->text() + 'x' + ui.SizeY->text() + "&scale=2key=";
- UrlBing = "http://dev.virtualearth.net/REST/V1/Imagery/Map/Aerial/" + ui.EarthHeight->text() + "%2C" + ui.EarthWidth->text() + "/17?mapSize=" + ui.SizeX->text() + ',' + ui.SizeY->text() + "&imagerySet=AerialWithLabels&format=png&key=Ah12kIOAYzmW3ONiCcYEImWIp2xL8pwMXEvlOjhzjLRhjBBOCgBygJe4PHOY_aKU";
- }
- ui.lineEdit->setText(QString::number(c));
- if (ui.GoogleUrl->isChecked())
- m_View->load(QUrl(UrlGoodle));
- if (ui.YandexUrl->isChecked())
- m_View->load(QUrl(UrlYandex));
- if (ui.BingUrl->isChecked())
- m_View->load(QUrl(UrlBing));
- }
- int MapScanner::CheckDot(double a, double b)
- {
- for (int count = 0; count < m_MassivWidth.size(); count++)
- if (((a - (Delta / 2)) <= m_MassivHeight[count]) && ((a + (Delta / 2)) >= m_MassivHeight[count])
- && ((b - (Delta / 2)) <= m_MassivWidth[count]) && ((b + (Delta / 2)) >= m_MassivWidth[count]))
- return count;
- else return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement