QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsfeature3dhandler_p.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsfeature3dhandler_p.cpp
3 --------------------------------------
4 Date : January 2019
5 Copyright : (C) 2019 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16
18
19#include "qgsfeaturerequest.h"
20#include "qgsvectorlayer.h"
21
22#include "qgs3dmapsettings.h"
23#include "qgs3dutils.h"
24
26
27
28namespace Qgs3DSymbolImpl
29{
30
31 Qt3DCore::QEntity *entityFromHandler( QgsFeature3DHandler *handler, const Qgs3DMapSettings &map, QgsVectorLayer *layer )
32 {
33 Qgs3DRenderContext context( map );
34
36 exprContext.setFields( layer->fields() );
37 context.setExpressionContext( exprContext );
38
39 QSet<QString> attributeNames;
40 if ( !handler->prepare( context, attributeNames ) )
41 return nullptr;
42
43 // build the feature request
45 req.setDestinationCrs( map.crs(), map.transformContext() );
46 req.setSubsetOfAttributes( attributeNames, layer->fields() );
47
48 QgsFeature f;
49 QgsFeatureIterator fi = layer->getFeatures( req );
50 while ( fi.nextFeature( f ) )
51 {
52 context.expressionContext().setFeature( f );
53 handler->processFeature( f, context );
54 }
55
56 Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;
57 handler->finalize( entity, context );
58 return entity;
59 }
60
61}
62
63void QgsFeature3DHandler::updateZRangeFromPositions( const QVector<QVector3D> &positions )
64{
65 for ( const QVector3D &pos : positions )
66 {
67 if ( pos.y() < mZMin )
68 mZMin = pos.y();
69 if ( pos.y() > mZMax )
70 mZMax = pos.y();
71 }
72}
73
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
static QgsExpressionContext globalProjectLayerExpressionContext(QgsVectorLayer *layer)
Returns expression context for use in preparation of 3D data of a layer.
Definition: qgs3dutils.cpp:662
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.