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;

/** 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 /;

/* 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 */
virtual bool srcHasNoDataValue( int bandNo ) const;

Expand All @@ -145,14 +131,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
/** \brief Set source nodata value usage */
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. */
virtual double srcNoDataValue( int bandNo ) const;

Expand All @@ -161,9 +139,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
/** Get list of user no data value ranges */
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;

// Defined in parent
Expand Down Expand Up @@ -235,11 +210,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
@note: this method was added in version 1.2*/
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 */
virtual QDateTime timestamp() const;

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

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

/** Validates creation options for a specific dataset and destination format.
* @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
{
NoCapabilities,
Identify,
ExactMinimumMaximum,
ExactResolution,
EstimatedMinimumMaximum,
BuildPyramids,
Histogram,
Size,
Create,
Remove,
BuildPyramids,
Identify,
IdentifyValue,
IdentifyText,
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
__revision__ = '$Format:%H$'

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

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

class SextanteLog():

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

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

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


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


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


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


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



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



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

#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):
self.read_size = read_size
self.file = open(filename)
self.file = codecs.open(filename, encoding="utf-8")
self.start_pos = self.file.tell()
if end:
self.seek_end()
Expand Down Expand Up @@ -259,8 +254,6 @@ def tail(self, lines=10):
else:
return []



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

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

def tail(file, lines=200):
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
cboResamplingMethod->clear();
foreach ( QString method, QgsRasterDataProvider::pyramidResamplingMethods( mRasterLayer->providerType() ) )
cboResamplingMethod->addItem( method );

QPair<QString, QString> method;
foreach ( method, QgsRasterDataProvider::pyramidResamplingMethods( mRasterLayer->providerType() ) )
{
cboResamplingMethod->addItem( method.second, method.first );
}
// build pyramid list
QList< QgsRasterPyramid > myPyramidList = provider->buildPyramidList();
QList< QgsRasterPyramid >::iterator myRasterPyramidIterator;
Expand Down Expand Up @@ -195,7 +197,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
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
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 )
{
Expand Down Expand Up @@ -933,7 +938,7 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
QApplication::setOverrideCursor( Qt::WaitCursor );
QString res = provider->buildPyramids(
myPyramidList,
cboResamplingMethod->currentText(),
cboResamplingMethod->itemData( cboResamplingMethod->currentIndex() ).toString(),
( QgsRasterDataProvider::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex() );
QApplication::restoreOverrideCursor();
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 height = expectedProvider->ySize();
int blockSize = width * height * QgsRasterBlock::typeSize( expectedProvider->dataType( band ) ) ;
void * expectedData = malloc( blockSize );
void * verifiedData = malloc( blockSize );
QgsRasterBlock *expectedBlock = expectedProvider->block( band, expectedProvider->extent(), width, height );
QgsRasterBlock *verifiedBlock = verifiedProvider->block( band, expectedProvider->extent(), width, height );

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

// compare data values
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 ++ )
{
bool cellOk = true;
double verifiedVal = QgsRasterBlock::readValue( verifiedData, verifiedProvider->dataType( band ), row * width + col );
double expectedVal = QgsRasterBlock::readValue( expectedData, expectedProvider->dataType( band ), row * width + col );
double verifiedVal = verifiedBlock->value( row, col );
double expectedVal = expectedBlock->value( row, col );

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

mReport += htmlTable;

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

0 comments on commit 45a1bb4

Please sign in to comment.