Skip to content

Commit

Permalink
heatmap plugin: fix labeling s/metre/layer units/ (fixes #11276)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 18, 2015
1 parent 6bd96b2 commit c373d7b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/plugins/heatmap/heatmap.cpp
Expand Up @@ -202,7 +202,7 @@ void Heatmap::run()
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 )
if ( d.radiusUnit() == HeatmapGui::LayerUnits )
{
radiusToMapUnits = mapUnitsOf( 1, inputLayer->crs() );
}
Expand Down Expand Up @@ -364,17 +364,17 @@ void Heatmap::run()
*
*/

double Heatmap::mapUnitsOf( double meters, const QgsCoordinateReferenceSystem& layerCrs )
double Heatmap::mapUnitsOf( double layerdist, const QgsCoordinateReferenceSystem& layerCrs )
{
// Worker to transform metres input to mapunits
// Worker to transform layer input to mapunits
QgsDistanceArea da;
da.setSourceCrs( layerCrs.srsid() );
da.setEllipsoid( layerCrs.ellipsoidAcronym() );
if ( da.geographic() )
{
da.setEllipsoidalMode( true );
}
return meters / da.measureLine( QgsPoint( 0.0, 0.0 ), QgsPoint( 0.0, 1.0 ) );
return layerdist / da.measureLine( QgsPoint( 0.0, 0.0 ), QgsPoint( 0.0, 1.0 ) );
}

int Heatmap::bufferSize( double radius, double cellsize )
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/heatmap/heatmap.h
Expand Up @@ -102,8 +102,8 @@ class Heatmap: public QObject, public QgisPlugin
private:
double mDecay;

//! Worker to convert meters to map units
double mapUnitsOf( double meters, const QgsCoordinateReferenceSystem& layerCrs );
//! Worker to convert layer to map units
double mapUnitsOf( double dist, const QgsCoordinateReferenceSystem& layerCrs );
//! Worker to calculate buffer size in pixels
int bufferSize( double radius, double cellsize );
//! Calculate the value given to a point width a given distance for a specified kernel shape
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/heatmap/heatmapgui.cpp
Expand Up @@ -361,11 +361,11 @@ double HeatmapGui::estimateRadius()

double estimate = maxExtent / 30;

if ( mBufferUnitCombo->currentIndex() == HeatmapGui::Meters )
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
{
// metres selected, so convert estimate from map units
// layer units selected, so convert estimate from map units
QgsCoordinateReferenceSystem layerCrs = inputLayer->crs();
estimate = estimate / mapUnitsOf( 1, layerCrs );
estimate /= mapUnitsOf( 1, layerCrs );
}

// Make estimate pretty by rounding off to first digit only (eg 356->300, 0.567->0.5)
Expand Down Expand Up @@ -447,7 +447,7 @@ void HeatmapGui::updateBBox()
int idx = inputLayer->fields().indexFromName( mRadiusFieldCombo->currentField() );
double maxInField = inputLayer->maximumValue( idx ).toDouble();

if ( mRadiusFieldUnitCombo->currentIndex() == HeatmapGui::Meters )
if ( mRadiusFieldUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
{
radiusInMapUnits = mapUnitsOf( maxInField, layerCrs );
}
Expand All @@ -459,7 +459,7 @@ void HeatmapGui::updateBBox()
else
{
double radiusValue = mBufferSizeLineEdit->text().toDouble();
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::Meters )
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
{
radiusInMapUnits = mapUnitsOf( radiusValue, layerCrs );
}
Expand All @@ -481,9 +481,9 @@ void HeatmapGui::updateBBox()
updateSize();
}

double HeatmapGui::mapUnitsOf( double meters, const QgsCoordinateReferenceSystem& layerCrs ) const
double HeatmapGui::mapUnitsOf( double dist, const QgsCoordinateReferenceSystem& layerCrs ) const
{
// converter function to transform metres input to mapunits
// converter function to transform layer input to mapunits
// so that bounding box can be updated
QgsDistanceArea da;
da.setSourceCrs( layerCrs.srsid() );
Expand All @@ -493,8 +493,8 @@ double HeatmapGui::mapUnitsOf( double meters, const QgsCoordinateReferenceSystem
da.setEllipsoidalMode( true );
}
double unitDistance = da.measureLine( QgsPoint( 0.0, 0.0 ), QgsPoint( 0.0, 1.0 ) );
QgsDebugMsg( QString( "Converted %1 meters to %2 mapunits" ).arg( meters ).arg( meters / unitDistance ) );
return meters / unitDistance;
QgsDebugMsg( QString( "Converted %1 layer to %2 map units" ).arg( dist ).arg( dist / unitDistance ) );
return dist / unitDistance;
}
/*
*
Expand All @@ -515,7 +515,7 @@ bool HeatmapGui::variableRadius() const
double HeatmapGui::radius() const
{
double radius = mBufferSizeLineEdit->text().toDouble();
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::Meters )
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
{
radius = mapUnitsOf( radius, inputVectorLayer()->crs() );
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/heatmap/heatmapgui.h
Expand Up @@ -33,7 +33,7 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
// Should have been private, made public to be used in heatmap.cpp
enum mBufferType
{
Meters,
LayerUnits,
MapUnits
};

Expand All @@ -46,7 +46,7 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
/** Returns the fixed radius value */
double radius() const;

/** Return the radius Unit (meters/map units) */
/** Return the radius unit (layer/map units) */
int radiusUnit() const;

/** Return the selected kernel shape */
Expand Down Expand Up @@ -119,8 +119,8 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
/** Update the LineEdits cellsize and row&col values */
void updateSize();

/** Convert Maters value to the corresponding map units based on Layer projection */
double mapUnitsOf( double meters, const QgsCoordinateReferenceSystem& layerCrs ) const;
/** Convert layer distance value to the corresponding map units based on layer projection */
double mapUnitsOf( double dist, const QgsCoordinateReferenceSystem& layerCrs ) const;

/** Estimate a reasonable starting value for the radius field */
double estimateRadius();
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/heatmap/heatmapguibase.ui
Expand Up @@ -89,7 +89,7 @@
<widget class="QComboBox" name="mBufferUnitCombo">
<item>
<property name="text">
<string>meters</string>
<string>layer units</string>
</property>
</item>
<item>
Expand Down Expand Up @@ -269,7 +269,7 @@
</property>
<item>
<property name="text">
<string>meters</string>
<string>layer units</string>
</property>
</item>
<item>
Expand Down

0 comments on commit c373d7b

Please sign in to comment.