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>
- //Для 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 = 0;
- int CountHeight = -1;
- int n, m;
- int j = 0, i = 0;
- MapScanner::MapScanner(QWidget *parent)
- : QDialog(parent)
- {
- ui.setupUi(this);
- m_ViewYandex->setGeometry(1000, 500, ui.SizeX->text().toFloat(), ui.SizeY->text().toFloat());
- m_ViewGoogle->setGeometry(1000, 300, ui.SizeX->text().toFloat(), ui.SizeY->text().toFloat());
- m_ViewBing->setGeometry(1000, 100, 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();
- 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 (j < n)
- {
- if (i < m + 1)
- {
- if (j % 2 == 0)
- {
- k = DownStep(k,kdelta);
- bag = true;
- }
- else
- {
- k = UpStep(k, kdelta);
- bag = false;
- }
- i++;
- }
- else
- {
- k = RightStep(w, k, kdelta);
- j++;
- i = 0;
- }
- if (ui.BingUrl->isChecked())
- m_Timer->start(15000);
- else
- m_Timer->start(1500);
- number++;
- }
- else
- {
- m_Timer->stop();
- m_ViewBing->close();
- m_ViewGoogle->close();
- m_ViewYandex->close();
- }
- }
- double MapScanner::RightStep(double a, double k, double kdelta)
- {
- a += Delta;
- ui.EarthWidth->setText(QString::number(a));
- CountWidth++;
- if (bag)
- k += 2 * kdelta;
- else
- k -= 2 * kdelta;
- ui.EarthHeight->setText(QString::number(k));
- return a;
- }
- double MapScanner::DownStep(double a,double kdelta)
- {
- a -= kdelta;
- ui.EarthHeight->setText(QString::number(a));
- CountHeight++;
- return a;
- }
- double MapScanner::UpStep(double a, double kdelta)
- {
- a += kdelta;
- ui.EarthHeight->setText(QString::number(a));
- CountHeight--;
- return a;
- }
- int MapScanner::CountI(double a, double b)
- {
- double SizeImage = 1.2772265625 * ui.SizeX->text().toDouble();
- int l = ((abs(a - b)) + 2 * Delta*(ui.LineSize->text().toDouble()) / SizeImage) / 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);
- double SizeImage = 1.2772265625 * ui.SizeX->text().toDouble();
- int l = (abs(a - b) + 2 * delta*(ui.LineSize->text().toDouble()) / SizeImage) / Delta;
- return l+1;
- }
- void MapScanner::StartProgramm()
- {
- QDir().mkdir("D:/Projects/MapScanner/MapScanner/" + ui.SavePath->text() + '/');
- QDir().mkdir("D:/Projects/MapScanner/MapScanner/" + ui.SavePath->text() + "/Yandex/");
- QDir().mkdir("D:/Projects/MapScanner/MapScanner/" + ui.SavePath->text() + "SaveImages/Google/");
- QDir().mkdir("D:/Projects/MapScanner/MapScanner/" + ui.SavePath->text() + "SaveImages/Bing/");
- 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);
- ui.lineEdit->setText(QString::number(n) + QString::number(m));
- QPixmap pix(ui.SizeX->text().toFloat() * n, ui.SizeY->text().toFloat() * m);
- pix.save(ui.SavePath->text() + "Google/newfile.png");
- pix.save(ui.SavePath->text() + "Yandex/newfile.png");
- pix.save(ui.SavePath->text() + "Bing/newfile.png");
- m_Timer->start(1);
- }
- void MapScanner::PushCoordinates()
- {
- m_MassivHeight.push_back(ui.EarthHeight->text().toDouble());
- m_MassivWidth.push_back(ui.EarthWidth->text().toDouble());
- m_MassivWidth.push_back(46.031060);
- m_MassivHeight.push_back(51.533812);
- m_MassivHeight.push_back(ui.EarthHeight2->text().toDouble());
- m_MassivWidth.push_back(ui.EarthWidth2->text().toDouble());
- }
- void MapScanner::DownloadMap()
- {
- double w = ui.EarthWidth->text().toDouble();
- double k = ui.EarthHeight->text().toDouble();
- double kRad = k / 180 * M_PI;
- double kdelta = Delta*(0.5*cos(kRad)*(pow(eps, 2)* (cos(2 * kRad) - 1) + 2)) / (1);
- QUrl UrlYandex;
- QUrl UrlGoodle;
- QUrl UrlBing;
- if (ui.YandexUrl->isChecked())
- {
- UrlYandex = CheckDot(w, k, kdelta, 1);
- m_ViewYandex->load(QUrl(UrlYandex));
- SaveImagesYandex("Yandex/");
- }
- if (ui.GoogleUrl->isChecked())
- {
- UrlGoodle = CheckDot(w, k, kdelta, 2);
- m_ViewGoogle->load(QUrl(UrlGoodle));
- SaveImagesGoogle("Google/");
- }
- if (ui.BingUrl->isChecked())
- {
- UrlBing = CheckDot(w, k, kdelta, 3);
- m_ViewBing->load(QUrl(UrlBing));
- SaveImagesBing("Bing/");
- }
- }
- QUrl MapScanner::CheckDot(double a, double b,double kdelta,int c)
- {
- QUrl 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" ;
- QUrl 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=";
- QUrl 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";
- for (int count = 0; count < m_MassivWidth.size(); count++)
- {
- if (c == 1)
- UrlYandex = UrlYandex.toString() + ",~" + QString::number(m_MassivWidth[count]) + "," + QString::number(m_MassivHeight[count]) + ",pmbls";
- if (c == 2)
- UrlGoodle = UrlGoodle.toString() + "&markers=color:red%7Csize:small%7C" + QString::number(m_MassivHeight[count]) + "," + QString::number(m_MassivWidth[count]) ;
- if (c == 3)
- UrlBing = UrlBing.toString() + "&pushpin=" + QString::number(m_MassivHeight[count]) + "," + QString::number(m_MassivWidth[count]) + ";60";
- }
- if (c == 1)
- return UrlYandex;
- else if (c == 2)
- return UrlGoodle;
- else return UrlBing;
- }
- void MapScanner::SaveImagesYandex(QString path)
- {
- QPixmap pic(m_ViewYandex->size());
- m_ViewYandex->show();
- m_ViewYandex->render(&pic);
- pic.save(ui.SavePath->text() + path + "img" + QString::number(number) + ".png");
- m_renderPixmap.load(ui.SavePath->text() + path + "newfile.png"); // создаём картинку
- QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
- p.drawPixmap(ui.SizeX->text().toFloat() * CountWidth, ui.SizeY->text().toFloat() * CountHeight, QPixmap(ui.SavePath->text() + path + "img" + QString::number(number) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
- p.end(); // завершаем работу рисовалки
- m_renderPixmap.save(ui.SavePath->text() + path + "newfile.png", "PNG"); // сохраняем файл
- }
- void MapScanner::SaveImagesGoogle(QString path)
- {
- QPixmap pic(m_ViewGoogle->size());
- m_ViewGoogle->show();
- m_ViewGoogle->render(&pic);
- pic.save(ui.SavePath->text() + path + "img" + QString::number(number) + ".png");
- m_renderPixmap.load(ui.SavePath->text() + path + "newfile.png"); // создаём картинку
- QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
- p.drawPixmap(ui.SizeX->text().toFloat() * CountWidth, ui.SizeY->text().toFloat() * CountHeight, QPixmap(ui.SavePath->text() + path + "img" + QString::number(number) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
- p.end(); // завершаем работу рисовалки
- m_renderPixmap.save(ui.SavePath->text() + path + "newfile.png", "PNG"); // сохраняем файл
- }
- void MapScanner::SaveImagesBing(QString path)
- {
- QPixmap pic(m_ViewBing->size());
- m_ViewBing->show();
- m_ViewBing->render(&pic);
- pic.save(ui.SavePath->text() + path + "img" + QString::number(number) + ".png");
- m_renderPixmap.load(ui.SavePath->text() + path + "newfile.png"); // создаём картинку
- QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
- p.drawPixmap(ui.SizeX->text().toFloat() * CountWidth, ui.SizeY->text().toFloat() * CountHeight, QPixmap(ui.SavePath->text() + path + "img" + QString::number(number) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
- p.end(); // завершаем работу рисовалки
- m_renderPixmap.save(ui.SavePath->text() + path + "newfile.png", "PNG"); // сохраняем файл
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- #ifndef MAPSCANNER_H
- #define MAPSCANNER_H
- #include <QtWidgets>
- #include <QtWebEngineWidgets/QtWebEngineWidgets>
- #include <QWebEngineView>
- #include <QPixmap>
- #include <QtNetwork/QNetworkAccessManager>
- #include <QNetworkReply>
- #include <QTimer>
- #include <QString>
- #include <QVector>
- #include <QDir>
- #include "ui_mapscanner.h"
- class MapScanner : public QDialog
- {
- Q_OBJECT
- public:
- MapScanner(QWidget *parent = 0);
- ~MapScanner();
- protected:
- QWebEngineView *m_ViewYandex = new QWebEngineView();
- QWebEngineView *m_ViewGoogle = new QWebEngineView();
- QWebEngineView *m_ViewBing = new QWebEngineView();
- QPixmap *m_Image;
- QPixmap m_renderPixmap;
- QTimer *m_Timer = new QTimer();
- QVector <double> m_MassivHeight;
- QVector <double> m_MassivWidth;
- void Work();//бегаем по карте
- void SaveImagesGoogle(QString);//рендерим и сохраняем
- void SaveImagesYandex(QString);//рендерим и сохраняем
- void SaveImagesBing(QString);//рендерис и сохраняем
- void DownloadMap();//загружаем карту
- void StartProgramm();//всякие нужные вещи
- void PushCoordinates();//загружаем координаты в массив
- double RightStep(double,double,double);//идем вправо
- double DownStep(double, double);//идём вниз
- double UpStep(double, double);//идём всё выше, выше и выыыыыше
- int CountI(double,double);//считаем количество снимков по ширине
- int CountJ(double, double);//считаем количество снимков по высоте
- QUrl CheckDot(double,double,double,int);//должна смотреть, входит точка маршрута на наш снимок, или нет
- private:
- Ui::MapScannerClass ui;
- };
- #endif // MAPSCANNER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement