Skip to content

Commit

Permalink
Merge branch 'master' into delimited_text_bug_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrook committed Apr 17, 2013
2 parents c396128 + 22e54b9 commit 45a1bb4
Show file tree
Hide file tree
Showing 28 changed files with 253 additions and 1,170 deletions.
34 changes: 1 addition & 33 deletions python/core/raster/qgsrasterdataprovider.sip
Expand Up @@ -120,22 +120,8 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
virtual int ySize() const; virtual int ySize() const;


/** read block of data */ /** read block of data */
// TODO clarify what happens on the last block (the part outside raster)
// virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data );

/** read block of data using give extent and size */
// virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );

/** read block of data using give extent and size */
// virtual void *readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS, void *data );

/** Read block of data using given extent and size. */
// virtual void *readBlock( int bandNo, QgsRectangle const & extent, int width, int height );
virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) / Factory /; virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) / Factory /;


/* Read a value from a data block at a given index. */
//virtual double readValue( void *data, int type, int index );

/* Return true if source band has no data value */ /* Return true if source band has no data value */
virtual bool srcHasNoDataValue( int bandNo ) const; virtual bool srcHasNoDataValue( int bandNo ) const;


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


/** value representing null data */
//virtual double noDataValue() const;

/** Value representing currentno data.
* WARNING: this value returned by this method is not constant. It may change
* for example if user disable use of source no data value. */
//virtual double noDataValue( int bandNo ) const;

/** Value representing no data value. */ /** Value representing no data value. */
virtual double srcNoDataValue( int bandNo ) const; virtual double srcNoDataValue( int bandNo ) const;


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


virtual double minimumValue( int bandNo ) const;
virtual double maximumValue( int bandNo ) const;

virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const; virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const;


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


static QStringList cStringList2Q_( char ** stringList );

static QString makeTableCell( const QString & value );
static QString makeTableCells( const QStringList & values );

/** Time stamp of data source in the moment when data/metadata were loaded by provider */ /** Time stamp of data source in the moment when data/metadata were loaded by provider */
virtual QDateTime timestamp() const; virtual QDateTime timestamp() const;


Expand Down Expand Up @@ -273,9 +243,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
virtual bool remove(); virtual bool remove();


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


/** Validates creation options for a specific dataset and destination format. /** Validates creation options for a specific dataset and destination format.
* @note used by GDAL provider only * @note used by GDAL provider only
Expand Down
8 changes: 2 additions & 6 deletions python/core/raster/qgsrasterinterface.sip
Expand Up @@ -44,15 +44,11 @@ class QgsRasterInterface
enum Capability enum Capability
{ {
NoCapabilities, NoCapabilities,
Identify,
ExactMinimumMaximum,
ExactResolution,
EstimatedMinimumMaximum,
BuildPyramids,
Histogram,
Size, Size,
Create, Create,
Remove, Remove,
BuildPyramids,
Identify,
IdentifyValue, IdentifyValue,
IdentifyText, IdentifyText,
IdentifyHtml, IdentifyHtml,
Expand Down
35 changes: 12 additions & 23 deletions python/plugins/sextante/core/SextanteLog.py
Expand Up @@ -23,35 +23,37 @@
# This will get replaced with a git SHA1 when you do a git archive # This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'


import datetime
import os import os
from sextante.core.SextanteUtils import SextanteUtils
from sextante.core.SextanteConfig import SextanteConfig
import codecs import codecs
import datetime
from PyQt4 import QtGui from PyQt4 import QtGui

from sextante.core.SextanteUtils import SextanteUtils
from sextante.core.SextanteConfig import SextanteConfig

class SextanteLog(): class SextanteLog():


LOG_ERROR = "ERROR" LOG_ERROR = "ERROR"
LOG_INFO = "INFO" LOG_INFO = "INFO"
LOG_WARNING = "WARNING" LOG_WARNING = "WARNING"
LOG_ALGORITHM = "ALGORITHM" LOG_ALGORITHM = "ALGORITHM"
DATE_FORMAT = u"%a %b %d %Y %H:%M:%S".encode("utf-8")
recentAlgs = [] recentAlgs = []


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


@staticmethod @staticmethod
def logFilename(): def logFilename():
batchfile = SextanteUtils.userFolder() + os.sep + "sextante_qgis.log" batchfile = SextanteUtils.userFolder() + os.sep + "sextante_qgis.log"
return batchfile return batchfile



@staticmethod @staticmethod
def addToLog(msgtype, msg): def addToLog(msgtype, msg):
try: #it seems that this fails sometimes depending on the msg added: try: #it seems that this fails sometimes depending on the msg added:
Expand All @@ -63,8 +65,8 @@ def addToLog(msgtype, msg):
text = a text = a
else: else:
text = msg.replace("\n", "|") text = msg.replace("\n", "|")
line = msgtype + "|" + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "|" + text + "\n" line = msgtype + "|" + datetime.datetime.now().strftime(SextanteLog.DATE_FORMAT).decode("utf-8") + "|" + text + "\n"
logfile = open(SextanteLog.logFilename(), "a") logfile = codecs.open(SextanteLog.logFilename(), "a", encoding="utf-8")
#logfile = codecs.open(SextanteLog.logFilename(), "a", encoding='utf-8') #logfile = codecs.open(SextanteLog.logFilename(), "a", encoding='utf-8')
logfile.write(line) logfile.write(line)
logfile.close() logfile.close()
Expand All @@ -78,7 +80,6 @@ def addToLog(msgtype, msg):
except: except:
pass pass



@staticmethod @staticmethod
def getLogEntries(): def getLogEntries():
entries={} entries={}
Expand Down Expand Up @@ -115,7 +116,6 @@ def getLogEntries():
entries[SextanteLog.LOG_WARNING] = warnings entries[SextanteLog.LOG_WARNING] = warnings
return entries return entries



@staticmethod @staticmethod
def getRecentAlgorithms(): def getRecentAlgorithms():
recentAlgsSetting = SextanteConfig.getSetting(SextanteConfig.RECENT_ALGORITHMS) recentAlgsSetting = SextanteConfig.getSetting(SextanteConfig.RECENT_ALGORITHMS)
Expand All @@ -125,14 +125,11 @@ def getRecentAlgorithms():
pass pass
return SextanteLog.recentAlgs return SextanteLog.recentAlgs



@staticmethod @staticmethod
def clearLog(): def clearLog():
os.unlink(SextanteLog.logFilename()) os.unlink(SextanteLog.logFilename())
SextanteLog.startLogging() SextanteLog.startLogging()




class LogEntry(): class LogEntry():
def __init__(self, date, text): def __init__(self, date, text):
self.date = date self.date = date
Expand All @@ -141,8 +138,6 @@ def __init__(self, date, text):
import re import re
import time import time




#=============================================================================== #===============================================================================


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


def __init__(self, filename, read_size=1024, end=False): def __init__(self, filename, read_size=1024, end=False):
self.read_size = read_size self.read_size = read_size
self.file = open(filename) self.file = codecs.open(filename, encoding="utf-8")
self.start_pos = self.file.tell() self.start_pos = self.file.tell()
if end: if end:
self.seek_end() self.seek_end()
Expand Down Expand Up @@ -259,8 +254,6 @@ def tail(self, lines=10):
else: else:
return [] return []




def __iter__(self): def __iter__(self):
return self.follow() return self.follow()


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


def tail(file, lines=200): def tail(file, lines=200):
return Tailer(file).tail(lines) return Tailer(file).tail(lines)




17 changes: 11 additions & 6 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -164,9 +164,11 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
{ {
// initialize resampling methods // initialize resampling methods
cboResamplingMethod->clear(); cboResamplingMethod->clear();
foreach ( QString method, QgsRasterDataProvider::pyramidResamplingMethods( mRasterLayer->providerType() ) ) QPair<QString, QString> method;
cboResamplingMethod->addItem( method ); foreach ( method, QgsRasterDataProvider::pyramidResamplingMethods( mRasterLayer->providerType() ) )

{
cboResamplingMethod->addItem( method.second, method.first );
}
// build pyramid list // build pyramid list
QList< QgsRasterPyramid > myPyramidList = provider->buildPyramidList(); QList< QgsRasterPyramid > myPyramidList = provider->buildPyramidList();
QList< QgsRasterPyramid >::iterator myRasterPyramidIterator; QList< QgsRasterPyramid >::iterator myRasterPyramidIterator;
Expand Down Expand Up @@ -195,7 +197,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
mOptsPage_Pyramids->setEnabled( false ); mOptsPage_Pyramids->setEnabled( false );
} }


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


if ( !( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Histogram ) ) if ( !( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Size ) )
{ {
if ( mOptsPage_Histogram != NULL ) if ( mOptsPage_Histogram != NULL )
{ {
Expand Down Expand Up @@ -933,7 +938,7 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::setOverrideCursor( Qt::WaitCursor );
QString res = provider->buildPyramids( QString res = provider->buildPyramids(
myPyramidList, myPyramidList,
cboResamplingMethod->currentText(), cboResamplingMethod->itemData( cboResamplingMethod->currentIndex() ).toString(),
( QgsRasterDataProvider::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex() ); ( QgsRasterDataProvider::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex() );
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
mPyramidProgress->setValue( 0 ); mPyramidProgress->setValue( 0 );
Expand Down
22 changes: 13 additions & 9 deletions src/core/raster/qgsrasterchecker.cpp
Expand Up @@ -145,12 +145,16 @@ bool QgsRasterChecker::runTest( QString theVerifiedKey, QString theVerifiedUri,


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


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


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


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


mReport += htmlTable; mReport += htmlTable;


free( expectedData ); delete expectedBlock;
free( verifiedData ); delete verifiedBlock;
} }
delete verifiedProvider; delete verifiedProvider;
delete expectedProvider; delete expectedProvider;
Expand Down

0 comments on commit 45a1bb4

Please sign in to comment.