Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
84
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.  
  7. //Для z=17 4820 326.97
  8. //Для z=18 2415 161.09
  9.  
  10. //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
  11. //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=
  12. //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
  13. #define _CRT_SECURE_NO_WARNINGS
  14.  
  15. double eps = sqrt(pow(6378, 2) - pow(6356, 2)) / (6378);
  16. double Delta = 0.002746368;
  17. int number = 0;
  18. bool bag = true;
  19. int CountWidth = -1;
  20. int CountHeight = 0;
  21. int n, m;
  22. int j = 0, i = 0;
  23.  
  24. MapScanner::MapScanner(QWidget *parent)
  25.     : QDialog(parent), m_renderPixmap(2048, 2048)
  26. {
  27.     ui.setupUi(this);
  28.  
  29.     m_View->setGeometry(1000, 500, ui.SizeX->text().toFloat(), ui.SizeY->text().toFloat());
  30.     m_Timer = new QTimer();
  31.  
  32.     connect(ui.MyButton, &QPushButton::clicked, [&]()
  33.     {
  34.         PushCoordinates();
  35.         StartProgramm();
  36.     });
  37.  
  38.     m_Timer->setSingleShot(true);
  39.  
  40.     connect(m_Timer, &QTimer::timeout, [&]()
  41.     {
  42.         DownloadMap();
  43.         SaveImages();
  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.     if (i < m)
  64.     {
  65.         if (j < n)
  66.         {
  67.             if (i % 2 == 0)
  68.             {
  69.                 w = RightStep(w, w2);
  70.                 j++;
  71.                 bag = true;
  72.             }
  73.             else
  74.             {
  75.                 w = LeftStep(w, w2);
  76.                 j++;
  77.                 bag = false;
  78.             }
  79.         }
  80.         else
  81.         {
  82.             k = DownStep(w, w2, k, k2, kdelta);
  83.             i++;
  84.             j = 0;
  85.         }
  86.         m_Timer->start(2500);
  87.     }
  88.     else
  89.     {
  90.         m_Timer->stop();
  91.         m_View->close();
  92.     }
  93.    
  94. }
  95.  
  96. double MapScanner::RightStep(double a, double b)
  97. {
  98.     a += Delta;
  99.     ui.EarthWidth->setText(QString::number(a));
  100.     number++;
  101.     CountWidth++;
  102.     return a;
  103. }
  104. double MapScanner::LeftStep(double a, double b)
  105. {
  106.     a -= Delta;
  107.     ui.EarthWidth->setText(QString::number(a));
  108.     number++;
  109.     CountWidth--;
  110.     return a;
  111. }
  112. double MapScanner::DownStep(double w, double w2,double a, double b,double delta)
  113. {
  114.     a -= delta;
  115.     ui.EarthHeight->setText(QString::number(a));
  116.     if (bag)
  117.     {
  118.         w -= 2 * Delta;
  119.         ui.EarthWidth->setText(QString::number(w));
  120.     }
  121.     else
  122.     {
  123.         w += 2 * Delta;
  124.         ui.EarthWidth->setText(QString::number(w));
  125.     }
  126.     number++;
  127.     CountHeight++;
  128.     return a;
  129. }
  130.  
  131. int MapScanner::CountI(double a, double b)
  132. {
  133.     int l = ((abs(a - b)) + 2 * Delta*(ui.LineSize->text().toDouble()) / 326.97) / Delta;
  134.     return l;
  135. }
  136. int MapScanner::CountJ(double a, double b)
  137. {
  138.     double kRad = a / 180 * M_PI;
  139.     double delta = Delta*(0.5*cos(kRad)*(pow(eps, 2)* (cos(2 * kRad) - 1) + 2)) / (1);
  140.     int l = (abs(a - b) + 2 * delta*(ui.LineSize->text().toDouble()) / 326.97) / Delta;
  141.     return l;
  142. }
  143. void MapScanner::StartProgramm()
  144. {
  145.     double w = ui.EarthWidth->text().toDouble();
  146.     double w2 = ui.EarthWidth2->text().toDouble();
  147.     n = CountI(w, w2);
  148.  
  149.     double k = ui.EarthHeight->text().toDouble();
  150.     double k2 = ui.EarthHeight2->text().toDouble();
  151.  
  152.     m = CountJ(k, k2);
  153.     QPixmap pix(2048, 2048);
  154.     pix.save(ui.SavePath->text() + "newfile.png");
  155.     m_Timer->start(1);
  156. }
  157. void MapScanner::SaveImages()
  158. {
  159.     QPixmap pic(m_View->size());
  160.     m_View->show();
  161.     m_View->render(&pic);
  162.     pic.save(ui.SavePath->text() + "img" + QString::number(number) + ".png");
  163.  
  164.     m_renderPixmap.load(ui.SavePath->text() + "newfile.png"); // создаём картинку
  165.     QPainter p(&m_renderPixmap); // создаём рисовалку и нацеливаем её на картинку
  166.     p.drawPixmap(256 * CountWidth, 256 * CountHeight, QPixmap(ui.SavePath->text() + "img" + QString::number(number) + ".png")); // накладываем изображение из файла на эту картинку в координаты 0,0
  167.     p.end(); // завершаем работу рисовалки
  168.     m_renderPixmap.save(ui.SavePath->text() + "newfile.png", "PNG"); // сохраняем файл
  169. }
  170. void MapScanner::PushCoordinates()
  171. {
  172.     m_MassivHeight.push_back(ui.EarthHeight->text().toDouble());
  173.     m_MassivWidth.push_back(ui.EarthWidth->text().toDouble());
  174.     m_MassivHeight.push_back(ui.EarthHeight2->text().toDouble());
  175.     m_MassivWidth.push_back(ui.EarthWidth2->text().toDouble());
  176. }
  177. void MapScanner::DownloadMap()
  178. {
  179.     int c = 0;
  180.     c = CheckDot(ui.EarthHeight->text().toDouble(), ui.EarthWidth->text().toDouble());
  181.     QUrl UrlYandex;
  182.     QUrl UrlGoodle;
  183.     QUrl UrlBing;
  184.     if (c != -1)
  185.     {
  186.         //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";
  187.         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";
  188.         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=";
  189.         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";
  190.     }
  191.     else
  192.     {
  193.         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";
  194.         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=";
  195.         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";
  196.     }
  197.     ui.lineEdit->setText(QString::number(c));
  198.     if (ui.GoogleUrl->isChecked())
  199.         m_View->load(QUrl(UrlGoodle));
  200.     if (ui.YandexUrl->isChecked())
  201.         m_View->load(QUrl(UrlYandex));
  202.     if (ui.BingUrl->isChecked())
  203.         m_View->load(QUrl(UrlBing));
  204. }
  205. int MapScanner::CheckDot(double a, double b)
  206. {
  207.     for (int count = 0; count < m_MassivWidth.size(); count++)
  208.         if (((a - (Delta / 2)) <= m_MassivHeight[count]) && ((a + (Delta / 2)) >= m_MassivHeight[count])
  209.             && ((b - (Delta / 2)) <= m_MassivWidth[count]) && ((b + (Delta / 2)) >= m_MassivWidth[count]))
  210.             return count;
  211.         else return -1;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement