You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.5 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//////////////////////////////////////////////////////////////////////////////
//文件: 格式转换类
//主要功能:
// 读取KML格式
//
//程序编写: 2025-8-21
//
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include ".\otherformat.h"
#include ".\EmbellishBaseLib.h"
#include "afxcoll.h"
#include "..\Layer.h"
#include "..\Xy.h"
#include "..\Utils.h"
#include "..\GdbxDefine.h"
namespace NFormatReader
{
class CKMLFile
: public CEmbellishBaseLib
{
public:
CKMLFile(void);
virtual ~CKMLFile(void);
private:
struct KMLInfo
{
double m_dScaleFactor; //比例因子,当前图件的比例值1m_dScaleFactor
CString m_kmlXmlns; //kml版本 目前有2.1 2.2 2.3
CString m_kmlXmlnsA; //kml版本 目前有2.2 2.3
CString m_kmlXmlnsG; //kml版本 目前有2.2 2.3
CString m_fileEncCoding; //文件编码格式utf-8
CRect8 m_modelSpace;
int m_version; //读取的版本号
};
struct KMLPoint
{
double x; //经度
double y; //纬度
double z; //高程
};
struct PointStyle
{
double m_scale;
COLORREF m_pointColor;
COLORREF m_lableColor;
COLORREF m_lineColor;//线段全局样式也可能在这 2.1版本
COLORREF m_polyColor;
CString m_id;
CString m_iconUrl;
void clear()
{
m_scale = 0;
m_pointColor = -1;
m_lableColor = -1;
m_lineColor = -1;
m_polyColor = -1;
m_id = "";
m_iconUrl = "";
}
};
struct KMLStyleMap
{
CString m_id;
CString m_pairKey; //
CString m_pairStyleUrl; //样式名称 点集使用
std::unordered_map<std::string, PointStyle> m_pointStyle;
};
struct KMLPlacemark
{
double m_lineWidth;
COLORREF m_lineColor;
COLORREF m_polyColor;
CString m_name;
CString m_styleUrl;
std::vector<KMLPoint> m_point;
void clear()
{
m_lineWidth = 0;
m_name = "";
m_lineColor = -1;
m_polyColor = -1;
m_point.clear();
}
};
struct KMLDocument
{
CString m_layerName;
KMLStyleMap m_styleInfo; //每个Document会有一个样式
};
KMLInfo m_info;
public:
int Read(CFile& fr, short ver = -1); //XML文件读写
int Read(LPCTSTR lpszPathName, short ver = -1);
int SetMapUnit(int gm_unit);
protected:
int ReadData(CFile& fr, short ver = -1); //XML文件读写(详细字段)
int ReadKMLInfoHead(CFile& fr, short ver, void* pXmlParse); //kml的基本信息
int ReadKMLDocument(CFile& fr, short ver = -1);
int ReadKMLPlacemark(CFile& fr, const KMLDocument &dInfo, short ver = -1);
int ReadKMLStyle(CFile& fr, KMLPlacemark &info, short ver = -1);
int ReadKMLStyle(CFile& fr, PointStyle &pInfo, short ver = -1);
int ReadKMLLineStyle(CFile& fr, KMLPlacemark &info, short ver = -1);
int ReadKMLPolyStyle(CFile& fr, KMLPlacemark &info, short ver = -1);
int ReadKMLIconStyle(CFile& fr, PointStyle &info, short ver = -1);
int ReadKMLColorStyle(CFile& fr, COLORREF& color, short ver = -1);
int InitMapInfo();
int DrawKMLLine(const KMLPlacemark &pInfo, const KMLDocument &dInfo); //绘制线段
int DrawKMLPolygon(const KMLPlacemark &pInfo, const KMLDocument &dInfo); //绘制多边形
int DrawKMLPoint(const KMLPlacemark &pInfo, const KMLDocument &dInfo); //绘制点
private:
void DeSerialize(CArchive& ar);
vector<CString> SplitByLine(const CString& input); //Layers 按照 \r\n 分割字符串为多个部分
CString ChangeEncoding(const CString &str, const CString &enc, int type = 0); //编码转换
CString Utf8ToGb2312(const CString& utf8Str, int type = 0); //转码
wchar_t* ReplaceLineBreaks(wchar_t* pWideChar, int type = 0); //去除字符中的\\r\\n
COLORREF KMLColorToCOLORREF(const CString& colorStr);
};
};