22 using namespace Marble;
27 TileCreatorSourceSrtm(
const QString &sourceDir )
28 : m_sourceDir( sourceDir )
32 virtual QSize fullImageSize()
const
37 virtual QImage tile(
int n,
int m,
int maxTileLevel )
39 Q_ASSERT( maxTileLevel == 9 );
42 Q_ASSERT( nmax == 512 );
45 qreal startLat = ( ( ( (qreal)n * 180 ) / nmax ) - 90 ) * -1;
46 qreal startLng = ( ( (qreal)m * 360 ) / mmax ) - 180;
52 if (hgtFileName(std::floor(startLng), std::floor(startLat)).isNull()
53 && hgtFileName(std::floor(startLng)+1, std::floor(startLat)).isNull()
54 && hgtFileName(std::floor(startLng), std::floor(startLat)-1).isNull()
55 && hgtFileName(std::floor(startLng)+1, std::floor(startLat)-1).isNull()
63 QImage image( 2400, 2400, QImage::Format_ARGB32 );
66 painter.fillRect( 0, 0, 2400, 2400, QColor( Qt::black ) );
67 QImage i = readHgt(std::floor(startLng), std::floor(startLat));
68 painter.drawImage( 0, 0, i );
69 painter.drawImage( 1200, 0, readHgt( std::floor(startLng)+1, std::floor(startLat) ) );
70 painter.drawImage( 0, 1200, readHgt( std::floor(startLng), std::floor(startLat)-1 ) );
71 painter.drawImage( 1200, 1200, readHgt( std::floor(startLng)+1, std::floor(startLat)-1 ) );
78 image = image.scaled( QSize(imageSizeResized, imageSizeResized),
79 Qt::IgnoreAspectRatio );
83 int startLngPx = startLng * 1200;
84 startLngPx = ( 180 * 1200 ) + startLngPx;
87 int startLatPx = startLat * 1200;
88 startLatPx = ( 90 * 1200 ) - startLatPx;
93 int imageLngPx = std::floor(startLng);
94 imageLngPx = 180 + imageLngPx;
98 int imageLatPx = std::floor(90 - startLat);
104 Q_ASSERT(1200*2 - (startLngPx - imageLngPx) >= 675);
105 Q_ASSERT(1200*2 - (startLatPx - imageLatPx) >= 675);
106 Q_ASSERT(startLngPx - imageLngPx >= 0);
107 Q_ASSERT(startLatPx - imageLatPx >= 0);
109 int imageLngPxResized = imageLngPx * 1.6;
110 int imageLatPxResized = imageLatPx * 1.6;
113 Q_ASSERT(startLngPxResized - imageLngPxResized < imageSizeResized);
114 Q_ASSERT(startLatPxResized - imageLatPxResized < imageSizeResized);
115 Q_ASSERT(startLngPxResized - imageLngPxResized >= 0);
116 Q_ASSERT(startLatPxResized - imageLatPxResized >= 0);
118 QImage croppedImage = image.copy(startLngPx - imageLngPx, startLatPx - imageLatPx, 675, 675);
125 QString hgtFileName(
int lng,
int lat )
127 QChar EW( lng >= 0 ?
'E' :
'W' );
128 QChar NS( lat >= 0 ?
'N' :
'S' );
131 dirs <<
"Africa" <<
"Australia" <<
"Eurasia" <<
"Silands" <<
"North_America" <<
"South_America";
132 foreach(
const QString &dir, dirs) {
133 QString fileName = m_sourceDir +
'/' + dir +
'/';
134 if ( lat < 0 ) lat *= -1;
135 fileName += QString(
"%1%2%3%4.hgt" ).arg( NS ).arg( lat<0 ? lat*-1 : lat, 2, 10, QLatin1Char(
'0') )
136 .arg( EW ).arg( lng<0 ? lng*-1 : lng, 3, 10, QLatin1Char(
'0' ) );
139 if ( !QFile::exists( fileName ) && QFile::exists( fileName +
".zip" ) ) {
140 qDebug() <<
"zip found, unzipping";
142 p.execute(
"unzip", QStringList() << fileName +
".zip" );
144 QFile( QDir::currentPath() +
'/' + QFileInfo( fileName ).fileName()).rename(fileName);
146 if ( QFile::exists( fileName ) ) {
154 QImage readHgt(
int lng,
int lat )
156 static QCache<QPair<int, int>, QImage > cache( 10 );
157 if ( cache.contains( qMakePair( lng, lat ) ) ) {
158 return *cache[ qMakePair( lng, lat ) ];
160 QString fileName = hgtFileName( lng, lat );
161 if ( fileName.isNull() ) {
168 QFile file( fileName );
170 file.open( QIODevice::ReadOnly );
175 QImage image( 1200, 1200, QImage::Format_ARGB32 );
177 QByteArray data = file.read( 2 );
180 unsigned short height = *(
unsigned short*)data.data();
181 height = ( height << 8 | height >> 8 );
185 image.setPixel( iLng, iLat, pixel );
188 if ( iLat >= 1199 && iLng >= 1199 )
break;
198 cache.insert( qMakePair( lng, lat ),
new QImage( image ) );
212 m_tilecreator =
new TileCreator( source,
"false", argv[2] );
217 connect( m_tilecreator, SIGNAL(finished()),
this, SLOT(quit()) );
218 m_tilecreator->start();
const int defaultLevelZeroColumns
Base Class for custom tile source.
void setVerifyExactResult(bool verify)
const unsigned int c_defaultTileSize
void setTileFormat(const QString &format)
TCCoreApplication(int &argc, char **argv)
MARBLE_EXPORT int levelToRow(int levelZeroRows, int level)
Get the maximum number of tile rows for a given tile level.
MARBLE_EXPORT int levelToColumn(int levelZeroColumns, int level)
Get the maximum number of tile columns for a given tile level.
void setTileQuality(int quality)
void setResume(bool resume)
const int defaultLevelZeroRows