Skip to content
Permalink
Browse files
Merge heatmap_fixes branch
  • Loading branch information
nyalldawson committed Mar 13, 2013
2 parents 032c5f5 + 239479a commit 04d9165f4007b3162c6cb135c11a9884a3ca592e
@@ -110,10 +110,10 @@ void Heatmap::run()
QgsRectangle myBBox = d.bbox();
int columns = d.columns();
int rows = d.rows();
float cellsize = d.cellSizeX(); // or d.cellSizeY(); both have the same value
float myDecay = d.decayRatio();
double cellsize = d.cellSizeX(); // or d.cellSizeY(); both have the same value
double myDecay = d.decayRatio();
int kernelShape = d.kernelShape();

// Start working on the input vector
QgsVectorLayer* inputLayer = d.inputVectorLayer();

@@ -168,8 +168,8 @@ void Heatmap::run()
int wField = 0;

// Handle different radius options
float radius;
float radiusToMapUnits = 1;
double radius;
double radiusToMapUnits = 1;
int myBuffer;
if ( d.variableRadius() )
{
@@ -230,7 +230,7 @@ void Heatmap::run()
// If radius is variable then fetch it and calculate new pixel buffer size
if ( d.variableRadius() )
{
radius = myFeature.attribute( rField ).toFloat() * radiusToMapUnits;
radius = myFeature.attribute( rField ).toDouble() * radiusToMapUnits;
myBuffer = bufferSize( radius, cellsize );
}

@@ -245,25 +245,25 @@ void Heatmap::run()
poBand->RasterIO( GF_Read, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 );

float weight = 1.0;
double weight = 1.0;
if ( d.weighted() )
{
weight = myFeature.attribute( wField ).toFloat();
weight = myFeature.attribute( wField ).toDouble();
}

for ( int xp = 0; xp <= myBuffer; xp++ )
{
for ( int yp = 0; yp <= myBuffer; yp++ )
{
float distance = sqrt( pow( xp, 2.0 ) + pow( yp, 2.0 ) );
double distance = sqrt( pow( xp, 2.0 ) + pow( yp, 2.0 ) );

// is pixel outside search bandwidth of feature?
if ( distance > myBuffer )
{
continue;
}

float pixelValue = weight * calculateKernelValue( distance, myBuffer, kernelShape );
double pixelValue = weight * calculateKernelValue( distance, myBuffer, kernelShape );

// clearing anamolies along the axes
if ( xp == 0 && yp == 0 )
@@ -308,8 +308,8 @@ void Heatmap::run()
* Local functions
*
*/
float Heatmap::mapUnitsOf( float meters, QgsCoordinateReferenceSystem layerCrs )

double Heatmap::mapUnitsOf( double meters, QgsCoordinateReferenceSystem layerCrs )
{
// Worker to transform metres input to mapunits
QgsDistanceArea da;
@@ -322,7 +322,7 @@ float Heatmap::mapUnitsOf( float meters, QgsCoordinateReferenceSystem layerCrs )
return meters / da.measureLine( QgsPoint( 0.0, 0.0 ), QgsPoint( 0.0, 1.0 ) );
}

int Heatmap::bufferSize( float radius, float cellsize )
int Heatmap::bufferSize( double radius, double cellsize )
{
// Calculate the buffer size in pixels

@@ -82,9 +82,9 @@ class Heatmap: public QObject, public QgisPlugin

private:
//! Worker to convert meters to map units
float mapUnitsOf( float meters, QgsCoordinateReferenceSystem crs );
double mapUnitsOf( double meters, QgsCoordinateReferenceSystem layerCrs );
//! Worker to calculate buffer size in pixels
int bufferSize( float radius, float cellsize );
int bufferSize( double radius, double cellsize );
//! Calculate the value given to a point width a given distance for a specified kernel shape
float calculateKernelValue( float distance, int bandwidth, int kernelShape );
//! Uniform kernel function
@@ -170,7 +170,7 @@ void HeatmapGui::on_columnLineEdit_editingFinished()

void HeatmapGui::on_cellXLineEdit_editingFinished()
{
mXcellsize = cellXLineEdit->text().toFloat();
mXcellsize = cellXLineEdit->text().toDouble();
mYcellsize = mXcellsize;
mRows = mBBox.height() / mYcellsize + 1;
mColumns = mBBox.width() / mXcellsize + 1;
@@ -180,7 +180,7 @@ void HeatmapGui::on_cellXLineEdit_editingFinished()

void HeatmapGui::on_cellYLineEdit_editingFinished()
{
mYcellsize = cellYLineEdit->text().toFloat();
mYcellsize = cellYLineEdit->text().toDouble();
mXcellsize = mYcellsize;
mRows = mBBox.height() / mYcellsize + 1;
mColumns = mBBox.width() / mXcellsize + 1;
@@ -281,10 +281,10 @@ void HeatmapGui::updateBBox()
mBBox = inputLayer->extent();
QgsCoordinateReferenceSystem layerCrs = inputLayer->crs();

float radiusInMapUnits = 0.0;
double radiusInMapUnits = 0.0;
if ( useRadius->isChecked() )
{
float maxInField = inputLayer->maximumValue( radiusFieldCombo->itemData( radiusFieldCombo->currentIndex() ).toInt() ).toFloat();
double maxInField = inputLayer->maximumValue( radiusFieldCombo->itemData( radiusFieldCombo->currentIndex() ).toInt() ).toDouble();

if ( radiusFieldUnitCombo->currentIndex() == HeatmapGui::Meters )
{
@@ -297,7 +297,7 @@ void HeatmapGui::updateBBox()
}
else
{
float radiusValue = mBufferLineEdit->text().toFloat();
double radiusValue = mBufferLineEdit->text().toDouble();
if ( mRadiusUnitCombo->currentIndex() == HeatmapGui::Meters )
{
radiusInMapUnits = mapUnitsOf( radiusValue, layerCrs );
@@ -325,7 +325,7 @@ void HeatmapGui::updateBBox()
}
}

float HeatmapGui::mapUnitsOf( float meters, QgsCoordinateReferenceSystem layerCrs )
double HeatmapGui::mapUnitsOf( double meters, QgsCoordinateReferenceSystem layerCrs )
{
// converter function to transform metres input to mapunits
// so that bounding box can be updated
@@ -356,9 +356,9 @@ bool HeatmapGui::variableRadius()
return useRadius->isChecked();
}

float HeatmapGui::radius()
double HeatmapGui::radius()
{
float radius = mBufferLineEdit->text().toFloat();
double radius = mBufferLineEdit->text().toDouble();
if ( mRadiusUnitCombo->currentIndex() == HeatmapGui::Meters )
{
radius = mapUnitsOf( radius, inputVectorLayer()->crs() );
@@ -380,9 +380,9 @@ int HeatmapGui::kernelShape()
return kernelShapeCombo->currentIndex();
}

float HeatmapGui::decayRatio()
double HeatmapGui::decayRatio()
{
return mDecayLineEdit->text().toFloat();
return mDecayLineEdit->text().toDouble();
}

int HeatmapGui::radiusField()
@@ -50,7 +50,7 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
bool variableRadius();

/** Returns the fixed radius value */
float radius();
double radius();

/** Return the radius Unit (meters/map units) */
int radiusUnit();
@@ -59,7 +59,7 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
int kernelShape();

/** Return the decay ratio */
float decayRatio();
double decayRatio();

/** Return the attribute field for variable radius */
int radiusField();
@@ -83,10 +83,10 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
int columns() { return mColumns; }

/** Returns the cell size X value */
float cellSizeX() { return mXcellsize; }
double cellSizeX() { return mXcellsize; }

/** Returns the cell size Y valuue */
float cellSizeY() { return mYcellsize; }
double cellSizeY() { return mYcellsize; }

/** Return the BBox */
QgsRectangle bbox() { return mBBox; }
@@ -96,7 +96,7 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase

// bbox of layer for lineedit changes
QgsRectangle mBBox;
float mXcellsize, mYcellsize;
double mXcellsize, mYcellsize;
int mRows, mColumns;

/** Function to check wether all constrains are satisfied and enable the OK button */
@@ -112,7 +112,7 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
void updateSize();

/** Convert Maters value to the corresponding map units based on Layer projection */
float mapUnitsOf( float meters, QgsCoordinateReferenceSystem layerCrs );
double mapUnitsOf( double meters, QgsCoordinateReferenceSystem layerCrs );

private slots:
void on_mButtonBox_accepted();

0 comments on commit 04d9165

Please sign in to comment.