Skip to content

Commit

Permalink
Convert radius to a float, not an integer. Fixes heatmaps created wit…
Browse files Browse the repository at this point in the history
…h a radius < 1.
  • Loading branch information
nyalldawson committed Mar 12, 2013
1 parent 7942be9 commit 3b8cbc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/plugins/heatmap/heatmap.cpp
Expand Up @@ -172,7 +172,7 @@ void Heatmap::run()
rField = d.radiusField();
myAttrList.append( rField );
QgsDebugMsg( QString( "Radius Field index received: %1" ).arg( rField ) );

// If not using map units, then calculate a conversion factor to convert the radii to map units
if ( d.radiusUnit() == HeatmapGui::Meters )
{
Expand All @@ -184,13 +184,13 @@ void Heatmap::run()
radius = d.radius(); // radius returned by d.radius() is already in map units
myBuffer = bufferSize( radius, cellsize );
}

if ( d.weighted() )
{
wField = d.weightField();
myAttrList.append( wField );
}

// This might have attributes or mightnot have attibutes at all
// based on the variableRadius() and weighted()
QgsFeatureIterator fit = inputLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( myAttrList ) );
Expand Down Expand Up @@ -222,14 +222,14 @@ void Heatmap::run()
{
continue;
}

// If radius is variable then fetch it and calculate new pixel buffer size
if ( d.variableRadius() )
{
radius = myFeature.attribute( rField ).toFloat() * radiusToMapUnits;
myBuffer = bufferSize( radius, cellsize );
}

int blockSize = 2 * myBuffer + 1; //Block SIDE would be more appropriate
// calculate the pixel position
unsigned int xPosition, yPosition;
Expand All @@ -252,13 +252,13 @@ void Heatmap::run()
for ( int yp = 0; yp <= myBuffer; yp++ )
{
float distance = sqrt( pow( xp, 2.0 ) + pow( yp, 2.0 ) );

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

float pixelValue = weight * ( 1 - (( 1 - myDecay ) * distance / myBuffer ) );

// clearing anamolies along the axes
Expand Down Expand Up @@ -304,7 +304,7 @@ void Heatmap::run()
* Local functions
*
*/

float Heatmap::mapUnitsOf( float meters, QgsCoordinateReferenceSystem layerCrs )
{
// Worker to transform metres input to mapunits
Expand All @@ -328,8 +328,8 @@ int Heatmap::bufferSize( float radius, float cellsize )
++buffer;
}
return buffer;
}
}


// Unload the plugin by cleaning up the GUI
void Heatmap::unload()
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/heatmap/heatmapgui.cpp
Expand Up @@ -358,7 +358,7 @@ bool HeatmapGui::variableRadius()

float HeatmapGui::radius()
{
float radius = mBufferLineEdit->text().toInt();
float radius = mBufferLineEdit->text().toFloat();
if ( mRadiusUnitCombo->currentIndex() == HeatmapGui::Meters )
{
radius = mapUnitsOf( radius, inputVectorLayer()->crs() );
Expand Down

0 comments on commit 3b8cbc2

Please sign in to comment.