[QGIS Commit] r14896 - in branches/raster-providers/src: core
core/raster providers/gdal providers/grass providers/wms
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Dec 12 13:28:34 EST 2010
Author: rblazek
Date: 2010-12-12 10:28:34 -0800 (Sun, 12 Dec 2010)
New Revision: 14896
Modified:
branches/raster-providers/src/core/qgscoordinatetransform.h
branches/raster-providers/src/core/qgsrasterdataprovider.h
branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
branches/raster-providers/src/core/raster/qgsrasterviewport.h
branches/raster-providers/src/providers/gdal/qgsgdalprovider.cpp
branches/raster-providers/src/providers/gdal/qgsgdalprovider.h
branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp
branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.h
branches/raster-providers/src/providers/wms/qgswmsprovider.cpp
branches/raster-providers/src/providers/wms/qgswmsprovider.h
Log:
disabled old transformation code in raster layer, prepared for reprojection
Modified: branches/raster-providers/src/core/qgscoordinatetransform.h
===================================================================
--- branches/raster-providers/src/core/qgscoordinatetransform.h 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/core/qgscoordinatetransform.h 2010-12-12 18:28:34 UTC (rev 14896)
@@ -111,13 +111,13 @@
* Get the QgsCoordinateReferenceSystem representation of the layer's coordinate system
* @return QgsCoordinateReferenceSystem of the layer's coordinate system
*/
- QgsCoordinateReferenceSystem& sourceCrs() { return mSourceCRS; }
+ const QgsCoordinateReferenceSystem& sourceCrs() const { return mSourceCRS; }
/*!
* Get the QgsCoordinateReferenceSystem representation of the map canvas coordinate system
* @return QgsCoordinateReferenceSystem of the map canvas coordinate system
*/
- QgsCoordinateReferenceSystem& destCRS() { return mDestCRS; }
+ const QgsCoordinateReferenceSystem& destCRS() const { return mDestCRS; }
/*! Transform the point from Source Coordinate System to Destination Coordinate System
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
Modified: branches/raster-providers/src/core/qgsrasterdataprovider.h
===================================================================
--- branches/raster-providers/src/core/qgsrasterdataprovider.h 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/core/qgsrasterdataprovider.h 2010-12-12 18:28:34 UTC (rev 14896)
@@ -26,6 +26,7 @@
#include "qgsdataprovider.h"
#include "qgscolorrampshader.h"
#include "qgsrasterpyramid.h"
+#include "qgscoordinatereferencesystem.h"
#include <cmath>
@@ -297,7 +298,7 @@
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 ) {};
+ virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theDestCRS, void *data ) {};
/** value representing null data */
virtual double noDataValue() const { return 0; }
Modified: branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterlayer.cpp 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/core/raster/qgsrasterlayer.cpp 2010-12-12 18:28:34 UTC (rev 14896)
@@ -27,6 +27,7 @@
#include "qgsrectangle.h"
#include "qgsrendercontext.h"
#include "qgscoordinatereferencesystem.h"
+#include "qgscoordinatetransform.h"
#include "gdalwarper.h"
#include "cpl_conv.h"
@@ -852,10 +853,16 @@
QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();
myRasterViewPort->mDrawnExtent = myRasterExtent;
+ if ( rendererContext.coordinateTransform() ) {
+ myRasterViewPort->mDestCRS = rendererContext.coordinateTransform()->destCRS();
+ } else {
+ myRasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid
+ }
// calculate raster pixel offsets from origin to clipped rect
// we're only interested in positive offsets where the origin of the raster
// is northwest of the origin of the view
+ /*
myRasterViewPort->rectXOffsetFloat = ( theViewExtent.xMinimum() - mLayerExtent.xMinimum() ) / qAbs( mGeoTransform[1] );
myRasterViewPort->rectYOffsetFloat = ( mLayerExtent.yMaximum() - theViewExtent.yMaximum() ) / qAbs( mGeoTransform[5] );
@@ -879,11 +886,13 @@
.arg( mGeoTransform[3] )
.arg( mGeoTransform[4] )
.arg( mGeoTransform[5] ), 3 );
+ */
// get dimensions of clipped raster image in raster pixel space/ RasterIO will do the scaling for us.
// So for example, if the user is zoomed in a long way, there may only be e.g. 5x5 pixels retrieved from
// the raw raster data, but rasterio will seamlessly scale the up to whatever the screen coordinats are
// e.g. a 600x800 display window (see next section below)
+ /*
myRasterViewPort->clippedXMin = ( myRasterExtent.xMinimum() - mGeoTransform[0] ) / mGeoTransform[1];
myRasterViewPort->clippedXMax = ( myRasterExtent.xMaximum() - mGeoTransform[0] ) / mGeoTransform[1];
myRasterViewPort->clippedYMin = ( myRasterExtent.yMinimum() - mGeoTransform[3] ) / mGeoTransform[5];
@@ -904,10 +913,13 @@
myRasterViewPort->clippedHeight =
static_cast<int>( ceil( myRasterViewPort->clippedYMax ) - floor( myRasterViewPort->clippedYMin ) );
-
+ */
// but make sure the intended SE corner extent doesn't exceed the SE corner
// of the source raster, otherwise GDAL's RasterIO gives an error and returns nothing.
// The SE corner = NW origin + dimensions of the image itself.
+
+ // This is no more necessary I believe, we read the block of data defined by extent, no need to think about raster size
+ /*
if (( myRasterViewPort->rectXOffset + myRasterViewPort->clippedWidth )
> mWidth )
{
@@ -920,31 +932,59 @@
myRasterViewPort->clippedHeight =
mHeight - myRasterViewPort->rectYOffset;
}
+ */
// get dimensions of clipped raster image in device coordinate space (this is the size of the viewport)
myRasterViewPort->topLeftPoint = theQgsMapToPixel.transform( myRasterExtent.xMinimum(), myRasterExtent.yMaximum() );
myRasterViewPort->bottomRightPoint = theQgsMapToPixel.transform( myRasterExtent.xMaximum(), myRasterExtent.yMinimum() );
- myRasterViewPort->drawableAreaXDim = static_cast<int>( qAbs(( myRasterViewPort->clippedWidth / theQgsMapToPixel.mapUnitsPerPixel() * mGeoTransform[1] ) ) + 0.5 );
- myRasterViewPort->drawableAreaYDim = static_cast<int>( qAbs(( myRasterViewPort->clippedHeight / theQgsMapToPixel.mapUnitsPerPixel() * mGeoTransform[5] ) ) + 0.5 );
+ // align to output device grid, i.e. floor/ceil to integers
+ // TODO: this should only be done if paint device is raster - screen, image
+ // for other devices (pdf) it can have floating point origin
+ // we could use floating point for raster devices as well, but respecting the
+ // output device grid should make it more effective as the resampling is done in
+ // the provider anyway
+ if ( true )
+ {
+ myRasterViewPort->topLeftPoint.setX( floor( myRasterViewPort->topLeftPoint.x() ) );
+ myRasterViewPort->topLeftPoint.setY( floor( myRasterViewPort->topLeftPoint.y() ) );
+ myRasterViewPort->bottomRightPoint.setX( ceil( myRasterViewPort->bottomRightPoint.x() ) );
+ myRasterViewPort->bottomRightPoint.setY( ceil( myRasterViewPort->bottomRightPoint.y() + 10 ) );
+ // recalc myRasterExtent to aligned values
+ myRasterExtent.set (
+ theQgsMapToPixel.toMapCoordinatesF ( myRasterViewPort->topLeftPoint.x(),
+ myRasterViewPort->bottomRightPoint.y() ),
+ theQgsMapToPixel.toMapCoordinatesF ( myRasterViewPort->bottomRightPoint.x(),
+ myRasterViewPort->topLeftPoint.y() )
+ );
+ }
+
+ //myRasterViewPort->drawableAreaXDim = static_cast<int>( qAbs(( myRasterViewPort->clippedWidth / theQgsMapToPixel.mapUnitsPerPixel() * mGeoTransform[1] ) ) + 0.5 );
+ //myRasterViewPort->drawableAreaYDim = static_cast<int>( qAbs(( myRasterViewPort->clippedHeight / theQgsMapToPixel.mapUnitsPerPixel() * mGeoTransform[5] ) ) + 0.5 );
+
+ myRasterViewPort->drawableAreaXDim = static_cast<int>( qAbs(( myRasterExtent.width() / theQgsMapToPixel.mapUnitsPerPixel() ) ));
+ myRasterViewPort->drawableAreaYDim = static_cast<int>( qAbs(( myRasterExtent.height() / theQgsMapToPixel.mapUnitsPerPixel() ) ));
+
//the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is becasue
//theQgsMapToPixel.mapUnitsPerPixel() is less then 1,
//so we will just get the pixel data and then render these special cases differently in paintImageToCanvas()
+ /*
if ( 2 >= myRasterViewPort->clippedWidth && 2 >= myRasterViewPort->clippedHeight )
{
myRasterViewPort->drawableAreaXDim = myRasterViewPort->clippedWidth;
myRasterViewPort->drawableAreaYDim = myRasterViewPort->clippedHeight;
}
-
+ */
QgsDebugMsgLevel( QString( "mapUnitsPerPixel = %1" ).arg( theQgsMapToPixel.mapUnitsPerPixel() ), 3 );
QgsDebugMsgLevel( QString( "mWidth = %1" ).arg( mWidth ), 3 );
QgsDebugMsgLevel( QString( "mHeight = %1" ).arg( mHeight ), 3 );
+ /*
QgsDebugMsgLevel( QString( "rectXOffset = %1" ).arg( myRasterViewPort->rectXOffset ), 3 );
QgsDebugMsgLevel( QString( "rectXOffsetFloat = %1" ).arg( myRasterViewPort->rectXOffsetFloat ), 3 );
QgsDebugMsgLevel( QString( "rectYOffset = %1" ).arg( myRasterViewPort->rectYOffset ), 3 );
QgsDebugMsgLevel( QString( "rectYOffsetFloat = %1" ).arg( myRasterViewPort->rectYOffsetFloat ), 3 );
-
+ */
QgsDebugMsgLevel( QString( "myRasterExtent.xMinimum() = %1" ).arg( myRasterExtent.xMinimum() ), 3 );
QgsDebugMsgLevel( QString( "myRasterExtent.xMaximum() = %1" ).arg( myRasterExtent.xMaximum() ), 3 );
QgsDebugMsgLevel( QString( "myRasterExtent.yMinimum() = %1" ).arg( myRasterExtent.yMinimum() ), 3 );
@@ -955,6 +995,7 @@
QgsDebugMsgLevel( QString( "topLeftPoint.y() = %1" ).arg( myRasterViewPort->topLeftPoint.y() ), 3 );
QgsDebugMsgLevel( QString( "bottomRightPoint.y() = %1" ).arg( myRasterViewPort->bottomRightPoint.y() ), 3 );
+ /*
QgsDebugMsgLevel( QString( "clippedXMin = %1" ).arg( myRasterViewPort->clippedXMin ), 3 );
QgsDebugMsgLevel( QString( "clippedXMax = %1" ).arg( myRasterViewPort->clippedXMax ), 3 );
QgsDebugMsgLevel( QString( "clippedYMin = %1" ).arg( myRasterViewPort->clippedYMin ), 3 );
@@ -962,9 +1003,10 @@
QgsDebugMsgLevel( QString( "clippedWidth = %1" ).arg( myRasterViewPort->clippedWidth ), 3 );
QgsDebugMsgLevel( QString( "clippedHeight = %1" ).arg( myRasterViewPort->clippedHeight ), 3 );
+ */
QgsDebugMsgLevel( QString( "drawableAreaXDim = %1" ).arg( myRasterViewPort->drawableAreaXDim ), 3 );
QgsDebugMsgLevel( QString( "drawableAreaYDim = %1" ).arg( myRasterViewPort->drawableAreaYDim ), 3 );
-
+
QgsDebugMsgLevel( "ReadXml: gray band name : " + mGrayBandName, 3 );
QgsDebugMsgLevel( "ReadXml: red band name : " + mRedBandName, 3 );
QgsDebugMsgLevel( "ReadXml: green band name : " + mGreenBandName, 3 );
@@ -981,6 +1023,8 @@
// Some providers were returning QImage directly, not they are passing ARGB data - ARGBDataType
if ( mDataProvider->capabilities() & QgsRasterDataProvider::Draw )
{
+ // Currently not used
+ /*
QgsDebugMsg( "Wanting a '" + mProviderKey + "' provider to draw this." );
// TODO this should be probably moved to WMS?
@@ -1008,13 +1052,12 @@
int pixelHeight = rasterPartRect.height() / theQgsMapToPixel.mapUnitsPerPixel() + 0.5;
- /*
- QgsDebugMsg( "**********WMS tile parameter***************" );
- QgsDebugMsg( "pixelWidth: " + QString::number( pixelWidth ) );
- QgsDebugMsg( "pixelHeight: " + QString::number( pixelHeight ) );
- QgsDebugMsg( "mapWidth: " + QString::number( rasterPartRect.width() ) );
- QgsDebugMsg( "mapHeight: " + QString::number( rasterPartRect.height(), 'f', 8 ) );
- QgsDebugMsg( "mapUnitsPerPixel: " + QString::number( theQgsMapToPixel.mapUnitsPerPixel() ) );*/
+ //QgsDebugMsg( "**********WMS tile parameter***************" );
+ //QgsDebugMsg( "pixelWidth: " + QString::number( pixelWidth ) );
+ //QgsDebugMsg( "pixelHeight: " + QString::number( pixelHeight ) );
+ //QgsDebugMsg( "mapWidth: " + QString::number( rasterPartRect.width() ) );
+ //QgsDebugMsg( "mapHeight: " + QString::number( rasterPartRect.height(), 'f', 8 ) );
+ //QgsDebugMsg( "mapUnitsPerPixel: " + QString::number( theQgsMapToPixel.mapUnitsPerPixel() ) );
QImage* image = mDataProvider->draw( rasterPartRect, pixelWidth, pixelHeight );
@@ -1075,6 +1118,7 @@
delete image;
}
}
+ */
}
else if ( mDataProvider->capabilities() & QgsRasterDataProvider::Data )
{
@@ -2022,6 +2066,13 @@
myMetadata += mCRS->toProj4();
myMetadata += "</p>\n";
+ myMetadata += "<p class=\"glossy\">";
+ myMetadata += tr( "Layer Extent (layer original source projection): " );
+ myMetadata += "</p>\n";
+ myMetadata += "<p>";
+ myMetadata += mDataProvider->extent().toString();
+ myMetadata += "</p>\n";
+
// output coordinate system
// TODO: this is not related to layer, to be removed? [MD]
#if 0
@@ -2275,6 +2326,7 @@
int myRequestValid;
// TODO: add 'has null value' to capabilities
+ /*
myRequestValid = 1;
double myValue = mDataProvider->noDataValue();
@@ -2286,7 +2338,11 @@
{
setNoDataValue( -9999.0 );
mValidNoDataValue = false;
+
}
+ */
+ setNoDataValue ( mDataProvider->noDataValue() );
+ mValidNoDataValue = mDataProvider->isNoDataValueValid();
}
}
@@ -2332,6 +2388,7 @@
mValidNoDataValue = false;
//Initialize the last view port structure, should really be a class
+ /*
mLastViewPort.rectXOffset = 0;
mLastViewPort.rectXOffsetFloat = 0.0;
mLastViewPort.rectYOffset = 0;
@@ -2342,6 +2399,7 @@
mLastViewPort.clippedYMax = 0.0;
mLastViewPort.clippedWidth = 0;
mLastViewPort.clippedHeight = 0;
+ */
mLastViewPort.drawableAreaXDim = 0;
mLastViewPort.drawableAreaYDim = 0;
}
@@ -2492,6 +2550,10 @@
mLayerExtent.setYMaximum( mbr.yMaximum() );
mLayerExtent.setYMinimum( mbr.yMinimum() );
+ mWidth = mDataProvider->xSize();
+ mHeight = mDataProvider->ySize();
+
+
// upper case the first letter of the layer name
QgsDebugMsg( "mLayerName: " + name() );
@@ -3009,6 +3071,7 @@
if ( mProviderKey.isEmpty() )
{
QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();
+ /*
myRasterViewPort->rectXOffset = 0;
myRasterViewPort->rectYOffset = 0;
myRasterViewPort->clippedXMin = 0;
@@ -3017,6 +3080,7 @@
myRasterViewPort->clippedYMax = 0;
myRasterViewPort->clippedWidth = mWidth;
myRasterViewPort->clippedHeight = mHeight;
+ */
myRasterViewPort->topLeftPoint = QgsPoint( 0, 0 );
myRasterViewPort->bottomRightPoint = QgsPoint( theQPixmap->width(), theQPixmap->height() );
myRasterViewPort->drawableAreaXDim = theQPixmap->width();
@@ -3042,6 +3106,7 @@
if ( mProviderKey.isEmpty() )
{
QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();
+ /*
myRasterViewPort->rectXOffset = 0;
myRasterViewPort->rectYOffset = 0;
myRasterViewPort->clippedXMin = 0;
@@ -3050,6 +3115,7 @@
myRasterViewPort->clippedYMax = 0;
myRasterViewPort->clippedWidth = mWidth;
myRasterViewPort->clippedHeight = mHeight;
+ */
myRasterViewPort->topLeftPoint = QgsPoint( 0, 0 );
myRasterViewPort->bottomRightPoint = QgsPoint( thepImage->width(), thepImage->height() );
myRasterViewPort->drawableAreaXDim = thepImage->width();
@@ -4421,8 +4487,10 @@
return false;
}
+// Not used
void QgsRasterLayer::paintImageToCanvas( QPainter* theQPainter, QgsRasterViewPort * theRasterViewPort, const QgsMapToPixel* theQgsMapToPixel, QImage* theImage )
{
+/*
// Set up the initial offset into the myQImage we want to copy to the map canvas
// This is useful when the source image pixels are larger than the screen image.
int paintXoffset = 0;
@@ -4560,6 +4628,7 @@
paintXoffset,
paintYoffset );
}
+*/
}
QString QgsRasterLayer::projectionWkt()
@@ -4576,6 +4645,7 @@
{
int size = mDataProvider->dataTypeSize(bandNo)/8;
+/*
QgsDebugMsg( "calling RasterIO with " +
QString( ", source NW corner: " ) + QString::number( viewPort->rectXOffset ) +
", " + QString::number( viewPort->rectYOffset ) +
@@ -4583,7 +4653,7 @@
", " + QString::number( viewPort->clippedHeight ) +
", dest size: " + QString::number( viewPort->drawableAreaXDim ) +
", " + QString::number( viewPort->drawableAreaYDim ) );
-
+*/
void *data = VSIMalloc( size * viewPort->drawableAreaXDim * viewPort->drawableAreaYDim );
/* Abort if out of memory */
@@ -4614,7 +4684,7 @@
viewPort->mDrawnExtent.xMaximum(),
viewPort->mDrawnExtent.yMaximum()
);
- mDataProvider->readBlock ( bandNo, partExtent, viewPort->drawableAreaXDim, viewPort->drawableAreaYDim, data );
+ mDataProvider->readBlock ( bandNo, partExtent, viewPort->drawableAreaXDim, viewPort->drawableAreaYDim, QgsCoordinateReferenceSystem(), data );
}
return data;
}
@@ -4789,7 +4859,8 @@
int pixels = mViewPort->drawableAreaXDim * mViewPort->drawableAreaYDim;
//maxPixelsInVirtualMemory = 1000;
int mNumPartImages = pixels / maxPixelsInVirtualMemory + 1.0;
- mNumRasterRowsPerPart = ( double )mViewPort->clippedHeight / ( double )mNumPartImages + 0.5;
+ //mNumRasterRowsPerPart = ( double )mViewPort->clippedHeight / ( double )mNumPartImages + 0.5;
+ mNumRasterRowsPerPart = ( double )mViewPort->drawableAreaYDim / ( double )mNumPartImages + 0.5;
mCurrentPartRasterMin = -1;
mCurrentPartRasterMax = -1;
@@ -4800,7 +4871,9 @@
createNextPartImage();
- if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight )
+ // TODO
+ //if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight )
+ if ( false )
{
//use Peter's fix for zoomed in rasters
mDrawPixelRect = true;
@@ -4850,19 +4923,24 @@
{
if ( mWritingEnabled )
{
- if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight )
+ // TODO: consider similar system with raster providers, see the comment
+ // in QgsRasterImageBuffer::drawPixelRectangle()
+ // e.g request the block with raster resolution and draw pixels as rectangles
+ //if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight )
+ if ( false )
{
drawPixelRectangle();
}
else
{
- int paintXoffset = 0;
- int paintYoffset = 0;
- int imageX = 0;
- int imageY = 0;
+ //int paintXoffset = 0;
+ //int paintYoffset = 0;
+ double imageX = 0;
+ double imageY = 0;
if ( mMapToPixel )
{
+ /*
paintXoffset = static_cast<int>(
( mViewPort->rectXOffsetFloat -
mViewPort->rectXOffset )
@@ -4876,16 +4954,24 @@
/ mMapToPixel->mapUnitsPerPixel()
* qAbs( mGeoTransform[5] )
);
-
- imageX = static_cast<int>( mViewPort->topLeftPoint.x() + 0.5 );
- imageY = static_cast<int>( mViewPort->topLeftPoint.y() + 0.5 + qAbs( mGeoTransform[5] ) * mCurrentPartRasterMin / mMapToPixel->mapUnitsPerPixel() );
+ */
+ //imageX = static_cast<int>( mViewPort->topLeftPoint.x() + 0.5 );
+ //imageY = static_cast<int>( mViewPort->topLeftPoint.y() + 0.5 + qAbs( mGeoTransform[5] ) * mCurrentPartRasterMin / mMapToPixel->mapUnitsPerPixel() );
+ imageX = mViewPort->topLeftPoint.x();
+ imageY = mViewPort->topLeftPoint.y() + mCurrentPartRasterMin / mMapToPixel->mapUnitsPerPixel();
}
+ /*
mPainter->drawImage( imageX, //the top-left point in the paint device
imageY,
*mCurrentImage,
paintXoffset, //specifies the top-left point in image
paintYoffset );
+ */
+ QgsDebugMsg( QString("mCurrentPartRasterMin = %1").arg( mCurrentPartRasterMin) );
+ QgsDebugMsg( QString("imageX = %1 imageY = %2").arg(imageX).arg(imageY) );
+ mPainter->drawImage( QPointF ( imageX, imageY ), //the top-left point in the paint device
+ *mCurrentImage );
}
}
}
@@ -4894,8 +4980,10 @@
CPLFree( mCurrentGDALData ); mCurrentGDALData = 0;
mCurrentPart++; // NEW
- QgsDebugMsg( QString("mCurrentPartRasterMax = %1 mViewPort->clippedHeight = %2").arg(mCurrentPartRasterMax).arg(mViewPort->clippedHeight) );
- if ( mCurrentPartRasterMax >= mViewPort->clippedHeight )
+ //QgsDebugMsg( QString("mCurrentPartRasterMax = %1 mViewPort->clippedHeight = %2").arg(mCurrentPartRasterMax).arg(mViewPort->clippedHeight) );
+ QgsDebugMsg( QString("mCurrentPartRasterMax = %1 mViewPort->drawableAreaYDim = %2").arg(mCurrentPartRasterMax).arg(mViewPort->drawableAreaYDim) );
+ //if ( mCurrentPartRasterMax >= mViewPort->clippedHeight )
+ if ( mCurrentPartRasterMax >= mViewPort->drawableAreaYDim )
{
return false; //already at the end...
}
@@ -4903,9 +4991,11 @@
mCurrentPartRasterMin = mCurrentPartRasterMax + 1;
mCurrentPartRasterMax = mCurrentPartRasterMin + mNumRasterRowsPerPart;
- if ( mCurrentPartRasterMax > mViewPort->clippedHeight )
+ //if ( mCurrentPartRasterMax > mViewPort->clippedHeight )
+ if ( mCurrentPartRasterMax > mViewPort->drawableAreaYDim )
{
- mCurrentPartRasterMax = mViewPort->clippedHeight;
+ //mCurrentPartRasterMax = mViewPort->clippedHeight;
+ mCurrentPartRasterMax = mViewPort->drawableAreaYDim;
}
mCurrentRow = mCurrentPartRasterMin;
mCurrentPartImageRow = 0;
@@ -4923,24 +5013,30 @@
int overlapRows = 0;
if ( mMapToPixel )
{
+ // TODO: do we still need overlaps?
overlapRows = mMapToPixel->mapUnitsPerPixel() / qAbs( mGeoTransform[5] ) + 2;
}
- if ( mCurrentPartRasterMax + overlapRows >= mViewPort->clippedHeight )
+ //if ( mCurrentPartRasterMax + overlapRows >= mViewPort->clippedHeight )
+ if ( mCurrentPartRasterMax + overlapRows >= mViewPort->drawableAreaYDim )
{
overlapRows = 0;
}
int rasterYSize = mCurrentPartRasterMax - mCurrentPartRasterMin + overlapRows;
+ QgsDebugMsg( "rasterYSize = " + QString::number( rasterYSize ));
- if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight ) //for zoomed in rasters
+ // TODO: consider something like this
+ //if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight ) //for zoomed in rasters
+ if ( false )
{
- rasterYSize = mViewPort->clippedHeight;
- ySize = mViewPort->drawableAreaYDim;
+ //rasterYSize = mViewPort->clippedHeight;
+ //ySize = mViewPort->drawableAreaYDim;
}
else //normal mode
{
if ( mMapToPixel )
{
- ySize = qAbs((( rasterYSize ) / mMapToPixel->mapUnitsPerPixel() * mGeoTransform[5] ) ) + 0.5;
+ // makes no more sense
+ //ySize = qAbs((( rasterYSize ) / mMapToPixel->mapUnitsPerPixel() * mGeoTransform[5] ) ) + 0.5;
}
}
QgsDebugMsg( QString("xSize = %1 ySize = %2").arg(xSize).arg(ySize) );
@@ -4968,7 +5064,7 @@
QgsDebugMsg( QString("mCurrentRow = %1 yMaximum = %2 ySize = %3 mapUnitsPerPixel = %4").arg(mCurrentRow).arg(mViewPort->mDrawnExtent.yMaximum()).arg(ySize).arg(mMapToPixel->mapUnitsPerPixel()) );
QgsRectangle partExtent ( mViewPort->mDrawnExtent.xMinimum(), yMin,
mViewPort->mDrawnExtent.xMaximum(), yMax );
- mDataProvider->readBlock ( mBandNo, partExtent, xSize, ySize, mCurrentGDALData );
+ mDataProvider->readBlock ( mBandNo, partExtent, xSize, ySize, mViewPort->mDestCRS, mCurrentGDALData );
// TODO - error check - throw exception
@@ -4994,6 +5090,11 @@
void QgsRasterImageBuffer::drawPixelRectangle()
{
+// TODO: consider using similar with raster providers, originaly it was used only with
+// 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight
+// but why? but I believe that it should be used always if the ration of original
+// raster resolution and device resolution is under certain limit
+/*
// Set up the initial offset into the myQImage we want to copy to the map canvas
// This is useful when the source image pixels are larger than the screen image.
int paintXoffset = 0;
@@ -5014,6 +5115,8 @@
/ mMapToPixel->mapUnitsPerPixel()
* qAbs( mGeoTransform[5] )
);
+
+
}
//fix for zoomed in rasters
@@ -5112,6 +5215,7 @@
}
}
}
+*/
}
// Keep this for now, it is used by Python interface!!!
Modified: branches/raster-providers/src/core/raster/qgsrasterviewport.h
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterviewport.h 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/core/raster/qgsrasterviewport.h 2010-12-12 18:28:34 UTC (rev 14896)
@@ -19,6 +19,7 @@
#define QGSRASTERVIEWPORT_H
#include <qgspoint.h>
+#include "qgscoordinatetransform.h"
/** \ingroup core
* This class provides details of the viewable area that a raster will
@@ -33,38 +34,38 @@
// RASTER SPACE
/** \brief The offset from the left hand edge of the raster for the rectangle that will be drawn to screen.
* TODO Check this explanation is correc!*/
- int rectXOffset;
- float rectXOffsetFloat;
+ //int rectXOffset;
+ //float rectXOffsetFloat;
/** \brief The offset from the bottom edge of the raster for the rectangle that will be drawn to screen.
* TODO Check this explanation is correc!*/
- int rectYOffset;
- float rectYOffsetFloat;
+ //int rectYOffset;
+ //float rectYOffsetFloat;
// RASTER SPACE
/** \brief Lower left X dimension of clipped raster image in raster pixel space.
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
* be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
* whatever the screen coordinates are (e.g. a 600x800 display window) */
- double clippedXMin;
+ //double clippedXMin;
/** \brief Top Right X dimension of clipped raster image in raster pixel space.
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
* be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
* whatever the screen coordinates are (e.g. a 600x800 display window) */
- double clippedXMax;
+ //double clippedXMax;
/** \brief Lower left Y dimension of clipped raster image in raster pixel space.
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
* be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
* whatever the screen coordinates are (e.g. a 600x800 display window) */
- double clippedYMin;
+ //double clippedYMin;
/** \brief Top Right X dimension of clipped raster image in raster pixel space.
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
* be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
* whatever the screen coordinates are (e.g. a 600x800 display window) */
- double clippedYMax;
+ //double clippedYMax;
/** \brief Distance in pixels from clippedXMin to clippedXMax. */
- int clippedWidth;
+ //int clippedWidth;
/** \brief Distance in pixels from clippedYMin to clippedYMax */
- int clippedHeight;
+ //int clippedHeight;
// NOT IN MAP SPACE BUT DEVICE SPACE
/** \brief Coordinate (in geographic coordinate system) of top left corner of the part of the raster that
@@ -84,6 +85,9 @@
// intersection of current map extent and layer extent
QgsRectangle mDrawnExtent;
+
+ // Target coordinate system
+ QgsCoordinateReferenceSystem mDestCRS;
};
#endif //QGSRASTERVIEWPORT_H
Modified: branches/raster-providers/src/providers/gdal/qgsgdalprovider.cpp
===================================================================
--- branches/raster-providers/src/providers/gdal/qgsgdalprovider.cpp 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/providers/gdal/qgsgdalprovider.cpp 2010-12-12 18:28:34 UTC (rev 14896)
@@ -44,7 +44,9 @@
#include "gdalwarper.h"
#include "ogr_spatialref.h"
#include "cpl_conv.h"
+#include "cpl_string.h"
+
static QString PROVIDER_KEY = "gdal";
static QString PROVIDER_DESCRIPTION = "GDAL provider";
@@ -203,8 +205,36 @@
double myNoDataValue = GDALGetRasterNoDataValue( GDALGetRasterBand( mGdalDataset, 1 ), &isValid );
if ( isValid )
{
+ QgsDebugMsg( QString("GDALGetRasterNoDataValue = %1").arg( myNoDataValue ) ) ;
mNoDataValue = myNoDataValue;
mValidNoDataValue = true;
+ }
+ else
+ {
+ // But we need a null value in case of reprojection and BTW also for
+ // aligned margines
+
+ switch ( dataType( 0 ) ) {
+ case QgsRasterDataProvider::Byte:
+ mNoDataValue = 255.0;
+ break;
+ case QgsRasterDataProvider::Int16:
+ mNoDataValue = -32768.0;
+ break;
+ case QgsRasterDataProvider::UInt16:
+ mNoDataValue = 65535.0;
+ break;
+ case QgsRasterDataProvider::Int32:
+ mNoDataValue = -2147483648.0;
+ break;
+ case QgsRasterDataProvider::UInt32:
+ mNoDataValue = 4294967295.0;
+ break;
+ default:
+ mNoDataValue = std::numeric_limits<int>::max();
+ }
+ QgsDebugMsg( QString("GDALGetRasterNoDataValue not set, using = %1").arg( mNoDataValue ) );
+ mValidNoDataValue = true;
}
QgsDebugMsg( QString("mNoDataValue = %1").arg ( mNoDataValue ) );
@@ -434,11 +464,12 @@
GDALReadBlock( myGdalBand, xBlock, yBlock, block );
}
-void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent, int thePixelWidth, int thePixelHeight, void *theBlock )
+void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent, int thePixelWidth, int thePixelHeight, QgsCoordinateReferenceSystem theDestCRS, void *theBlock )
{
QgsDebugMsg( "thePixelWidth = " + QString::number( thePixelWidth ) );
QgsDebugMsg( "thePixelHeight = " + QString::number( thePixelHeight ) );
QgsDebugMsg( "theExtent: " + theExtent.toString() );
+ QgsDebugMsg( "theDestCRS: " + theDestCRS.toWkt() );
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
@@ -453,7 +484,9 @@
QString myMemDsn;
myMemDsn.sprintf ( "DATAPOINTER = %p", theBlock );
QgsDebugMsg( myMemDsn );
+
+ // TODO: more bands support
myMemDsn.sprintf ( "MEM:::DATAPOINTER=%u,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE=%s,PIXELOFFSET=0,LINEOFFSET=0,BANDOFFSET=0", (int)theBlock, thePixelWidth, thePixelHeight, GDALGetDataTypeName( myGdalDataType ) );
QgsDebugMsg( "Open GDAL MEM : " + myMemDsn );
@@ -469,9 +502,11 @@
+ QString::fromUtf8( CPLGetLastErrorMsg() ) );
return;
}
+
// TODO add CRS to method params
//GDALSetProjection( myGdalMemDataset, crs().toWkt().toAscii().constData() );
GDALSetProjection( myGdalMemDataset, GDALGetProjectionRef( mGdalDataset ) );
+ //GDALSetProjection( myGdalMemDataset, theDestCRS.toWkt().toAscii().constData() );
double myMemGeoTransform[6];
myMemGeoTransform[0] = theExtent.xMinimum(); /* top left x */
@@ -519,7 +554,31 @@
CPLAssert( myWarpOptions->pTransformerArg != NULL);
myWarpOptions->pfnTransformer = GDALGenImgProjTransform;
+ //double myNoDataRow = (double *) CPLMalloc( sizeof(double) * thePixelWidth );
+
+
+ myWarpOptions->padfDstNoDataReal = (double *) CPLMalloc( myWarpOptions->nBandCount * sizeof(double));
+ myWarpOptions->padfDstNoDataImag = (double *) CPLMalloc( myWarpOptions->nBandCount * sizeof(double));
+
+ for ( int i = 0; i < myWarpOptions->nBandCount; i++ )
+ {
+
+ myWarpOptions->padfDstNoDataReal[i] = mNoDataValue;
+ myWarpOptions->padfDstNoDataImag[i] = 0.0;
+
+ GDALSetRasterNoDataValue( GDALGetRasterBand( myGdalMemDataset,
+ myWarpOptions->panDstBands[i] ),
+ myWarpOptions->padfDstNoDataReal[i] );
+
+ }
+
+ // TODO optimize somehow to avoid no data init if not necessary
+ // i.e. no projection, but there is also the problem with margine
+ myWarpOptions->papszWarpOptions =
+ CSLSetNameValue(myWarpOptions->papszWarpOptions,"INIT_DEST", "NO_DATA" );
+
+
GDALWarpOperation myOperation;
myOperation.Initialize( myWarpOptions );
Modified: branches/raster-providers/src/providers/gdal/qgsgdalprovider.h
===================================================================
--- branches/raster-providers/src/providers/gdal/qgsgdalprovider.h 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/providers/gdal/qgsgdalprovider.h 2010-12-12 18:28:34 UTC (rev 14896)
@@ -200,7 +200,7 @@
void readBlock( int bandNo, int xBlock, int yBlock, void *data );
- void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
+ void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theDestCRS, void *data );
double noDataValue() const;
void computeMinMax(int bandNo);
Modified: branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp
===================================================================
--- branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp 2010-12-12 18:28:34 UTC (rev 14896)
@@ -201,7 +201,7 @@
memcpy( block, data.data(), size );
}
-void QgsGrassRasterProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight, void *block )
+void QgsGrassRasterProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight, QgsCoordinateReferenceSystem theDestCRS, void *block )
{
QgsDebugMsg( "Entered" );
QgsDebugMsg( "pixelWidth = " + QString::number( pixelWidth ) );
Modified: branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.h
===================================================================
--- branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.h 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.h 2010-12-12 18:28:34 UTC (rev 14896)
@@ -191,7 +191,7 @@
void readBlock( int bandNo, int xBlock, int yBlock, void *data );
- void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
+ void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theDestCRS, void *data );
double noDataValue() const;
double minimumValue(int bandNo)const;
Modified: branches/raster-providers/src/providers/wms/qgswmsprovider.cpp
===================================================================
--- branches/raster-providers/src/providers/wms/qgswmsprovider.cpp 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/providers/wms/qgswmsprovider.cpp 2010-12-12 18:28:34 UTC (rev 14896)
@@ -678,7 +678,7 @@
return cachedImage;
}
-void QgsWmsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight, void *block )
+void QgsWmsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight, QgsCoordinateReferenceSystem theDestCRS, void *block )
{
QgsDebugMsg( "Entered" );
// TODO: optimize to avoid writing to QImage
Modified: branches/raster-providers/src/providers/wms/qgswmsprovider.h
===================================================================
--- branches/raster-providers/src/providers/wms/qgswmsprovider.h 2010-12-12 17:36:44 UTC (rev 14895)
+++ branches/raster-providers/src/providers/wms/qgswmsprovider.h 2010-12-12 18:28:34 UTC (rev 14896)
@@ -459,7 +459,7 @@
*/
QImage *draw( QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight );
- void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
+ void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theDestCRS, void *data );
/** Return the extent for this data layer
More information about the QGIS-commit
mailing list