Skip to content

Commit 644bfbb

Browse files
committed
heatmap plugin: fix labeling s/metre/layer units/ (fixes #11276)
(backports from commit c373d7b)
1 parent e7a981c commit 644bfbb

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

src/plugins/heatmap/heatmap.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void Heatmap::run()
202202
QgsDebugMsg( QString( "Radius Field index received: %1" ).arg( rField ) );
203203

204204
// If not using map units, then calculate a conversion factor to convert the radii to map units
205-
if ( d.radiusUnit() == HeatmapGui::Meters )
205+
if ( d.radiusUnit() == HeatmapGui::LayerUnits )
206206
{
207207
radiusToMapUnits = mapUnitsOf( 1, inputLayer->crs() );
208208
}
@@ -363,17 +363,17 @@ void Heatmap::run()
363363
*
364364
*/
365365

366-
double Heatmap::mapUnitsOf( double meters, QgsCoordinateReferenceSystem layerCrs )
366+
double Heatmap::mapUnitsOf( double layerdist, const QgsCoordinateReferenceSystem &layerCrs )
367367
{
368-
// Worker to transform metres input to mapunits
368+
// Worker to transform layer input to mapunits
369369
QgsDistanceArea da;
370370
da.setSourceCrs( layerCrs.srsid() );
371371
da.setEllipsoid( layerCrs.ellipsoidAcronym() );
372372
if ( da.geographic() )
373373
{
374374
da.setEllipsoidalMode( true );
375375
}
376-
return meters / da.measureLine( QgsPoint( 0.0, 0.0 ), QgsPoint( 0.0, 1.0 ) );
376+
return layerdist / da.measureLine( QgsPoint( 0.0, 0.0 ), QgsPoint( 0.0, 1.0 ) );
377377
}
378378

379379
int Heatmap::bufferSize( double radius, double cellsize )

src/plugins/heatmap/heatmap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ class Heatmap: public QObject, public QgisPlugin
102102
private:
103103
double mDecay;
104104

105-
//! Worker to convert meters to map units
106-
double mapUnitsOf( double meters, QgsCoordinateReferenceSystem layerCrs );
105+
//! Worker to convert layer to map units
106+
double mapUnitsOf( double dist, const QgsCoordinateReferenceSystem& layerCrs );
107107
//! Worker to calculate buffer size in pixels
108108
int bufferSize( double radius, double cellsize );
109109
//! Calculate the value given to a point width a given distance for a specified kernel shape

src/plugins/heatmap/heatmapgui.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ double HeatmapGui::estimateRadius()
361361

362362
double estimate = maxExtent / 30;
363363

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

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

450-
if ( mRadiusFieldUnitCombo->currentIndex() == HeatmapGui::Meters )
450+
if ( mRadiusFieldUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
451451
{
452452
radiusInMapUnits = mapUnitsOf( maxInField, layerCrs );
453453
}
@@ -459,7 +459,7 @@ void HeatmapGui::updateBBox()
459459
else
460460
{
461461
double radiusValue = mBufferSizeLineEdit->text().toDouble();
462-
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::Meters )
462+
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
463463
{
464464
radiusInMapUnits = mapUnitsOf( radiusValue, layerCrs );
465465
}
@@ -481,9 +481,9 @@ void HeatmapGui::updateBBox()
481481
updateSize();
482482
}
483483

484-
double HeatmapGui::mapUnitsOf( double meters, QgsCoordinateReferenceSystem layerCrs ) const
484+
double HeatmapGui::mapUnitsOf( double dist, const QgsCoordinateReferenceSystem& layerCrs ) const
485485
{
486-
// converter function to transform metres input to mapunits
486+
// converter function to transform layer input to mapunits
487487
// so that bounding box can be updated
488488
QgsDistanceArea da;
489489
da.setSourceCrs( layerCrs.srsid() );
@@ -493,8 +493,8 @@ double HeatmapGui::mapUnitsOf( double meters, QgsCoordinateReferenceSystem layer
493493
da.setEllipsoidalMode( true );
494494
}
495495
double unitDistance = da.measureLine( QgsPoint( 0.0, 0.0 ), QgsPoint( 0.0, 1.0 ) );
496-
QgsDebugMsg( QString( "Converted %1 meters to %2 mapunits" ).arg( meters ).arg( meters / unitDistance ) );
497-
return meters / unitDistance;
496+
QgsDebugMsg( QString( "Converted %1 layer to %2 map units" ).arg( dist ).arg( dist / unitDistance ) );
497+
return dist / unitDistance;
498498
}
499499
/*
500500
*
@@ -515,7 +515,7 @@ bool HeatmapGui::variableRadius() const
515515
double HeatmapGui::radius() const
516516
{
517517
double radius = mBufferSizeLineEdit->text().toDouble();
518-
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::Meters )
518+
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
519519
{
520520
radius = mapUnitsOf( radius, inputVectorLayer()->crs() );
521521
}

src/plugins/heatmap/heatmapgui.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
3333
// Should have been private, made public to be used in heatmap.cpp
3434
enum mBufferType
3535
{
36-
Meters,
36+
LayerUnits,
3737
MapUnits
3838
};
3939

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

49-
/** Return the radius Unit (meters/map units) */
49+
/** Return the radius unit (layer/map units) */
5050
int radiusUnit() const;
5151

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

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

125125
/** Estimate a reasonable starting value for the radius field */
126126
double estimateRadius();

src/plugins/heatmap/heatmapguibase.ui

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<widget class="QComboBox" name="mBufferUnitCombo">
9090
<item>
9191
<property name="text">
92-
<string>meters</string>
92+
<string>layer units</string>
9393
</property>
9494
</item>
9595
<item>
@@ -269,7 +269,7 @@
269269
</property>
270270
<item>
271271
<property name="text">
272-
<string>meters</string>
272+
<string>layer units</string>
273273
</property>
274274
</item>
275275
<item>

0 commit comments

Comments
 (0)