|
|
|
|
#include "googleTile.h"
|
|
|
|
|
#include <opencv2/imgcodecs.hpp>
|
|
|
|
|
#include <opencv2/imgproc.hpp>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
#define M_PI 3.1415926
|
|
|
|
|
|
|
|
|
|
googleTile::googleTile()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
googleTile::~googleTile()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void googleTile::ExportGeoPng(cv::Mat _pan, TileInfo info, std::string dir, std::string name)
|
|
|
|
|
{
|
|
|
|
|
// 保存全景图
|
|
|
|
|
string png_path = dir + "/" + name + ".png";
|
|
|
|
|
cv::imwrite(png_path, _pan);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 写入kml
|
|
|
|
|
string kml_path = dir + "/" + name + ".kml";
|
|
|
|
|
std::ofstream kml_file(kml_path);
|
|
|
|
|
|
|
|
|
|
// 写入 KML 文件的头部
|
|
|
|
|
kml_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
|
|
|
|
|
kml_file << "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" << std::endl;
|
|
|
|
|
kml_file << "<Document>" << std::endl;
|
|
|
|
|
|
|
|
|
|
// 写入 GroundOverlay 元素
|
|
|
|
|
kml_file << "<GroundOverlay>" << std::endl;
|
|
|
|
|
kml_file << " <name>My Panoramic Image</name>" << std::endl;
|
|
|
|
|
kml_file << " <Icon>" << std::endl;
|
|
|
|
|
kml_file << " <href>" << name + ".png" << "</href>" << std::endl;
|
|
|
|
|
kml_file << " </Icon>" << std::endl;
|
|
|
|
|
|
|
|
|
|
// 使用四个角点计算 LatLonBox
|
|
|
|
|
kml_file << " <LatLonBox>" << std::endl;
|
|
|
|
|
kml_file << " <north>" << info.north << "</north>" << std::endl; // 经度范围
|
|
|
|
|
kml_file << " <south>" << info.south << "</south>" << std::endl;
|
|
|
|
|
kml_file << " <east>" << info.east << "</east>" << std::endl; // 纬度范围
|
|
|
|
|
kml_file << " <west>" << info.west << "</west>" << std::endl;
|
|
|
|
|
kml_file << " </LatLonBox>" << std::endl;
|
|
|
|
|
|
|
|
|
|
// 写入 KML 文件的尾部
|
|
|
|
|
kml_file << "</GroundOverlay>" << std::endl;
|
|
|
|
|
kml_file << "</Document>" << std::endl;
|
|
|
|
|
kml_file << "</kml>" << std::endl;
|
|
|
|
|
|
|
|
|
|
kml_file.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void googleTile::ExportTile(cv::Mat _pan, TileInfo info, std::string dir, std::string name)
|
|
|
|
|
{
|
|
|
|
|
// 计算四至的瓦片编号
|
|
|
|
|
TileIndex westNorth = LatLonToTile(info.west, info.north, 10);
|
|
|
|
|
int a = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TileIndex googleTile::LatLonToTile(double latitude, double longitude, int zoomLevel)
|
|
|
|
|
{
|
|
|
|
|
// 将纬度转换为墨卡托投影
|
|
|
|
|
double latRad = latitude * M_PI / 180.0;
|
|
|
|
|
double sinLat = sin(latRad);
|
|
|
|
|
|
|
|
|
|
// 计算经度的瓦片编号(0-2^zoomLevel)
|
|
|
|
|
int xTile = static_cast<int>((longitude + 180.0) / 360.0 * pow(2.0, zoomLevel));
|
|
|
|
|
|
|
|
|
|
// 计算纬度的瓦片编号(0-2^zoomLevel)
|
|
|
|
|
int yTile = static_cast<int>((1.0 - log((1.0 + sinLat) / (1.0 - sinLat)) / (2.0 * M_PI)) / 2.0 * pow(2.0, zoomLevel));
|
|
|
|
|
|
|
|
|
|
return TileIndex{ xTile, yTile, zoomLevel };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|