dmptilelayer.cpp
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**************************************************************************
* file: dmptilelayer.cpp
* Author: wanzhongping
* Date: 2021-11-13 16:49:00
* Email: zhongpingw@chinadci.com
* copyright: 广州城市信息研究所有限公司
***************************************************************************/
#include "dmptilelayer.h"
#include "dmpxmlutils.h"
#include <iostream>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/typeof/typeof.hpp>
DmpTileLayer::DmpTileLayer(const std::string &path, const std::string &baseName)
: DmpMapLayer(DmpMapLayerType::TileLayer, baseName, path)
{
}
DmpTileLayer::~DmpTileLayer()
{
std::vector<DmpTileMatrixSet *>::iterator iter = tileMatrixSets_.begin();
for (; iter != tileMatrixSets_.end(); ++iter)
{
if (*iter != NULL)
{
delete *iter;
*iter = NULL;
}
}
tileMatrixSets_.clear();
}
bool DmpTileLayer::readXml(const boost::property_tree::ptree &layerNode)
{
try
{
name_ = layerNode.get<std::string>("<xmlattr>.name");
title_ = layerNode.get<std::string>("<xmlattr>.alias");
boost::property_tree::ptree pExtent = layerNode.get_child("extent");
extent_ = DmpXmlUtils::readRectangle(pExtent);
style_ = layerNode.get<std::string>("style");
format_ = layerNode.get<std::string>("format");
vendor_ = layerNode.get<std::string>("vendor");
datasource_ = layerNode.get<std::string>("datasource");
if(strcmp(vendor_.c_str(),"QGIS")==0)return true;
boost::property_tree::ptree pMatrixSets = layerNode.get_child("tileMatrixSets");
for (BOOST_AUTO(pos, pMatrixSets.begin()); pos != pMatrixSets.end(); ++pos)
{
boost::property_tree::ptree pTileMatrixSet = pos->second;
DmpTileMatrixSet *tileMatrixSet = new DmpTileMatrixSet();
if (tileMatrixSet->readXml(pTileMatrixSet))
{
tileMatrixSets_.push_back(tileMatrixSet);
}
else
{
delete tileMatrixSet;
return false;
}
}
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
return false;
}
return true;
}
bool DmpTileLayer::writeXml(boost::property_tree::ptree &layerNode)
{
return false;
}
std::string DmpTileLayer::getVendor()
{
return vendor_;
}
std::string DmpTileLayer::getDataSource()
{
return datasource_;
}
void DmpTileLayer::getTileMatrixSets(std::vector<DmpTileMatrixSet*>& tileMatrixSets )
{
tileMatrixSets=tileMatrixSets_;
}
std::string DmpTileLayer::getFormat()
{
return format_;
}
std::string DmpTileLayer::getStyle()
{
return style_;
}