Skip to content

Commit 45a1bb4

Browse files
committed
Merge branch 'master' into delimited_text_bug_fixes
2 parents c396128 + 22e54b9 commit 45a1bb4

28 files changed

+253
-1170
lines changed

python/core/raster/qgsrasterdataprovider.sip

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,8 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
120120
virtual int ySize() const;
121121

122122
/** read block of data */
123-
// TODO clarify what happens on the last block (the part outside raster)
124-
// virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data );
125-
126-
/** read block of data using give extent and size */
127-
// virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
128-
129-
/** read block of data using give extent and size */
130-
// virtual void *readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS, void *data );
131-
132-
/** Read block of data using given extent and size. */
133-
// virtual void *readBlock( int bandNo, QgsRectangle const & extent, int width, int height );
134123
virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) / Factory /;
135124

136-
/* Read a value from a data block at a given index. */
137-
//virtual double readValue( void *data, int type, int index );
138-
139125
/* Return true if source band has no data value */
140126
virtual bool srcHasNoDataValue( int bandNo ) const;
141127

@@ -145,14 +131,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
145131
/** \brief Set source nodata value usage */
146132
virtual void setUseSrcNoDataValue( int bandNo, bool use );
147133

148-
/** value representing null data */
149-
//virtual double noDataValue() const;
150-
151-
/** Value representing currentno data.
152-
* WARNING: this value returned by this method is not constant. It may change
153-
* for example if user disable use of source no data value. */
154-
//virtual double noDataValue( int bandNo ) const;
155-
156134
/** Value representing no data value. */
157135
virtual double srcNoDataValue( int bandNo ) const;
158136

@@ -161,9 +139,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
161139
/** Get list of user no data value ranges */
162140
virtual QgsRasterRangeList userNoDataValue( int bandNo ) const;
163141

164-
virtual double minimumValue( int bandNo ) const;
165-
virtual double maximumValue( int bandNo ) const;
166-
167142
virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const;
168143

169144
// Defined in parent
@@ -235,11 +210,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
235210
@note: this method was added in version 1.2*/
236211
void setDpi( int dpi );
237212

238-
static QStringList cStringList2Q_( char ** stringList );
239-
240-
static QString makeTableCell( const QString & value );
241-
static QString makeTableCells( const QStringList & values );
242-
243213
/** Time stamp of data source in the moment when data/metadata were loaded by provider */
244214
virtual QDateTime timestamp() const;
245215

@@ -273,9 +243,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
273243
virtual bool remove();
274244

275245
/** Returns a list of pyramid resampling method names for given provider */
276-
static QStringList pyramidResamplingMethods( QString providerKey = "gdal" );
277-
/** Returns the pyramid resampling argument that corresponds to a given method */
278-
static QString pyramidResamplingArg( QString method, QString providerKey = "gdal" );
246+
static QList<QPair<QString,QString> > pyramidResamplingMethods( QString providerKey );
279247

280248
/** Validates creation options for a specific dataset and destination format.
281249
* @note used by GDAL provider only

python/core/raster/qgsrasterinterface.sip

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,11 @@ class QgsRasterInterface
4444
enum Capability
4545
{
4646
NoCapabilities,
47-
Identify,
48-
ExactMinimumMaximum,
49-
ExactResolution,
50-
EstimatedMinimumMaximum,
51-
BuildPyramids,
52-
Histogram,
5347
Size,
5448
Create,
5549
Remove,
50+
BuildPyramids,
51+
Identify,
5652
IdentifyValue,
5753
IdentifyText,
5854
IdentifyHtml,

python/plugins/sextante/core/SextanteLog.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,37 @@
2323
# This will get replaced with a git SHA1 when you do a git archive
2424
__revision__ = '$Format:%H$'
2525

26-
import datetime
2726
import os
28-
from sextante.core.SextanteUtils import SextanteUtils
29-
from sextante.core.SextanteConfig import SextanteConfig
3027
import codecs
28+
import datetime
3129
from PyQt4 import QtGui
30+
31+
from sextante.core.SextanteUtils import SextanteUtils
32+
from sextante.core.SextanteConfig import SextanteConfig
33+
3234
class SextanteLog():
3335

3436
LOG_ERROR = "ERROR"
3537
LOG_INFO = "INFO"
3638
LOG_WARNING = "WARNING"
3739
LOG_ALGORITHM = "ALGORITHM"
40+
DATE_FORMAT = u"%a %b %d %Y %H:%M:%S".encode("utf-8")
3841
recentAlgs = []
3942

4043
@staticmethod
4144
def startLogging():
4245
if os.path.isfile(SextanteLog.logFilename()):
43-
logfile = open(SextanteLog.logFilename(), "a")
46+
logfile = codecs.open(SextanteLog.logFilename(), "a", encoding="utf-8")
4447
else:
45-
logfile = open(SextanteLog.logFilename(), "w")
46-
logfile.write("Started logging at " + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "\n")
48+
logfile = codecs.open(SextanteLog.logFilename(), "w", encoding="utf-8")
49+
logfile.write("Started logging at " + datetime.datetime.now().strftime(SextanteLog.DATE_FORMAT).decode("utf-8") + "\n")
4750
logfile.close()
4851

4952
@staticmethod
5053
def logFilename():
5154
batchfile = SextanteUtils.userFolder() + os.sep + "sextante_qgis.log"
5255
return batchfile
5356

54-
5557
@staticmethod
5658
def addToLog(msgtype, msg):
5759
try: #it seems that this fails sometimes depending on the msg added:
@@ -63,8 +65,8 @@ def addToLog(msgtype, msg):
6365
text = a
6466
else:
6567
text = msg.replace("\n", "|")
66-
line = msgtype + "|" + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "|" + text + "\n"
67-
logfile = open(SextanteLog.logFilename(), "a")
68+
line = msgtype + "|" + datetime.datetime.now().strftime(SextanteLog.DATE_FORMAT).decode("utf-8") + "|" + text + "\n"
69+
logfile = codecs.open(SextanteLog.logFilename(), "a", encoding="utf-8")
6870
#logfile = codecs.open(SextanteLog.logFilename(), "a", encoding='utf-8')
6971
logfile.write(line)
7072
logfile.close()
@@ -78,7 +80,6 @@ def addToLog(msgtype, msg):
7880
except:
7981
pass
8082

81-
8283
@staticmethod
8384
def getLogEntries():
8485
entries={}
@@ -115,7 +116,6 @@ def getLogEntries():
115116
entries[SextanteLog.LOG_WARNING] = warnings
116117
return entries
117118

118-
119119
@staticmethod
120120
def getRecentAlgorithms():
121121
recentAlgsSetting = SextanteConfig.getSetting(SextanteConfig.RECENT_ALGORITHMS)
@@ -125,14 +125,11 @@ def getRecentAlgorithms():
125125
pass
126126
return SextanteLog.recentAlgs
127127

128-
129128
@staticmethod
130129
def clearLog():
131130
os.unlink(SextanteLog.logFilename())
132131
SextanteLog.startLogging()
133132

134-
135-
136133
class LogEntry():
137134
def __init__(self, date, text):
138135
self.date = date
@@ -141,8 +138,6 @@ def __init__(self, date, text):
141138
import re
142139
import time
143140

144-
145-
146141
#===============================================================================
147142

148143
#this code has been take from pytailer
@@ -173,7 +168,7 @@ class Tailer(object):
173168

174169
def __init__(self, filename, read_size=1024, end=False):
175170
self.read_size = read_size
176-
self.file = open(filename)
171+
self.file = codecs.open(filename, encoding="utf-8")
177172
self.start_pos = self.file.tell()
178173
if end:
179174
self.seek_end()
@@ -259,8 +254,6 @@ def tail(self, lines=10):
259254
else:
260255
return []
261256

262-
263-
264257
def __iter__(self):
265258
return self.follow()
266259

@@ -269,7 +262,3 @@ def close(self):
269262

270263
def tail(file, lines=200):
271264
return Tailer(file).tail(lines)
272-
273-
274-
275-

src/app/qgsrasterlayerproperties.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
164164
{
165165
// initialize resampling methods
166166
cboResamplingMethod->clear();
167-
foreach ( QString method, QgsRasterDataProvider::pyramidResamplingMethods( mRasterLayer->providerType() ) )
168-
cboResamplingMethod->addItem( method );
169-
167+
QPair<QString, QString> method;
168+
foreach ( method, QgsRasterDataProvider::pyramidResamplingMethods( mRasterLayer->providerType() ) )
169+
{
170+
cboResamplingMethod->addItem( method.second, method.first );
171+
}
170172
// build pyramid list
171173
QList< QgsRasterPyramid > myPyramidList = provider->buildPyramidList();
172174
QList< QgsRasterPyramid >::iterator myRasterPyramidIterator;
@@ -195,7 +197,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
195197
mOptsPage_Pyramids->setEnabled( false );
196198
}
197199

198-
if ( !( provider->capabilities() & QgsRasterDataProvider::Histogram ) )
200+
// We can calculate histogram for all data sources but estimated only if
201+
// size is unknown - could also be enabled if well supported (estimated histogram
202+
// and and let user know that it is estimated)
203+
if ( !( provider->capabilities() & QgsRasterDataProvider::Size ) )
199204
{
200205
// disable Histogram tab completely
201206
mOptsPage_Histogram->setEnabled( false );
@@ -572,7 +577,7 @@ void QgsRasterLayerProperties::sync()
572577
}
573578
}
574579

575-
if ( !( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Histogram ) )
580+
if ( !( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Size ) )
576581
{
577582
if ( mOptsPage_Histogram != NULL )
578583
{
@@ -933,7 +938,7 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
933938
QApplication::setOverrideCursor( Qt::WaitCursor );
934939
QString res = provider->buildPyramids(
935940
myPyramidList,
936-
cboResamplingMethod->currentText(),
941+
cboResamplingMethod->itemData( cboResamplingMethod->currentIndex() ).toString(),
937942
( QgsRasterDataProvider::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex() );
938943
QApplication::restoreOverrideCursor();
939944
mPyramidProgress->setValue( 0 );

src/core/raster/qgsrasterchecker.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ bool QgsRasterChecker::runTest( QString theVerifiedKey, QString theVerifiedUri,
145145

146146
int width = expectedProvider->xSize();
147147
int height = expectedProvider->ySize();
148-
int blockSize = width * height * QgsRasterBlock::typeSize( expectedProvider->dataType( band ) ) ;
149-
void * expectedData = malloc( blockSize );
150-
void * verifiedData = malloc( blockSize );
148+
QgsRasterBlock *expectedBlock = expectedProvider->block( band, expectedProvider->extent(), width, height );
149+
QgsRasterBlock *verifiedBlock = verifiedProvider->block( band, expectedProvider->extent(), width, height );
151150

152-
expectedProvider->readBlock( band, expectedProvider->extent(), width, height, expectedData );
153-
verifiedProvider->readBlock( band, expectedProvider->extent(), width, height, verifiedData );
151+
if ( !expectedBlock || !expectedBlock->isValid() ||
152+
!verifiedBlock || !verifiedBlock->isValid() )
153+
{
154+
allOk = false;
155+
mReport += "cannot read raster block";
156+
continue;
157+
}
154158

155159
// compare data values
156160
QString htmlTable = QString( "<table style='%1'>" ).arg( mTabStyle );
@@ -160,8 +164,8 @@ bool QgsRasterChecker::runTest( QString theVerifiedKey, QString theVerifiedUri,
160164
for ( int col = 0; col < width; col ++ )
161165
{
162166
bool cellOk = true;
163-
double verifiedVal = QgsRasterBlock::readValue( verifiedData, verifiedProvider->dataType( band ), row * width + col );
164-
double expectedVal = QgsRasterBlock::readValue( expectedData, expectedProvider->dataType( band ), row * width + col );
167+
double verifiedVal = verifiedBlock->value( row, col );
168+
double expectedVal = expectedBlock->value( row, col );
165169

166170
QString valStr;
167171
if ( compare( verifiedVal, expectedVal, 0 ) )
@@ -182,8 +186,8 @@ bool QgsRasterChecker::runTest( QString theVerifiedKey, QString theVerifiedUri,
182186

183187
mReport += htmlTable;
184188

185-
free( expectedData );
186-
free( verifiedData );
189+
delete expectedBlock;
190+
delete verifiedBlock;
187191
}
188192
delete verifiedProvider;
189193
delete expectedProvider;

0 commit comments

Comments
 (0)