Qgis 2 Threejs
Qgis 2 Threejs
Release 2.7
Minoru Akagi
1 Examples 3
2 Tutorial 5
3 Exporter 11
4 Object Types 27
8 Development 47
Index 49
i
ii
Qgis2threejs Plugin Document, Release 2.7
Qgis2threejs plugin is a QGIS plugin, which visualizes DEM data and vector data in 3D on a web view. You can build
various kinds of 3D objects and generate files for web publishing in simple procedure. In addition, you can save the
3D model in glTF format for 3DCG or 3D printing.
Table Of Contents:
Contents 1
Qgis2threejs Plugin Document, Release 2.7
2 Contents
CHAPTER 1
Examples
Sources: Geospatial Information Authority of Japan. GSI Tiles (dem, ort, relief)
• Mt. Fuji: Shaded relief map made with SRTM3 data
3
Qgis2threejs Plugin Document, Release 2.7
Source: U.S. NASA and NGA. SRTM elevation data (SRTM V2.1. Filled small voids using gdal_fillnodata.py)
• Forest Basins: Slope map
Sources: Geospatial Information Authority of Japan. 5m DEM of Fundamental Geospatial Data and GSI Tiles
(ort)
4 Chapter 1. Examples
CHAPTER 2
Tutorial
Open the Plugin Manager (Plugins > Manage and Install Plugins...) and install Qgis2threejs plugin.
Hint: Need help? See the 9.1. Installing and Managing Plugins section of the QGIS training manual.
If you already have raster DEM data, you can skip this step.
NASA published elevation data generated from NASA’s Shuttle Radar Topography Mission digital topographic data.
We can use the data freely. SRTM elevation data can be downloaded from the EarthExplorer (User registration re-
quired).
Horizontal unit of SRTM data is degree, whereas vertical unit is meter. For appropriate visualization, you need to
transform the DEM data to a projected CRS. QGIS can perform the CRS transformation on the fly.
So, let’s change the current project CRS to a projected CRS.
5
Qgis2threejs Plugin Document, Release 2.7
Click the CRS status icon in the bottom-right corner of the window to open the project properties dialog, and then
select a suitable CRS for the DEM extent. If you don’t know which CRS is best suited, select the Spherical Mercator
projection (EPSG:3857), which is adopted by many web maps.
Note: In the Spherical Mercator projection, every feature size is horizontally larger than actual size except those of
features on the equator. At latitude 40 degrees it is enlarged 1.3 times, at 60 degrees enlarged twice.
Open the Layer Properties dialog for the DEM layer and colorize the DEM layer richly.
An example (Singleband pseudocolor render type and inverted BrBG color map):
Zoom to a part of the DEM layer extent as the map canvas is filled by the colorized DEM layer, and then click the
6 Chapter 2. Tutorial
Qgis2threejs Plugin Document, Release 2.7
There is a preview on the right side. The scene doesn’t contain any 3D objects now.
Let’s add the DEM layer into the scene. Just click the checkbox on the left of the DEM layer under the DEM layer
group.
A 3D terrain object with map canvas image draped on it shows up in the preview.
Click on the File - Export to Web... menu entry to open this dialog.
Select a directory to export the scene, check Enable the Viewer to Run Locally option and press
Export button.
Note: Most web browsers do not allow loading data files on local file system via Ajax. With Enable the Viewer
to Run Locally option the plugin outputs geometry and image data into a js file.
8 Chapter 2. Tutorial
Qgis2threejs Plugin Document, Release 2.7
Open the .html file with a web browser. You can see exported scene in web browser.
You can publish the exported 3D viewer application and data just by uploading the output folder to a web hosting
service such as Netlify and GitHub Pages.
Note: Please do not forget to ensure that you comply with the Terms and use for the data before publishing the data
to the web.
2.10 In conclusion
Tutorial is over. Now you know 3D visualization with QGIS is very easy. If you can use high-quality data, you can
create beautiful 3D scenes!
Tip: Next, how about adding a background map layer to the map canvas. You can do it easily with QuickMapServices
plugin. Also, how about adding vector data to the scene. Object Types page has images of various object types. See
Exporter for the detail.
10 Chapter 2. Tutorial
CHAPTER 3
Exporter
Contents
• Window
• Scene Settings
• Camera Settings
• Controls Settings
• Widgets
• DEM Layer Settings
• Vector Layer Settings
• Point Cloud Layer Settings
• Animation
• Export to Web Dialog
• Exporter Settings
3.1 Window
Qgis2threejs exporter window has Layers panel and Animation panel on the left side, and preview on the right side.
11
Qgis2threejs Plugin Document, Release 2.7
In this plugin, the word “export settings” means all configuration settings for a 3D scene and its viewer application,
which consist of settings for scene, camera, every layer to export, animation, widgets on web page and so on. You can
configure them via Scene menu, Layers panel, Animation panel, View menu and Export to Web dialog.
In the Layers panel, each layer item has a checkbox on its left. Check the checkbox to add the layer to current
scene. To open layer properties dialog and configure settings for the layer, double-click on the layer item or click on
Properties. . . from context menu (right click menu).
Export settings are automatically saved to a .qto3settings file alongside the current QGIS project file if you are
working with a QGIS project file. When you open the exporter later, the export settings of the project will be restored.
If you don’t want to use preview, uncheck Preview checkbox in the lower right corner of the window. You might want
to uncheck it to avoid waiting for updating 3D objects in the scene for each export settings update.
3.1.1 Menu
• File
– Export to Web. . . Exports files for publishing current scene to web. See Export to Web Dialog section.
– Save Scene As
* Load. . .
* Save. . .
12 Chapter 3. Exporter
Qgis2threejs Plugin Document, Release 2.7
Scene settings dialog controls some basic configuration settings for current scene. Click on Scene - Scene
Settings... menu entry to open the dialog.
• World Coordinates
– Origin of xy-plane
Center of base extent Origin of map coordinate system
– Z exaggeration
Vertical exaggeration factor. This value affects terrain shape and z positions of all vector 3D
objects. This also affects 3D object height of some object types with volume. Shape types to be
affected:
Point : Cylinder, Cube, Cone
Polygon : Extruded
The following shape types have volume, but their heights aren’t affected by this factor:
Point : Sphere
Line : Pipe, Cone, Box
The default value is 1.0.
• Base Extent
– Use map canvas extent
– Fixed extent
– Fix aspect ratio to 1:1 Checked by default since version 2.7.
• Background
Select either sky-like gradient or a solid color for the scene background. Default is Sky.
• Display of coordinates
If the Latitude and longitude (WGS84) option is selected, coordinates of clicked position
on a 3D object are displayed in longitude and latitude (WGS84). If Proj4js doesn’t support current
map CRS, this option is disabled.
14 Chapter 3. Exporter
Qgis2threejs Plugin Document, Release 2.7
• Light Directional light from the lower left of the 2D map Point light above
the camera
• Fog Color and density.
• Material & Effect
– Basic material type
Material type applied to most 3D objects, except for Point, Billboard, Model File and Line type
objects. Select a material type from Lambert material, Phong material and Toon material. Default
is Lambert material.
– Enable outline effect
• Perspective Camera
Renders closer objects as bigger and farther objects as smaller.
• Orthographic Camera
Rendered object size doesn’t depend on the distance from the camera.
OrbitControls is available.
3.5 Widgets
• Navigation widget
• North arrow
Adds an arrow that indicates the direction of grid North at the lower-left corner of the web page.
• Header/Footer label
Adds a header label to top-left corner of the web page and/or a footer label to lower-left corner. Label
text can contain valid HTML tags for styling.
16 Chapter 3. Exporter
Qgis2threejs Plugin Document, Release 2.7
3.6.1 Geometry
• Resampling level
Select a DEM resolution from several levels. This resolution is used to resample the DEM, but is not
for texture.
• Clip DEM with polygon layer
Clips the DEM with a polygon layer. If you have a polygon layer that represents the area that elevation
data exist or represents drainage basins, you might want to use this option.
3.6.2 Material
The material list has one item map (canvas) by default. You can add a material to the list by clicking + button,
selecting one of Select layer(s), Image file, Solid color and Map canvas layers.
• Map canvas layers
Render a texture image with the current map settings for each DEM block.
• Layer image(s)
Render a texture image with the selected layer(s) for each DEM block.
• Image file
Textures the main DEM block with existing image file such as PNG file and JPEG file. TIFF is not
supported by some browser. See Image format support for details.
• Solid color
To select a color, press the button on the right side.
• Image width (px)
Select width of image draped on each DEM block. Default value is 1024.
• Opaciy
Sets opacity of DEM object. 100 is opaque, and 0 is transparent.
• Transparent background
When map canvas image or layer image is chosen
Makes image background transparent.
• Enable shading
Adds a shading effect to DEM surface. Checked by default.
3.6.3 Tiles
• Tiles
This option enlarges output DEM by placing DEM blocks around the main block of the map canvas
extent. Size can be selected from odd numbers in the range of 3 to 9. If you select 3, total 9 (=3x3)
blocks (a center block and 8 surrounding blocks) are output. Roughness can be selected from powers
of 2 in the range of 1 to 64. If you select 2, grid point spacing of each surrounding block is doubled.
It means that the number of grid points in the same area becomes 1/4.
• Build sides
This option adds sides and bottom to each DEM block. The z position of bottom in the 3D world is
fixed. You can adjust the height of sides by changing the value of vertical shift option in the World
panel. If you want to change color, edit the output JS file directly.
• Add edge lines
This option adds frame to the DEM. If you want to change color, edit the output JS file directly.
• Add quad wireframe
• Name
• Visible on Load
18 Chapter 3. Exporter
Qgis2threejs Plugin Document, Release 2.7
Vector layers are grouped into three types: Point, Line and Polygon. Common settings for all types:
• Type
Select a shape type.
• Z coordinate
– Altitude Mode
* Absolute
Altitude is distance above zero-level.
* Expression
A numeric value, field or more complex expression (QGIS expressions).
* Z value / M value
Uses z coordinate or m value of each vertex. the evaluated value is added to it.
These options can be chosen when the layer geometries have z coordinates or m values.
Cannot be chosen when the object type is Extruded or Overlay.
• Geometry and Material
Usually, there are options to set object color and transparency. Refer to the links below for each
object type specific settings. The unit of value for object size is that of the map CRS.
• Feature
Select the features to be exported.
– All features
All features of the layer are exported.
– Features that intersect with map canvas extent
Features on the map canvas are exported.
* Clip geometries
This option is available with Line/Polygon layer. If checked, geometries are
clipped by the extent of map canvas.
• Attributes
If the export attributes option is checked, attributes are exported with feature geometries. Attributes
are displayed when you click an object on web browser.
• Labels
This combo box is not available when layer type is line.
– Show labels a label is displayed above each object.
– Position
– Text
– Fill background
– Connector
20 Chapter 3. Exporter
Qgis2threejs Plugin Document, Release 2.7
• Others
– Name
– Visible on Load
Whether the layer is visible on page load or not.
– Clickable
3.7.1 Point
Point layers in the project are listed as the child items. The following shape types are available:
Sphere, Cylinder, Cone, Box, Disk, Plane, Model File
See Point Layer section in Object Types page for each object type specific settings.
3.7.2 Line
Line layers in the project are listed as the child items. The following shape types are available:
Line, Pipe, Cone, Box, Wall
See Line Layer section in Object Types page for each object type specific settings.
3.7.3 Polygon
Polygon layers in the project are listed as the child items. The following shape types are available:
Polygon, Extruded, Overlay
See Polygon Layer section in Object Types page for each object type specific settings.
• Information
• Material
– Color type
– Opacity
• Other options * Name * Show bounding boxes * Visible on load * Clickable
3.9 Animation
• Camera Motion
Group and keyframe item.
• Layer
– Texture change
– Growing line
– Change opacity
• Tween
22 Chapter 3. Exporter
Qgis2threejs Plugin Document, Release 2.7
3.9. Animation 23
Qgis2threejs Plugin Document, Release 2.7
24 Chapter 3. Exporter
Qgis2threejs Plugin Document, Release 2.7
* Magnetic North Direction Magnetic North direction clockwise from the upper di-
rection of the map, in degrees. This value will be set to 0 if map canvas is rotated
so that magnetic North direction is same as the map upper direction. Otherwise,
the value should be determined taking account of grid magnetic angle (angle be-
tween grid North and magnetic North) and map rotation. Used to determine device
camera direction.
• Animation and Narrative
– Start animation once the scene has been loaded
• Export button
Exporting starts when you press the Export button. When the exporting has been done and Open
exported page in web browser option is checked, the exported page is opened in default web browser
(or a web browser specified in Exporter Settings).
26 Chapter 3. Exporter
CHAPTER 4
Object Types
• Point Layer
• Line Layer
• Polygon Layer
Sphere | Cylinder | Cone | Box | Disk | Plane | Point | Billboard | Model File
4.1.1 Sphere
27
Qgis2threejs Plugin Document, Release 2.7
Specific settings :
• Radius Numerical value.
Origin :
center of sphere
three.js geometry class:
SphereBufferGeoemtry
4.1.2 Cylinder
Specific settings :
• Radius Numerical value.
• Height Numerical value.
Origin :
4.1.3 Cone
Specific settings :
• Radius Numerical value.
• Height Numerical value.
Origin :
center of bottom (if height > 0)
three.js geometry class:
CylinderBufferGeometry
4.1.4 Box
Specific settings :
• Width Numerical value.
• Depth Numerical value.
• Height Numerical value.
Origin :
center of bottom (if height > 0)
three.js geometry class:
BoxBufferGeometry
4.1.5 Disk
Specific settings :
• Radius Numerical value.
4.1.6 Plane
Specific settings :
• Width Numerical value.
• Length Numerical value.
• Dip Numerical value in degrees. See Strike and dip - Wikipedia.
• Dip direction Numerical value in degrees.
Origin :
center of plane
three.js geometry class:
PlaneBufferGeometry
4.1.7 Point
Specific settings :
• Radius Numerical value.
Origin :
center of sprite
three.js geometry class:
SphereBufferGeoemtry
4.1.8 Billboard
Image which always faces towards the camera. When an image file on local file system is specified, the image file is
copied to the export destination. When an image file on a web server is specified, the model file is not copied.
Specific settings :
• Image file File path or URL.
Load 3D model from supported format model file. COLLADA (*.dae) and glTF (*.gltf, *.glb) are sup-
ported. When a model file on local file system is specified, the model file is copied to the export destination. You need
to copy the relevant files such as texture image after export. When a model file URL is specified, the model file is not
copied.
Specific settings :
• Model file File path or URL.
• Scale Numerical value.
• Rotation (x) Numerical value in degrees.
• Rotation (y) Numerical value in degrees.
• Rotation (z) Numerical value in degrees.
• Rotation Order The options are XYZ, YZX, ZXY, XZY, YXZ and ZYX. See Euler - three.js docs.
Origin :
origin of model
4.2.1 Line
Specific settings :
no specific settings
three.js object class:
Line
Image was created with GSI Tiles (ort, dem).
4.2.2 Pipe
Specific settings :
• Radius Numerical value.
three.js geometry classes:
CylinderBufferGeometry and SphereBufferGeoemtry
4.2.3 Cone
Specific settings :
• Radius Numerical value.
three.js geometry class:
CylinderBufferGeometry
Image was created with GSI Tiles (ort, dem) and National Land Numerical Information (Rivers. MILT of Japan).
4.2.4 Box
Specific settings :
4.2.5 Wall
Specific settings :
• Other side Z Z coordinate of the other side edge.
Image was created with SRTM3 elevation data.
4.3.1 Polygon
Specific settings :
4.3.2 Extruded
Specific settings :
• Height Numerical value.
Image was created with GSI Tiles (ort, dem) and OpenStreetMap (© OpenStreetMap contributors, License).
4.3.3 Overlay
Overlay polygon draped on the main DEM with specified color, border color and opacity. When the altitude mode
is Relative to DEM layer, each polygon is located at the relative height from the DEM surface. Otherwise,
creates a flat polygon at specified altitude.
Specific settings :
• Border No border, feature style, random color or expression.
Image was created with GSI Tiles (ort, dem) and National Land Numerical Information (Sediment Disaster Hazard
Area. Provided by Okayama prefecture, Japan).
In Export to Web dialog, you can choose one from following available web viewer templates:
• 3D Viewer Template
• 3D Viewer(dat-gui) Template
• Mobile Template
There is a list of mouse/keyboard controls in about box. Press I key to show the box.
When you click on a 3D object, layer name that the object belongs to and the clicked coordinates (in order of x, y,
z) are displayed. If Latitude and longitude (WGS84) option in World Settings is selected, longitude and
latitude are in DMS format (degrees, minutes and seconds). If Export attributes option of each vector layer is
selected, attribute values of the clicked feature follows them.
Pressing R key starts/stops rotate animation. Camera rotates around the camera target clockwise.
Press Shift + S to show save image dialog, then enter image size and click the OK button. In addition, with some
web browsers, you need to click a link to save image. The image file format is PNG. To change label color and/or
adjust label size, edit Qgis2threejs.css (print-label class).
39
Qgis2threejs Plugin Document, Release 2.7
Note: A known issue: Wrong image output if the size is too large (issue #42)
You can get current view URL in the about box, and later restore the view by entering the URL in the URL box of web
browser.
Parameters used in view URL:
• cx, cy, cz: camera position
• tx, ty, tz: camera target
For example, file:///D:/example.html#cx=-64.8428840144039&cy=-40.75234765087484&cz=24.603200058346065
Other parameters:
• width: canvas width (pixels)
• height: canvas height (pixels)
• popup: pop up another window with specified width and height
This template is a simple 3D viewer. Ragardless of “Visible on load” layer setting, all exported layers are displayed
on page load.
This template has a dat-gui panel, which allows changing layer visibility and opacity, and adding a horizontal plane.
This is a template for mobile devices, which has mobile friendly GUI and experimental AR feature. In order to use
the AR feature (Camera and GPS), you need to upload exported files to a web server supporting SSL.
Do you want to export many scenes as web pages, image files or 3D model files? You can do them using Qgis2threejs
algorithms in Processing tool box. Qgis2threejs provides three algorithms - “Export as Web Page”, “Export as Image”
and “Export as 3D Model”.
6.1 Step 1
Add a DEM layer that covers the whole area you are going to export, a vector layer to point out area of interest for
each scene and any other layers to project. The vector layer is called as coverage layer and should have title field that
contains string used as title of file to export.
6.2 Step 2
6.3 Step 3
41
Qgis2threejs Plugin Document, Release 2.7
• Coverage Layer
A vector layer. Creates and exports scenes focused on each feature of this layer.
• Title Field
A field that contains string used as title of file to export.
• Current Feature Filter
Hides coverage layer features other than currently focused feature from texture image to be rendered.
• Output Directory
Path to output directory.
Advanced Parameters
• Scale Mode
– Fit to Geometry
Zoom to current feature geometry.
– Fixed scale (based on map canvas)
Use current map canvas scale.
• Buffer (%)
Default value is 10.
• Texture base width (px)
Default value is 1024.
• Texture base height (px)
In “Fit to Geometry” scale mode, leave this zero to respect aspect ratio of buffered geometry bounding
box. In “Fixed scale” scale mode, aspect ratio of map canvas size is respected when this is set to zero.
Default value is 0.
• Header Label
An expression which represents header label in HTML.
• Footer Label
An expression which represents footer label in HTML.
• Export Settings File (.qto3settings)
Optional. Path to export settings file. Leave this empty to use current export settings.
• Template
Select one of web page templates. See Export to Web Dialog in Exporter page and Web Viewer
Templates.
• Image width
Output image width in pixel. Default value is 2480.
• Image height
Output image height in pixel. Default value is 1748.
No specific settings.
7.1 Step 1
You need to prepare an export settings file. The export settings contains various settings, so you might want to create
the settings file using the Qgis2threejs exporter.
1. Open a QGIS project and click the Qgis2threejs icon in the web tool bar to open the Qgis2threejs exporter.
2. Add layers to scene, configure their settings, scene settings and decorations.
3. Click on the File - Export Settings - Save... menu entry, and then select a filename to save the
export settings (file extension is .qto3settings).
7.2 Step 2
You are ready to play with Python. Let’s open the QGIS Python console.
from PyQt5.QtCore import QSize
from Qgis2threejs.export import ThreeJSExporter, ImageExporter # or ModelExporter
from Qgis2threejs.mapextent import MapExtent
# extent to export
(continues on next page)
45
Qgis2threejs Plugin Document, Release 2.7
#
# 1. export scene as web page
#
filename = "D:/export/html_filename.html"
exporter = ThreeJSExporter()
exporter.loadSettings(path_to_settings) # export settings (for scene, layers,
˓→decorations and so on)
exporter.export(filename)
#
# 2. export scene as image
#
filename = "D:/export/image_filename.png"
exporter = ImageExporter()
exporter.loadSettings(path_to_settings)
exporter.setMapSettings(mapSettings)
Development
This plugin is now being developed personally by Minoru Akagi, and received many contributions.
Many thanks to all the contributors! Thanks also to bug reporters and everyone who gave me constructive suggestions!
Source Code: https://github.com/minorua/Qgis2threejs/
Issue Tracker: https://github.com/minorua/Qgis2threejs/issues
47
Qgis2threejs Plugin Document, Release 2.7
48 Chapter 8. Development
Index
B
Billboard, 32
Box (Line Layer), 35
Box (Point Layer), 29
C
Cone (Line Layer), 35
Cone (Point Layer), 29
Cylinder, 28
D
Disk, 30
E
Extruded, 37
L
Line, 33
M
Model-File, 33
O
Overlay, 37
P
Pipe, 34
Plane, 31
Point, 31
Polygon, 36
S
Sphere, 27
W
Wall, 36
49