Extrude features based on their attributes.

Use case
Extrusion is the process of stretching a flat, 2D shape vertically to create a 3D object in a scene. For example, you can extrude building polygons by a height value to create three-dimensional building shapes.
How to use the sample
Press the button to switch between using population density and total population for extrusion. Higher extrusion directly corresponds to higher attribute values.
How it works
- Create a
ServiceFeatureTablefrom a URL. - Create a feature layer from the service feature table.
- Make sure to set the rendering mode to dynamic,
setRenderingMode(FeatureRenderingMode::Dynamic).
- Apply a
SimpleRendererto the feature layer. - Set
ExtrusionModeof render,renderer::sceneProperties()::setExtrusionMode(ExtrusionMode::AbsoluteHeight). - Set extrusion expression of renderer,
renderer::getSceneProperties()::setExtrusionExpression("[POP2007] / 10").
Relevant API
- ExtrusionExpression
- ExtrusionMode
- FeatureLayer
- FeatureRenderingMode
- SceneProperties
- ServiceFeatureTable
- SimpleRenderer
Tags
3D, extrude, extrusion, extrusion expression, height, renderer, scene
Sample Code
// [WriteFile Name=FeatureLayerExtrusion, Category=Scenes]// [Legal]// Copyright 2017 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
#ifdef PCH_BUILD#include "pch.hpp"#endif // PCH_BUILD
// sample headers#include "FeatureLayerExtrusion.h"
// ArcGIS Maps SDK headers#include "ArcGISTiledElevationSource.h"#include "Camera.h"#include "ElevationSourceListModel.h"#include "FeatureLayer.h"#include "LayerListModel.h"#include "MapTypes.h"#include "Point.h"#include "RendererSceneProperties.h"#include "Scene.h"#include "SceneQuickView.h"#include "SceneViewTypes.h"#include "ServiceFeatureTable.h"#include "SimpleFillSymbol.h"#include "SimpleLineSymbol.h"#include "SimpleRenderer.h"#include "SpatialReference.h"#include "Surface.h"#include "SymbolTypes.h"#include "Viewpoint.h"
using namespace Esri::ArcGISRuntime;
FeatureLayerExtrusion::FeatureLayerExtrusion(QQuickItem* parent /* = nullptr */): QQuickItem(parent), // define line and fill symbols for a simple renderer m_lineSymbol(new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("Black"), 1.0f, this)), m_fillSymbol(new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("Blue"), m_lineSymbol, this)), m_renderer(new SimpleRenderer(m_fillSymbol, this)){ // set renderer extrusion mode to absolute to prevent clipping RendererSceneProperties props = m_renderer->sceneProperties(); props.setExtrusionMode(ExtrusionMode::AbsoluteHeight); props.setExtrusionExpression("[POP2007] / 10"); m_renderer->setSceneProperties(props);}
void FeatureLayerExtrusion::init(){ // Register classes for QML qmlRegisterType<SceneQuickView>("Esri.Samples", 1, 0, "SceneView"); qmlRegisterType<FeatureLayerExtrusion>("Esri.Samples", 1, 0, "FeatureLayerExtrusionSample");}
void FeatureLayerExtrusion::componentComplete(){ QQuickItem::componentComplete();
// Create the feature service to use m_featureTable = new ServiceFeatureTable(QUrl("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3"), this);
// add the service feature table to a feature layer m_featureLayer = new FeatureLayer(m_featureTable, this);
// set the feature layer to render dynamically to allow extrusion m_featureLayer->setRenderingMode(FeatureRenderingMode::Dynamic);
// set the simple renderer to the feature layer m_featureLayer->setRenderer(m_renderer);
// Create a scene and give it to the SceneView m_sceneView = findChild<SceneQuickView*>("sceneView"); Scene* scene = new Scene(BasemapStyle::ArcGISImageryStandard, this); Surface* surface = new Surface(this); surface->elevationSources()->append( new ArcGISTiledElevationSource( QUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"), this)); scene->setBaseSurface(surface); scene->operationalLayers()->append(m_featureLayer);
// set initial viewpoint const double distance = 12940924; const Point lookAtPoint(-99.659448, 20.513652, distance, SpatialReference::wgs84()); const Camera camera(lookAtPoint, 0, 15, 0); const Viewpoint initialVp(lookAtPoint, distance, camera); scene->setInitialViewpoint(initialVp);
// apply initial extrusion totalPopulation();
m_sceneView->setArcGISScene(scene);}
void FeatureLayerExtrusion::popDensity(){ // multiply population density by 5000 to make data legible RendererSceneProperties props = m_renderer->sceneProperties(); props.setExtrusionExpression("([POP07_SQMI] * 5000) + 100000"); m_renderer->setSceneProperties(props);}
void FeatureLayerExtrusion::totalPopulation(){ // divide total population by 10 to make data legible RendererSceneProperties props = m_renderer->sceneProperties(); props.setExtrusionExpression("[POP2007] / 10"); m_renderer->setSceneProperties(props);}// [WriteFile Name=FeatureLayerExtrusion, Category=Scenes]// [Legal]// Copyright 2017 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
#ifndef FEATURELAYEREXTRUSION_H#define FEATURELAYEREXTRUSION_H
// ArcGIS Maps SDK headers#include "Camera.h"#include "Point.h"
// Qt headers#include <QQuickItem>
namespace Esri::ArcGISRuntime{class FeatureLayer;class ServiceFeatureTable;class SceneQuickView;class OrbitLocationCameraController;class SimpleLineSymbol;class SimpleFillSymbol;class SimpleRenderer;enum class FeatureRenderingMode;}
class FeatureLayerExtrusion : public QQuickItem{ Q_OBJECT
public: explicit FeatureLayerExtrusion(QQuickItem* parent = nullptr); ~FeatureLayerExtrusion() override = default;
void componentComplete() override; static void init(); Q_INVOKABLE void popDensity(); Q_INVOKABLE void totalPopulation();
private: Esri::ArcGISRuntime::SceneQuickView* m_sceneView = nullptr; Esri::ArcGISRuntime::FeatureLayer* m_featureLayer = nullptr; Esri::ArcGISRuntime::ServiceFeatureTable* m_featureTable = nullptr; Esri::ArcGISRuntime::SimpleLineSymbol* m_lineSymbol = nullptr; Esri::ArcGISRuntime::SimpleFillSymbol* m_fillSymbol = nullptr; Esri::ArcGISRuntime::SimpleRenderer* m_renderer = nullptr; bool m_showTotalPopulation = true;
};
#endif // FEATURELAYEREXTRUSION_H// [WriteFile Name=FeatureLayerExtrusion, Category=Scenes]// [Legal]// Copyright 2017 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
import QtQuickimport QtQuick.Controlsimport Esri.Samples
FeatureLayerExtrusionSample { id: rootRectangle clip: true width: 800 height: 600
SceneView { id: sceneView objectName: "sceneView" anchors.fill: parent
Component.onCompleted: { // Set the focus on SceneView to initially enable keyboard navigation forceActiveFocus(); }
// combo box to update the extrusion ComboBox { id: popCombo anchors { top: parent.top left: parent.left margins: 10 }
property int modelWidth: 0 width: modelWidth + leftPadding + rightPadding + (indicator ? indicator.width : 10)
// Add a background to the ComboBox Rectangle { anchors.fill: parent radius: 10 // Make the rectangle visible if a dropdown indicator exists // An indicator only exists if a theme is set visible: parent.indicator border.width: 1 }
model: ["TOTAL POPULATION", "POPULATION DENSITY"]
onCurrentTextChanged: { if (currentText === "TOTAL POPULATION") totalPopulation(); else popDensity(); }
Component.onCompleted : { for (let i = 0; i < model.length; ++i) { metrics.text = model[i]; modelWidth = Math.max(modelWidth, metrics.width); } } TextMetrics { id: metrics font: popCombo.font } } }}// [Legal]// Copyright 2017 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
// sample headers#include "FeatureLayerExtrusion.h"
// ArcGIS Maps SDK headers#include "ArcGISRuntimeEnvironment.h"
// Qt headers#include <QCommandLineParser>#include <QDir>#include <QGuiApplication>#include <QQmlEngine>#include <QQuickView>#include <QSurfaceFormat>
// Platform specific headers#ifdef Q_OS_WIN#include <Windows.h>#endif
#define STRINGIZE(x) #x#define QUOTE(x) STRINGIZE(x)
int main(int argc, char *argv[]){ Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setUseLegacyAuthentication(false);#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) // Linux requires 3.2 OpenGL Context // in order to instance 3D symbols QSurfaceFormat fmt = QSurfaceFormat::defaultFormat(); fmt.setVersion(3, 2); QSurfaceFormat::setDefaultFormat(fmt);#endif
QGuiApplication app(argc, argv); app.setApplicationName(QString("FeatureLayerExtrusion"));
// Use of ArcGIS location services, such as basemap styles, geocoding, and routing services, // requires an access token. For more information see // https://links.esri.com/arcgis-runtime-security-auth.
// The following methods grant an access token:
// 1. User authentication: Grants a temporary access token associated with a user's ArcGIS account. // To generate a token, a user logs in to the app with an ArcGIS account that is part of an // organization in ArcGIS Online or ArcGIS Enterprise.
// 2. API key authentication: Get a long-lived access token that gives your application access to // ArcGIS location services. Go to the tutorial at https://links.esri.com/create-an-api-key. // Copy the API Key access token.
const QString accessToken = QString("");
if (accessToken.isEmpty()) { qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" << "you to authenticate with an ArcGIS account or set the API Key property."; } else { Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setApiKey(accessToken); }
// Initialize the sample FeatureLayerExtrusion::init();
// Initialize application view QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView);
QString arcGISRuntimeImportPath = QUOTE(ARCGIS_RUNTIME_IMPORT_PATH);
#if defined(LINUX_PLATFORM_REPLACEMENT) // on some linux platforms the string 'linux' is replaced with 1 // fix the replacement paths which were created QString replaceString = QUOTE(LINUX_PLATFORM_REPLACEMENT); arcGISRuntimeImportPath = arcGISRuntimeImportPath.replace(replaceString, "linux", Qt::CaseSensitive);#endif
// Add the import Path view.engine()->addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml")); // Add the Runtime and Extras path view.engine()->addImportPath(arcGISRuntimeImportPath);
// Set the source view.setSource(QUrl("qrc:/Samples/Scenes/FeatureLayerExtrusion/FeatureLayerExtrusion.qml"));
view.show();
return app.exec();}