Skip to content
Permalink
Browse files

heatmap plugin: fix labeling s/metre/layer units/ (fixes #11276)

(backports from commit c373d7b)
  • Loading branch information
jef-n committed Oct 17, 2015
1 parent e7a981c commit 644bfbb6d5acd67ef941119964ea6e3994bee407
@@ -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() );
}
@@ -363,17 +363,17 @@ void Heatmap::run()
*
*/

double Heatmap::mapUnitsOf( double meters, 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 )
@@ -102,8 +102,8 @@ class Heatmap: public QObject, public QgisPlugin
private:
double mDecay;

//! Worker to convert meters to map units
double mapUnitsOf( double meters, 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
@@ -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)
@@ -447,7 +447,7 @@ void HeatmapGui::updateBBox()
int idx = inputLayer->pendingFields().indexFromName( mRadiusFieldCombo->currentField() );
double maxInField = inputLayer->maximumValue( idx ).toDouble();

if ( mRadiusFieldUnitCombo->currentIndex() == HeatmapGui::Meters )
if ( mRadiusFieldUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
{
radiusInMapUnits = mapUnitsOf( maxInField, layerCrs );
}
@@ -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 );
}
@@ -481,9 +481,9 @@ void HeatmapGui::updateBBox()
updateSize();
}

double HeatmapGui::mapUnitsOf( double meters, 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() );
@@ -493,8 +493,8 @@ double HeatmapGui::mapUnitsOf( double meters, QgsCoordinateReferenceSystem layer
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;
}
/*
*
@@ -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() );
}
@@ -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
};

@@ -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 */
@@ -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, 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();
@@ -89,7 +89,7 @@
<widget class="QComboBox" name="mBufferUnitCombo">
<item>
<property name="text">
<string>meters</string>
<string>layer units</string>
</property>
</item>
<item>
@@ -269,7 +269,7 @@
</property>
<item>
<property name="text">
<string>meters</string>
<string>layer units</string>
</property>
</item>
<item>

0 comments on commit 644bfbb

Please sign in to comment.
You can’t perform that action at this time.