Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include "mapscanner.h"
  3. #include "scanner.h"
  4. #include <QtCore/QtMath>
  5.  
  6. //Для z=17 4820 326.97
  7. //Для z=18 2415 161.09
  8.  
  9. //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
  10. //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=
  11. //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
  12. #define _CRT_SECURE_NO_WARNINGS
  13.  
  14. double eps = sqrt(pow(6378, 2) - pow(6356, 2)) / (6378);
  15. double Delta = 0.002746368;
  16. int number = 0;
  17. bool bag = true;
  18. int CountWidth = 0;
  19. int CountHeight = -1;
  20. int n, m;
  21. int j = 0, i = 0;
  22.  
  23. MapScanner::MapScanner(QWidget *parent)
  24.     : QDialog(parent)
  25. {
  26.     ui.setupUi(this);
  27.  
  28.     m_ViewYandex->setGeometry(1000, 500, ui.SizeX->text().toFloat(), ui.SizeY->text().toFloat());
  29.     m_ViewGoogle->setGeometry(1000, 300, ui.SizeX->text().toFloat(), ui.SizeY->text().toFloat());
  30.     m_ViewBing->setGeometry(1000, 100, ui.SizeX->text().toFloat(), ui.SizeY->text().toFloat());
  31.     m_Timer = new QTimer();
  32.  
  33.     connect(ui.MyButton, &QPushButton::clicked, [&]()
  34.     {
  35.         PushCoordinates();
  36.         StartProgramm();
  37.     });
  38.  
  39.     m_Timer->setSingleShot(true);
  40.  
  41.     connect(m_Timer, &QTimer::timeout, [&]()
  42.     {
  43.         DownloadMap();
  44.         Work();
  45.     });
  46.  
  47. }
  48. MapScanner::~MapScanner()
  49. {
  50.    
  51. }
  52.  
  53. void MapScanner::Work()
  54. {
  55.     double w = ui.EarthWidth->text().toDouble();
  56.     double w2 = ui.EarthWidth2->text().toDouble();
  57.  
  58.     double k = ui.EarthHeight->text().toDouble();
  59.     double k2 = ui.EarthHeight2->text().toDouble();
  60.     double kRad = k / 180 * M_PI;
  61.     double kdelta = Delta*(0.5*cos(kRad)*(pow(eps, 2)* (cos(2 * kRad) - 1) + 2)) / (1);
  62.  
  63.  
  64.     if (j < n)
  65.     {
  66.         if (i < m + 1)
  67.         {
  68.             if (j % 2 == 0)
  69.             {
  70.                 k = DownStep(k,kdelta);
  71.                 bag = true;
  72.             }
  73.             else
  74.             {
  75.                 k = UpStep(k, kdelta);
  76.                 bag = false;
  77.             }
  78.             i++;
  79.         }
  80.         else
  81.         {
  82.             k = RightStep(w, k, kdelta);
  83.             j++;
  84.             i = 0;
  85.         }
  86.         if (ui.BingUrl->isChecked())
  87.             m_Timer->start(15000);
  88.         else
  89.             m_Timer->start(1500);
  90.         number++;
  91.     }
  92.     else
  93.     {
  94.         m_Timer->stop();
  95.         m_ViewBing->close();
  96.         m_ViewGoogle->close();
  97.         m_ViewYandex->close();
  98.     }
  99. }
  100.  
  101. double MapScanner::RightStep(double a, double k, double kdelta)
  102. {
  103.     a += Delta;
  104.     ui.EarthWidth->setText(QString::number(a));
  105.     CountWidth++;
  106.     if (bag)
  107.         k += 2 * kdelta;
  108.     else
  109.         k -= 2 * kdelta;
  110.     ui.EarthHeight->setText(QString::number(k));
  111.     return a;
  112. }
  113. double MapScanner::DownStep(double a,double kdelta)
  114. {
  115.     a -= kdelta;
  116.     ui.EarthHeight->setText(QString::number(a));
  117.     CountHeight++;
  118.     return a;
  119. }
  120. double MapScanner::UpStep(double a, double kdelta)
  121. {
  122.     a += kdelta;
  123.     ui.EarthHeight->setText(QString::number(a));
  124.     CountHeight--;
  125.     return a;
  126. }
  127.  
  128. int MapScanner::CountI(double a, double b)
  129. {
  130.     double SizeImage = 1.2772265625 * ui.SizeX->text().toDouble();
  131.     int l = ((abs(a - b)) + 2 * Delta*(ui.LineSize->text().toDouble()) / SizeImage) / Delta;
  132.     return l;
  133. }
  134. int MapScanner::CountJ(double a, double b)
  135. {
  136.     double kRad = a / 180 * M_PI;
  137.     double delta = Delta*(0.5*cos(kRad)*(pow(eps, 2)* (cos(2 * kRad) - 1) + 2)) / (1);
  138.     double SizeImage = 1.2772265625 * ui.SizeX->text().toDouble();
  139.     int l = (abs(a - b) + 2 * delta*(ui.LineSize->text().toDouble()) / SizeImage) / Delta;
  140.     return l+1;
  141. }
  142.  
  143. void MapScanner::StartProgramm()
  144. {
  145.     QDir().mkdir("D:/Projects/MapScanner/MapScanner/" + ui.SavePath->text() + '/');
  146.     QDir().mkdir("D:/Projects/MapScanner/MapScanner/" + ui.SavePath->text() + "/Yandex/");
  147.     QDir().mkdir("D:/Projects/MapScanner/MapScanner/" + ui.SavePath->text() + "SaveImages/Google/");
  148.     QDir().mkdir("D:/Projects/MapScanner/MapScanner/" + ui.SavePath->text() + "SaveImages/Bing/");
  149.  
  150.     double w = ui.EarthWidth->text().toDouble();
  151.     double w2 = ui.EarthWidth2->text().toDouble();
  152.     n = CountI(w, w2);
  153.  
  154.     double k = ui.EarthHeight->text().toDouble();
  155.     double k2 = ui.EarthHeight2->text().toDouble();
  156.  
  157.     m = CountJ(k, k2);
  158.     ui.lineEdit->setText(QString::number(n) + QString::number(m));
  159.     QPixmap pix(ui.SizeX->text().toFloat() * n, ui.SizeY->text().toFloat() * m);
  160.     pix.save(ui.SavePath->text() + "Google/newfile.png");
  161.     pix.save(ui.SavePath->text() + "Yandex/newfile.png");
  162.     pix.save(ui.SavePath->text() + "Bing/newfile.png");
  163.     m_Timer->start(1);
  164. }
  165. void MapScanner::PushCoordinates()
  166. {
  167.     m_MassivHeight.push_back(ui.EarthHeight->text().toDouble());
  168.     m_MassivWidth.push_back(ui.EarthWidth->text().toDouble());
  169.  
  170.     m_MassivWidth.push_back(46.031060);
  171.     m_MassivHeight.push_back(51.533812);
  172.  
  173.     m_MassivHeight.push_back(ui.EarthHeight2->text().toDouble());
  174.     m_MassivWidth.push_back(ui.EarthWidth2->text().toDouble());
  175. }
  176.  
  177. void MapScanner::DownloadMap()
  178. {
  179.     double w = ui.EarthWidth->text().toDouble();
  180.     double k = ui.EarthHeight->text().toDouble();
  181.     double kRad = k / 180 * M_PI;
  182.     double kdelta = Delta*(0.5*cos(kRad)*(pow(eps, 2)* (cos(2 * kRad) - 1) + 2)) / (1);
  183.     QUrl UrlYandex;
  184.     QUrl UrlGoodle;
  185.     QUrl UrlBing;
  186.    
  187.     if (ui.YandexUrl->isChecked())
  188.     {
  189.         UrlYandex = CheckDot(w, k, kdelta, 1);
  190.         m_ViewYandex->load(QUrl(UrlYandex));
  191.         SaveImagesYandex("Yandex/");
  192.     }
  193.     if (ui.GoogleUrl->isChecked())
  194.     {
  195.         UrlGoodle = CheckDot(w, k, kdelta, 2);
  196.         m_ViewGoogle->load(QUrl(UrlGoodle));
  197.         SaveImagesGoogle("Google/");
  198.     }
  199.     if (ui.BingUrl->isChecked())
  200.     {
  201.         UrlBing = CheckDot(w, k, kdelta, 3);
  202.         m_ViewBing->load(QUrl(UrlBing));
  203.         SaveImagesBing("Bing/");
  204.     }
  205. }
  206. QUrl MapScanner::CheckDot(double a, double b,double kdelta,int c)
  207. {
  208.     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" ;
  209.     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=";
  210.     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";
  211.     for (int count = 0; count < m_MassivWidth.size(); count++)
  212.     {
  213.             if (c == 1)
  214.                 UrlYandex = UrlYandex.toString() + ",~" + QString::number(m_MassivWidth[count]) + "," + QString::number(m_MassivHeight[count]) + ",pmbls";
  215.             if (c == 2)
  216.                 UrlGoodle = UrlGoodle.toString() + "&markers=color:red%7Csize:small%7C" + QString::number(m_MassivHeight[count]) + "," + QString::number(m_MassivWidth[count]) ;
  217.             if (c == 3)
  218.                 UrlBing = UrlBing.toString() + "&pushpin=" + QString::number(m_MassivHeight[count]) + "," + QString::number(m_MassivWidth[count]) + ";60";
  219.        
  220.     }
  221.     if (c == 1)
  222.         return UrlYandex;
  223.     else if (c == 2)
  224.         return UrlGoodle;
  225.     else return UrlBing;
  226. }
  227.  
  228. void MapScanner::SaveImagesYandex(QString path)
  229. {
  230.     QPixmap pic(m_ViewYandex->size());
  231.     m_ViewYandex->show();
  232.     m_ViewYandex->render(&pic);
  233.     pic.save(ui.SavePath->text() + path + "img" + QString::number(number) + ".png");
  234.  
  235.     m_renderPixmap.load(ui.SavePath->text() + path + "newfile.png"); // создаём картинку
  236.     QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
  237.     p.drawPixmap(ui.SizeX->text().toFloat() * CountWidth, ui.SizeY->text().toFloat() * CountHeight, QPixmap(ui.SavePath->text() + path + "img" + QString::number(number) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
  238.     p.end(); // завершаем работу рисовалки
  239.     m_renderPixmap.save(ui.SavePath->text() + path + "newfile.png", "PNG"); // сохраняем файл
  240. }
  241. void MapScanner::SaveImagesGoogle(QString path)
  242. {
  243.     QPixmap pic(m_ViewGoogle->size());
  244.     m_ViewGoogle->show();
  245.     m_ViewGoogle->render(&pic);
  246.     pic.save(ui.SavePath->text() + path + "img" + QString::number(number) + ".png");
  247.  
  248.     m_renderPixmap.load(ui.SavePath->text() + path + "newfile.png"); // создаём картинку
  249.     QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
  250.     p.drawPixmap(ui.SizeX->text().toFloat() * CountWidth, ui.SizeY->text().toFloat() * CountHeight, QPixmap(ui.SavePath->text() + path + "img" + QString::number(number) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
  251.     p.end(); // завершаем работу рисовалки
  252.     m_renderPixmap.save(ui.SavePath->text() + path + "newfile.png", "PNG"); // сохраняем файл
  253. }
  254. void MapScanner::SaveImagesBing(QString path)
  255. {
  256.     QPixmap pic(m_ViewBing->size());
  257.     m_ViewBing->show();
  258.     m_ViewBing->render(&pic);
  259.     pic.save(ui.SavePath->text() + path + "img" + QString::number(number) + ".png");
  260.  
  261.     m_renderPixmap.load(ui.SavePath->text() + path + "newfile.png"); // создаём картинку
  262.     QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
  263.     p.drawPixmap(ui.SizeX->text().toFloat() * CountWidth, ui.SizeY->text().toFloat() * CountHeight, QPixmap(ui.SavePath->text() + path + "img" + QString::number(number) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
  264.     p.end(); // завершаем работу рисовалки
  265.     m_renderPixmap.save(ui.SavePath->text() + path + "newfile.png", "PNG"); // сохраняем файл
  266. }
  267.  
  268.  
  269. //////////////////////////////////////////////////////////////////////////////////////////////
  270. #ifndef MAPSCANNER_H
  271. #define MAPSCANNER_H
  272.  
  273. #include <QtWidgets>
  274. #include <QtWebEngineWidgets/QtWebEngineWidgets>
  275. #include <QWebEngineView>
  276. #include <QPixmap>
  277. #include <QtNetwork/QNetworkAccessManager>
  278. #include <QNetworkReply>
  279. #include <QTimer>
  280. #include <QString>
  281. #include <QVector>
  282. #include <QDir>
  283.  
  284. #include "ui_mapscanner.h"
  285.  
  286. class MapScanner : public QDialog
  287. {
  288.     Q_OBJECT
  289.  
  290. public:
  291.     MapScanner(QWidget *parent = 0);
  292.     ~MapScanner();
  293.  
  294. protected:
  295.     QWebEngineView *m_ViewYandex = new QWebEngineView();
  296.     QWebEngineView *m_ViewGoogle = new QWebEngineView();
  297.     QWebEngineView *m_ViewBing = new QWebEngineView();
  298.     QPixmap *m_Image;
  299.     QPixmap m_renderPixmap;
  300.     QTimer *m_Timer = new QTimer();
  301.     QVector <double> m_MassivHeight;
  302.     QVector <double> m_MassivWidth;
  303.  
  304.  
  305.  
  306.     void Work();//бегаем по карте
  307.     void SaveImagesGoogle(QString);//рендерим и сохраняем
  308.     void SaveImagesYandex(QString);//рендерим и сохраняем
  309.     void SaveImagesBing(QString);//рендерис и сохраняем
  310.     void DownloadMap();//загружаем карту
  311.     void StartProgramm();//всякие нужные вещи
  312.     void PushCoordinates();//загружаем координаты в массив
  313.  
  314.     double RightStep(double,double,double);//идем вправо
  315.     double DownStep(double, double);//идём вниз
  316.     double UpStep(double, double);//идём всё выше, выше и выыыыыше
  317.  
  318.     int CountI(double,double);//считаем количество снимков по ширине
  319.     int CountJ(double, double);//считаем количество снимков по высоте
  320.  
  321.     QUrl CheckDot(double,double,double,int);//должна смотреть, входит точка маршрута на наш снимок, или нет
  322. private:
  323.     Ui::MapScannerClass ui;
  324.  
  325.  
  326. };
  327.  
  328. #endif // MAPSCANNER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement