dmptilematrixset.cpp 2.3 KB
/**************************************************************************
* file:              dmptilematrixset.cpp

* Author:            wanzhongping
* Date:              2021-11-16 15:52:48
* Email:             zhongpingw@chinadci.com
* copyright:         广州城市信息研究所有限公司
***************************************************************************/
#include "dmptilematrixset.h"
#include <iostream>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/typeof/typeof.hpp>

DmpTileMatrixSet::DmpTileMatrixSet()
{
    tileCols_ = 256;
    tileRows_ = 256;
    dpi_ = 96;
}

DmpTileMatrixSet::~DmpTileMatrixSet()
{
    if (tileOrigin_)
    {
        delete tileOrigin_;
        tileOrigin_ = nullptr;
    }

    std::vector<TileLevel *>::iterator iter = tileLevels_.begin();
    for (; iter != tileLevels_.end(); ++iter)
    {
        if (*iter != NULL)
        {
            delete *iter;
            *iter = NULL;
        }
    }
    tileLevels_.clear();
}

bool DmpTileMatrixSet::readXml(const boost::property_tree::ptree &matrixSetNode)
{
    try
    {
        id_ = matrixSetNode.get<std::string>("id");
        crs_ = matrixSetNode.get<std::string>("crs");
        tileCols_ = matrixSetNode.get<int>("tileCols");
        tileRows_ = matrixSetNode.get<int>("tileRows");
        dpi_ = matrixSetNode.get<int>("dpi");

        double x = matrixSetNode.get<double>("tileOrigin.X");
        double y = matrixSetNode.get<double>("tileOrigin.Y");
        tileOrigin_ = new DmpPoint(x, y);

        boost::property_tree::ptree pLevels = matrixSetNode.get_child("levels");
        for (BOOST_AUTO(pos, pLevels.begin()); pos != pLevels.end(); ++pos)
        {
            boost::property_tree::ptree pLevel = pos->second;
            TileLevel *tileLevel = new TileLevel();
            tileLevel->id = pLevel.get<int>("id");
            tileLevel->scaleDenominator = pLevel.get<double>("scaleDenominator");
            tileLevel->resolution = pLevel.get<double>("resolution");
            tileLevels_.push_back(tileLevel);
        }
    }
    catch (const std::exception &e)
    {
        std::cerr << e.what() << '\n';
        return false;
    }
    return true;
}

bool DmpTileMatrixSet::writeXml(boost::property_tree::ptree &matrixSetNode)
{
    return false;
}