Advertisement
Guest User

Untitled

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