Skip to content

Commit

Permalink
GRASS Direct
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Dec 6, 2012
1 parent bfa124f commit 4dc8499
Show file tree
Hide file tree
Showing 19 changed files with 2,336 additions and 365 deletions.
6 changes: 5 additions & 1 deletion src/core/raster/qgsrasterblock.cpp
Expand Up @@ -413,12 +413,16 @@ bool QgsRasterBlock::convert( QgsRasterBlock::DataType destDataType )
} }
QgsFree( mData ); QgsFree( mData );
mData = data; mData = data;
mDataType = destDataType;
mTypeSize = typeSize( mDataType );
} }
else if ( typeIsColor( mDataType ) && typeIsColor( destDataType ) ) else if ( typeIsColor( mDataType ) && typeIsColor( destDataType ) )
{ {
QImage::Format format = imageFormat( destDataType ); QImage::Format format = imageFormat( destDataType );
QImage image = mImage->convertToFormat( format ); QImage image = mImage->convertToFormat( format );
*mImage = image; *mImage = image;
mDataType = destDataType;
mTypeSize = typeSize( mDataType );
} }
else else
{ {
Expand Down Expand Up @@ -516,7 +520,7 @@ void * QgsRasterBlock::convert( void *srcData, QgsRasterBlock::DataType srcDataT
double value = readValue( srcData, srcDataType, i ); double value = readValue( srcData, srcDataType, i );
writeValue( destData, destDataType, i, value ); writeValue( destData, destDataType, i, value );
//double newValue = readValue( destData, destDataType, i ); //double newValue = readValue( destData, destDataType, i );
//QgsDebugMsg( QString("convert type %1 to %2: %3 -> %4").arg(srcDataType).arg(destDataType).arg( value ).arg( newValue ) ); //QgsDebugMsg( QString("convert %1 type %2 to %3: %4 -> %5").arg(i).arg(srcDataType).arg(destDataType).arg( value ).arg( newValue ) );
} }
return destData; return destData;
} }
Expand Down
10 changes: 7 additions & 3 deletions src/core/raster/qgsrasterprojector.cpp
Expand Up @@ -701,10 +701,10 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
QgsRasterBlock *outputBlock = new QgsRasterBlock(); QgsRasterBlock *outputBlock = new QgsRasterBlock();
if ( !mInput ) if ( !mInput )
{ {
QgsDebugMsg( "Input not set" );
return outputBlock; return outputBlock;
} }



if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS ) if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS )
{ {
QgsDebugMsg( "No projection necessary" ); QgsDebugMsg( "No projection necessary" );
Expand All @@ -723,6 +723,7 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
// If we zoom out too much, projector srcRows / srcCols maybe 0, which can cause problems in providers // If we zoom out too much, projector srcRows / srcCols maybe 0, which can cause problems in providers
if ( srcRows() <= 0 || srcCols() <= 0 ) if ( srcRows() <= 0 || srcCols() <= 0 )
{ {
QgsDebugMsg( "Zero srcRows or srcCols" );
return outputBlock; return outputBlock;
} }


Expand All @@ -737,20 +738,23 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex


size_t pixelSize = QgsRasterBlock::typeSize( mInput->dataType( bandNo ) ); size_t pixelSize = QgsRasterBlock::typeSize( mInput->dataType( bandNo ) );


if ( !outputBlock->reset( QgsRasterBlock::ARGB32_Premultiplied, width, height ) ) if ( !outputBlock->reset( mInput->dataType( bandNo ), width, height ) )
{ {
QgsDebugMsg( "Cannot reset block" );
delete inputBlock; delete inputBlock;
return outputBlock; return outputBlock;
} }
outputBlock->setNoDataValue( mInput->noDataValue( bandNo ) );


// TODO: fill by transparent // TODO: fill by no data or transparent


int srcRow, srcCol; int srcRow, srcCol;
for ( int i = 0; i < height; ++i ) for ( int i = 0; i < height; ++i )
{ {
for ( int j = 0; j < width; ++j ) for ( int j = 0; j < width; ++j )
{ {
srcRowCol( i, j, &srcRow, &srcCol ); srcRowCol( i, j, &srcRow, &srcCol );
QgsDebugMsgLevel( QString( "row = %1 col = %2 srcRow = %3 srcCol = %4" ).arg( i ).arg( j ).arg( srcRow ).arg( srcCol ), 5 );
size_t srcIndex = srcRow * mSrcCols + srcCol; size_t srcIndex = srcRow * mSrcCols + srcCol;
size_t destIndex = i * width + j; size_t destIndex = i * width + j;


Expand Down
1 change: 1 addition & 0 deletions src/plugins/grass/modules/default.qgc
Expand Up @@ -246,6 +246,7 @@
</section> </section>
<section label="Create random points"> <section label="Create random points">
<grass name="r.random"/> <grass name="r.random"/>
<grass name="r.random.raster"/>
<grass name="r.random.cells"/> <grass name="r.random.cells"/>
</section> </section>
<section label="Generate surface"> <section label="Generate surface">
Expand Down
Binary file added src/plugins/grass/modules/r.random.raster.1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/plugins/grass/modules/r.random.raster.2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/plugins/grass/modules/r.random.raster.qgm
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">

<qgisgrassmodule label="Create random raster" module="r.random" direct="1">
<option key="input"/>
<option key="n" answer="1" hidden="no"/>
<option key="raster_output" />
</qgisgrassmodule>
2 changes: 1 addition & 1 deletion src/plugins/grass/modules/r.surf.idw.qgm
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd"> <!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">


<qgisgrassmodule label="Inverse distance squared weighting raster interpolation" module="r.surf.idw"> <qgisgrassmodule label="Inverse distance squared weighting raster interpolation" module="r.surf.idw" direct="1">
<option key="input" /> <option key="input" />
<option key="npoints" /> <option key="npoints" />
<option key="output" /> <option key="output" />
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassmapcalc.cpp
Expand Up @@ -42,7 +42,7 @@ QgsGrassMapcalc::QgsGrassMapcalc(
QWidget * parent, Qt::WFlags f ) QWidget * parent, Qt::WFlags f )
: QMainWindow( iface->mainWindow(), Qt::Dialog ) : QMainWindow( iface->mainWindow(), Qt::Dialog )
, QgsGrassMapcalcBase( ) , QgsGrassMapcalcBase( )
, QgsGrassModuleOptions( tools, module, iface ) , QgsGrassModuleOptions( tools, module, iface, false )
, mTool( -1 ) , mTool( -1 )
, mObject( 0 ) , mObject( 0 )
, mConnector( 0 ) , mConnector( 0 )
Expand Down

0 comments on commit 4dc8499

Please sign in to comment.