2018-08-21 20:01:47 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QImageReader>
|
2021-01-17 19:33:06 +01:00
|
|
|
#include "common/util.h"
|
2018-08-21 20:01:47 +02:00
|
|
|
#include "geotiff.h"
|
2018-08-23 20:26:10 +02:00
|
|
|
#include "image.h"
|
2018-08-21 20:01:47 +02:00
|
|
|
#include "geotiffmap.h"
|
|
|
|
|
|
|
|
|
|
|
|
GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
|
2020-12-22 22:09:09 +01:00
|
|
|
: Map(fileName, parent), _img(0), _ratio(1.0), _valid(false)
|
2018-08-21 20:01:47 +02:00
|
|
|
{
|
2018-08-23 20:26:10 +02:00
|
|
|
QImageReader ir(fileName);
|
|
|
|
if (!ir.canRead()) {
|
|
|
|
_errorString = "Unsupported/invalid image file";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_size = ir.size();
|
|
|
|
|
2018-08-21 20:01:47 +02:00
|
|
|
GeoTIFF gt(fileName);
|
|
|
|
if (!gt.isValid()) {
|
|
|
|
_errorString = gt.errorString();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
_projection = gt.projection();
|
|
|
|
_transform = gt.transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
_valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GeoTIFFMap::~GeoTIFFMap()
|
|
|
|
{
|
|
|
|
delete _img;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-21 20:01:47 +02:00
|
|
|
{
|
2018-08-23 20:26:10 +02:00
|
|
|
if (_img)
|
|
|
|
_img->draw(painter, rect, flags);
|
|
|
|
}
|
2018-08-21 20:01:47 +02:00
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
void GeoTIFFMap::load(const Projection &in, const Projection &out,
|
|
|
|
qreal deviceRatio, bool hidpi)
|
2018-08-23 20:26:10 +02:00
|
|
|
{
|
2023-05-04 09:38:35 +02:00
|
|
|
Q_UNUSED(in);
|
|
|
|
Q_UNUSED(out);
|
2018-11-17 10:10:35 +01:00
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
_ratio = hidpi ? deviceRatio : 1.0;
|
|
|
|
|
|
|
|
_img = new Image(path());
|
2018-08-23 20:26:10 +02:00
|
|
|
if (_img)
|
|
|
|
_img->setDevicePixelRatio(_ratio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeoTIFFMap::unload()
|
|
|
|
{
|
|
|
|
delete _img;
|
|
|
|
_img = 0;
|
2018-08-21 20:01:47 +02:00
|
|
|
}
|
2022-04-29 23:16:10 +02:00
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
Map *GeoTIFFMap::create(const QString &path, bool *isDir)
|
2022-04-29 23:16:10 +02:00
|
|
|
{
|
|
|
|
if (isDir)
|
|
|
|
*isDir = false;
|
|
|
|
|
|
|
|
return new GeoTIFFMap(path);
|
|
|
|
}
|