forked from minorua/Qgis2threejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
93 lines (79 loc) · 3.14 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Qgis2threejs
A QGIS plugin
export terrain data, map canvas image and vector data to web browser
-------------------
begin : 2014-01-16
copyright : (C) 2014 Minoru Akagi
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from .conf import DEBUG_MODE
from .datamanager import ImageManager
from .builddem import DEMLayerBuilder
from .buildvector import VectorLayerBuilder
from .qgis2threejstools import logMessage
from . import q3dconst
class ThreeJSBuilder:
def __init__(self, settings, progress=None):
self.settings = settings
self.progress = progress or dummyProgress
self.imageManager = ImageManager(settings)
def buildScene(self, build_layers=True):
crs = self.settings.crs
extent = self.settings.baseExtent
rect = extent.unrotatedRect()
mapTo3d = self.settings.mapTo3d()
wgs84Center = self.settings.wgs84Center()
obj = {
"type": "scene",
"properties": {
"height": mapTo3d.planeHeight,
"width": mapTo3d.planeWidth,
"baseExtent": [rect.xMinimum(), rect.yMinimum(), rect.xMaximum(), rect.yMaximum()],
"crs": str(crs.authid()),
"proj": crs.toProj4(),
"rotation": extent.rotation(),
"wgs84Center": {
"lat": wgs84Center.y(),
"lon": wgs84Center.x()
},
"zExaggeration": mapTo3d.verticalExaggeration,
"zShift": mapTo3d.verticalShift
}
}
if build_layers:
obj["layers"] = self.buildLayers()
return obj
def buildLayers(self):
layers = []
for layer in self.settings.getLayerList():
if layer.visible:
layers.append(self.buildLayer(layer))
return layers
def buildLayer(self, layer):
if layer.geomType == q3dconst.TYPE_DEM:
builder = DEMLayerBuilder(self.settings, self.imageManager, layer)
else:
builder = VectorLayerBuilder(self.settings, self.imageManager, layer)
return builder.build()
def builders(self, layer):
if layer.geomType == q3dconst.TYPE_DEM:
builder = DEMLayerBuilder(self.settings, self.imageManager, layer)
else:
builder = VectorLayerBuilder(self.settings, self.imageManager, layer)
yield builder
for blockBuilder in builder.blocks():
yield blockBuilder
def dummyProgress(progress=None, statusMsg=None):
pass