1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/map/geotiffmap.cpp

82 lines
1.4 KiB
C++
Raw Normal View History

#include <QFileInfo>
#include <QPainter>
#include <QImageReader>
#include "common/config.h"
#include "geotiff.h"
2018-08-23 20:26:10 +02:00
#include "image.h"
#include "geotiffmap.h"
GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
2018-08-23 20:26:10 +02:00
: Map(parent), _fileName(fileName), _img(0), _ratio(1.0), _valid(false)
{
2018-08-23 20:26:10 +02:00
QImageReader ir(fileName);
if (!ir.canRead()) {
_errorString = "Unsupported/invalid image file";
return;
}
_size = ir.size();
GeoTIFF gt(fileName);
if (!gt.isValid()) {
_errorString = gt.errorString();
return;
} else {
_projection = gt.projection();
_transform = gt.transform();
}
_valid = true;
}
GeoTIFFMap::~GeoTIFFMap()
{
delete _img;
}
QString GeoTIFFMap::name() const
{
2018-08-23 20:26:10 +02:00
QFileInfo fi(_fileName);
return fi.fileName();
}
QPointF GeoTIFFMap::ll2xy(const Coordinates &c)
{
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
}
Coordinates GeoTIFFMap::xy2ll(const QPointF &p)
{
return _projection.xy2ll(_transform.img2proj(p * _ratio));
}
QRectF GeoTIFFMap::bounds()
{
return QRectF(QPointF(0, 0), _size / _ratio);
}
2018-08-23 20:26:10 +02:00
void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
{
2018-08-23 20:26:10 +02:00
if (_img)
_img->draw(painter, rect, flags);
}
2018-08-23 20:26:10 +02:00
void GeoTIFFMap::setDevicePixelRatio(qreal ratio)
{
_ratio = ratio;
if (_img)
_img->setDevicePixelRatio(_ratio);
}
void GeoTIFFMap::load()
{
if (!_img)
_img = new Image(_fileName);
}
void GeoTIFFMap::unload()
{
delete _img;
_img = 0;
}