34class QgsAlgorithmElevationProfilePlotItem : 
public Qgs2DPlot 
   37    explicit QgsAlgorithmElevationProfilePlotItem( 
int width, 
int height, 
int dpi )
 
   42      setSize( QSizeF( width, height ) );
 
   52      if ( !mPlotArea.isNull() )
 
   73      rc.
painter()->translate( mPlotArea.left(), mPlotArea.top() );
 
   74      const QStringList sourceIds = mRenderer->sourceIds();
 
   75      for ( 
const QString &source : sourceIds )
 
   77        mRenderer->render( rc, mPlotArea.width(), mPlotArea.height(), xMinimum(), 
xMaximum(), 
yMinimum(), 
yMaximum(), source );
 
   79      rc.
painter()->translate( -mPlotArea.left(), -mPlotArea.top() );
 
   88void QgsGenerateElevationProfileAlgorithm::initAlgorithm( 
const QVariantMap & )
 
   96  auto minimumDistanceParam = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( 
"MINIMUM_DISTANCE" ), QObject::tr( 
"Chart minimum distance (X axis)" ), 
Qgis::ProcessingNumberParameterType::Double, QVariant(), 
true );
 
   98  addParameter( minimumDistanceParam.release() );
 
   99  auto maximumDistanceParam = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( 
"MAXIMUM_DISTANCE" ), QObject::tr( 
"Chart maximum distance (X axis)" ), 
Qgis::ProcessingNumberParameterType::Double, QVariant(), 
true );
 
  101  addParameter( maximumDistanceParam.release() );
 
  102  auto minimumElevationParam = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( 
"MINIMUM_ELEVATION" ), QObject::tr( 
"Chart minimum elevation (Y axis)" ), 
Qgis::ProcessingNumberParameterType::Double, QVariant(), 
true );
 
  104  addParameter( minimumElevationParam.release() );
 
  105  auto maximumElevationParam = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( 
"MAXIMUM_ELEVATION" ), QObject::tr( 
"Chart maximum elevation (Y axis)" ), 
Qgis::ProcessingNumberParameterType::Double, QVariant(), 
true );
 
  107  addParameter( maximumElevationParam.release() );
 
  109  auto textColorParam = std::make_unique<QgsProcessingParameterColor>( QStringLiteral( 
"TEXT_COLOR" ), QObject::tr( 
"Chart text color" ), QColor( 0, 0, 0 ), 
true, 
true );
 
  111  addParameter( textColorParam.release() );
 
  112  auto backgroundColorParam = std::make_unique<QgsProcessingParameterColor>( QStringLiteral( 
"BACKGROUND_COLOR" ), QObject::tr( 
"Chart background color" ), QColor( 255, 255, 255 ), 
true, 
true );
 
  114  addParameter( backgroundColorParam.release() );
 
  115  auto borderColorParam = std::make_unique<QgsProcessingParameterColor>( QStringLiteral( 
"BORDER_COLOR" ), QObject::tr( 
"Chart border color" ), QColor( 99, 99, 99 ), 
true, 
true );
 
  117  addParameter( borderColorParam.release() );
 
  121  addParameter( toleranceParam.release() );
 
  125  addParameter( dpiParam.release() );
 
  130QString QgsGenerateElevationProfileAlgorithm::name()
 const 
  132  return QStringLiteral( 
"generateelevationprofileimage" );
 
  135QString QgsGenerateElevationProfileAlgorithm::displayName()
 const 
  137  return QObject::tr( 
"Generate elevation profile image" );
 
  140QStringList QgsGenerateElevationProfileAlgorithm::tags()
 const 
  142  return QObject::tr( 
"altitude,elevation,terrain,dem" ).split( 
',' );
 
  145QString QgsGenerateElevationProfileAlgorithm::group()
 const 
  147  return QObject::tr( 
"Plots" );
 
  150QString QgsGenerateElevationProfileAlgorithm::groupId()
 const 
  152  return QStringLiteral( 
"plots" );
 
  155QString QgsGenerateElevationProfileAlgorithm::shortHelpString()
 const 
  157  return QObject::tr( 
"This algorithm creates an elevation profile image from a list of map layer and an optional terrain." );
 
  160QString QgsGenerateElevationProfileAlgorithm::shortDescription()
 const 
  162  return QObject::tr( 
"Creates an elevation profile image from a list of map layer and an optional terrain." );
 
  165QgsGenerateElevationProfileAlgorithm *QgsGenerateElevationProfileAlgorithm::createInstance()
 const 
  167  return new QgsGenerateElevationProfileAlgorithm();
 
  172  const QgsGeometry curveGeom = parameterAsGeometry( parameters, QStringLiteral( 
"CURVE" ), context );
 
  175  QList<QgsMapLayer *> layers = parameterAsLayerList( parameters, QStringLiteral( 
"MAP_LAYERS" ), context );
 
  176  QgsMapLayer *terrainLayer = parameterAsLayer( parameters, QStringLiteral( 
"TERRAIN_LAYER" ), context );
 
  178  const double tolerance = parameterAsDouble( parameters, QStringLiteral( 
"TOLERANCE" ), context );
 
  180  QList<QgsAbstractProfileSource *> sources;
 
  184      sources.append( source );
 
  188  request.setCrs( curveCrs );
 
  189  request.setTolerance( tolerance );
 
  197      auto terrainProvider = std::make_unique<QgsRasterDemTerrainProvider>();
 
  198      terrainProvider->setLayer( rasterLayer );
 
  199      request.setTerrainProvider( terrainProvider.release() );
 
  203      auto terrainProvider = std::make_unique<QgsMeshTerrainProvider>();
 
  204      terrainProvider->setLayer( meshLayer );
 
  205      request.setTerrainProvider( terrainProvider.release() );
 
  210  mRenderer = std::make_unique<QgsProfilePlotRenderer>( sources, request );
 
  217  const QgsGeometry curveGeom = parameterAsGeometry( parameters, QStringLiteral( 
"CURVE" ), context );
 
  219  const bool hasMinimumDistance = parameters.value( QStringLiteral( 
"MINIMUM_DISTANCE" ) ).isValid();
 
  220  const double minimumDistance = parameterAsDouble( parameters, QStringLiteral( 
"MINIMUM_DISTANCE" ), context );
 
  221  const bool hasMaximumDistance = parameters.value( QStringLiteral( 
"MAXIMUM_DISTANCE" ) ).isValid();
 
  222  const double maximumDistance = parameterAsDouble( parameters, QStringLiteral( 
"MAXIMUM_DISTANCE" ), context );
 
  223  const bool hasMinimumElevation = parameters.value( QStringLiteral( 
"MINIMUM_ELEVATION" ) ).isValid();
 
  224  const double minimumElevation = parameterAsDouble( parameters, QStringLiteral( 
"MINIMUM_ELEVATION" ), context );
 
  225  const bool hasMaximumElevation = parameters.value( QStringLiteral( 
"MAXIMUM_ELEVATION" ) ).isValid();
 
  226  const double maximumElevation = parameterAsDouble( parameters, QStringLiteral( 
"MAXIMUM_ELEVATION" ), context );
 
  228  const int width = parameterAsInt( parameters, QStringLiteral( 
"WIDTH" ), context );
 
  229  const int height = parameterAsInt( parameters, QStringLiteral( 
"HEIGHT" ), context );
 
  230  const int dpi = parameterAsInt( parameters, QStringLiteral( 
"DPI" ), context );
 
  232  const QString outputImage = parameterAsString( parameters, QStringLiteral( 
"OUTPUT" ), context );
 
  234  const QColor textColor = parameterAsColor( parameters, QStringLiteral( 
"TEXT_COLOR" ), context );
 
  235  const QColor backgroundColor = parameterAsColor( parameters, QStringLiteral( 
"BACKGROUND_COLOR" ), context );
 
  236  const QColor borderColor = parameterAsColor( parameters, QStringLiteral( 
"BORDER_COLOR" ), context );
 
  238  QgsAlgorithmElevationProfilePlotItem plotItem( width, height, dpi );
 
  240  if ( textColor.isValid() )
 
  244    plotItem.xAxis().setTextFormat( textFormat );
 
  245    textFormat = plotItem.yAxis().textFormat();
 
  247    plotItem.yAxis().setTextFormat( textFormat );
 
  250  if ( borderColor.isValid() )
 
  252    auto lineSymbolLayer = std::make_unique<QgsSimpleLineSymbolLayer>( borderColor, 0.1 );
 
  253    lineSymbolLayer->setPenCapStyle( Qt::FlatCap );
 
  261  if ( backgroundColor.isValid() )
 
  263    auto fillSymbolLayer = std::make_unique<QgsSimpleFillSymbolLayer>( backgroundColor, Qt::SolidPattern, backgroundColor );
 
  268  generationContext.
setDpi( dpi );
 
  272  mRenderer->setContext( generationContext );
 
  274  mRenderer->startGeneration();
 
  275  mRenderer->waitForFinished();
 
  289    zMinimum = zRange.
lower() - 5;
 
  290    zMaximum = zRange.
lower() + 5;
 
  295    const double margin = ( zRange.
upper() - zRange.
lower() ) * 0.05;
 
  296    zMinimum = zRange.
lower() - margin;
 
  297    zMaximum = zRange.
upper() + margin;
 
  300  plotItem.setYMinimum( hasMinimumElevation ? minimumElevation : zMinimum );
 
  301  plotItem.setYMaximum( hasMaximumElevation ? maximumElevation : zMaximum );
 
  302  plotItem.setXMinimum( hasMinimumDistance ? minimumDistance : 0 );
 
  303  plotItem.setXMaximum( hasMaximumDistance ? maximumDistance : curveGeom.constGet()->length() );
 
  305  plotItem.setRenderer( mRenderer.get() );
 
  307  QImage image( 
static_cast<int>( plotItem.size().width() ), 
static_cast<int>( plotItem.size().height() ), QImage::Format_ARGB32_Premultiplied );
 
  308  image.fill( Qt::transparent );
 
  310  QPainter painter( &image );
 
  311  painter.setRenderHint( QPainter::Antialiasing, 
true );
 
  315  plotItem.calculateOptimisedIntervals( renderContext );
 
  316  plotItem.render( renderContext );
 
  318  image.save( outputImage );
 
  321  outputs.insert( QStringLiteral( 
"OUTPUT" ), outputImage );
 
@ MapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
 
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
 
@ Double
Double/float values.
 
Base class for 2-dimensional plot/chart/graphs.
 
void calculateOptimisedIntervals(QgsRenderContext &context)
Automatically sets the grid and label intervals to optimal values for display in the given render con...
 
double yMaximum() const
Returns the maximum value of the y axis.
 
void setSize(QSizeF size)
Sets the overall size of the plot (including titles and over components which sit outside the plot ar...
 
double xMaximum() const
Returns the maximum value of the x axis.
 
void setYMaximum(double maximum)
Sets the maximum value of the y axis.
 
double yMinimum() const
Returns the minimum value of the y axis.
 
QRectF interiorPlotArea(QgsRenderContext &context) const
Returns the area of the plot which corresponds to the actual plot content (excluding all titles and o...
 
void setYMinimum(double minimum)
Sets the minimum value of the y axis.
 
virtual void renderContent(QgsRenderContext &context, const QRectF &plotArea)
Renders the plot content.
 
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
 
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
 
Interface for classes which can generate elevation profiles.
 
Represents a coordinate reference system (CRS).
 
Abstract base class for curved geometry type.
 
QgsRange which stores a range of double values.
 
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
 
A geometry is the spatial representation of a feature.
 
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
 
A line symbol type, for rendering LineString and MultiLineString geometries.
 
Base class for all map layer types.
 
Represents a mesh layer supporting display of data on structured or unstructured meshes.
 
Contains information about the context in which a processing algorithm is executed.
 
QgsExpressionContext & expressionContext()
Returns the expression context.
 
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
 
Base class for providing feedback from a processing algorithm.
 
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
 
A geometry parameter for processing algorithms.
 
A map layer parameter for processing algorithms.
 
A parameter for processing algorithms which accepts multiple map layers.
 
A numeric parameter for processing algorithms.
 
Encapsulates the context in which an elevation profile is to be generated.
 
void setDpi(double dpi)
Sets the dpi (dots per inch) for the profie, to be used in size conversions.
 
void setMaximumErrorMapUnits(double error)
Sets the maximum allowed error in the generated result, in profile curve map units.
 
void setMapUnitsPerDistancePixel(double units)
Sets the number of map units per pixel in the distance dimension.
 
Generates and renders elevation profile plots.
 
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
 
T lower() const
Returns the lower bound of the range.
 
T upper() const
Returns the upper bound of the range.
 
Represents a raster layer.
 
Contains information about the context of a rendering operation.
 
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
 
QPainter * painter()
Returns the destination QPainter for the render operation.
 
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
 
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
 
Container for all settings relating to text rendering.
 
void setColor(const QColor &color)
Sets the color that text will be rendered in.
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
 
QList< QgsSymbolLayer * > QgsSymbolLayerList