Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
86
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. #include <QEventLoop>
  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 check = 0;
  17. bool bag = true;
  18. int CountWidth = -1;
  19. int CountHeight = 0;
  20. int n, m;
  21. int j, i;
  22. MapScanner::MapScanner(QWidget *parent)
  23.     : QDialog(parent), m_renderPixmap(2048, 2048)
  24. {
  25.     ui.setupUi(this);
  26.  
  27.    
  28.     QPixmap pix(2048, 2048);
  29.     pix.save(ui.SavePath->text() + "newfile.png");
  30.  
  31.     m_View = new QWebEngineView();
  32.     m_View->setGeometry(1000, 500, ui.SizeX->text().toFloat(), ui.SizeY->text().toFloat());
  33.     m_Timer = new QTimer();
  34.  
  35.     connect(ui.MyButton, &QPushButton::clicked, [&]()
  36.     {
  37.         m_Timer->start(1);
  38.     });
  39.  
  40.     m_Timer->setSingleShot(true);
  41.  
  42.     connect(m_Timer, &QTimer::timeout, [&]()
  43.     {
  44.         DownloadMap();
  45.         SaveImages();
  46.         Work();
  47.     });
  48. }
  49. MapScanner::~MapScanner()
  50. {
  51.    
  52. }
  53.  
  54. void MapScanner::Work()
  55. {
  56.     double k = ui.EarthHeight->text().toDouble();
  57.     double k2 = ui.EarthHeight2->text().toDouble();
  58.     double kRad = k / 180 * M_PI;
  59.     double kdelta = Delta*(0.5*cos(kRad)*(pow(eps, 2)* (cos(2 * kRad) - 1) + 2)) / (1);
  60.  
  61.     double w = ui.EarthWidth->text().toDouble();
  62.     double w2 = ui.EarthWidth2->text().toDouble();
  63.     n = CountI(w, w2);
  64.     m = CountJ(k, k2, kdelta);
  65.     if (j < m)
  66.     {
  67.         if (j % 2 == 0)
  68.         {
  69.             if (i < n)
  70.                 w = RightStep(w, w2);
  71.             i++;
  72.         }
  73.         else if (i < n)
  74.         {
  75.             w = LeftStep(w, w2);
  76.             i++;
  77.         }
  78.         k = DownStep(k, k2, kdelta);
  79.         j++;
  80.     }
  81. }
  82.  
  83. double MapScanner::RightStep(double a, double b)
  84. {
  85.     a += Delta;
  86.     ui.EarthWidth->setText(QString::number(a));
  87.     check++;
  88.     CountWidth++;
  89.     m_Timer->start(2500);
  90.     return a;
  91. }
  92. double MapScanner::DownStep(double a, double b,double delta)
  93. {
  94.     a -= delta;
  95.     ui.EarthHeight->setText(QString::number(a));
  96.     check++;
  97.     CountHeight++;
  98.     m_Timer->start(2500);
  99.     return a;
  100. }
  101. double MapScanner::LeftStep(double a, double b)
  102. {
  103.     a -= Delta;
  104.     ui.EarthWidth->setText(QString::number(a));
  105.     check++;
  106.     CountWidth--;
  107.     m_Timer->start(2500);
  108.     return a;
  109. }
  110. int MapScanner::CountI(double a, double b)
  111. {
  112.     int l = ((abs(a - b)) + 2 * Delta*(ui.LineSize->text().toDouble()) / 326.97) / Delta;
  113.     return l;
  114. }
  115. int MapScanner::CountJ(double a, double b,double delta)
  116. {
  117.     int l = (abs(a - b) + 2 * delta*(ui.LineSize->text().toDouble()) / 326.97) / Delta;
  118.     return l;
  119. }
  120. void MapScanner::DownloadMap()
  121. {
  122.     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,pmwtm1~37.64,55.76363,pmwtm99");
  123.     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=");
  124.     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");
  125.  
  126.     if (ui.GoogleUrl->isChecked())
  127.         m_View->load(QUrl(UrlGoodle));
  128.     if (ui.YandexUrl->isChecked())
  129.         m_View->load(QUrl(UrlYandex));
  130.     if (ui.BingUrl->isChecked())
  131.         m_View->load(QUrl(UrlBing));
  132. }
  133. void MapScanner::SaveImages()
  134. {
  135.     QPixmap pic(m_View->size());
  136.     m_View->show();
  137.     m_View->render(&pic);
  138.     pic.save(ui.SavePath->text() + "img" + QString::number(check) + ".png");
  139.  
  140.     //ui.lineEdit->setText(QString::number(n) + QString::number(m));
  141.  
  142.     m_renderPixmap.load(ui.SavePath->text() + "newfile.png"); // создаём картинку
  143.     QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
  144.     p.drawPixmap(256 * CountWidth, 256 * CountHeight, QPixmap(ui.SavePath->text() + "img" + QString::number(check) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
  145.     p.end(); // завершаем работу рисовалки
  146.     m_renderPixmap.save(ui.SavePath->text() + "newfile.png", "PNG"); // сохраняем файл
  147. }
  148.  
  149. void MapScanner::LoadMaps()
  150. {
  151.    
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement