def writeSurroundingDEM(writer, layer, warp_dem, stats, properties, progress=None): settings = writer.settings mapSettings = settings.mapSettings mapTo3d = settings.mapTo3d baseExtent = settings.baseExtent progress = progress or dummyProgress # options size = properties["spinBox_Size"] roughening = properties["spinBox_Roughening"] transparency = properties["spinBox_demtransp"] transp_background = properties.get("checkBox_TransparentBackground", False) prop = DEMPropertyReader(properties) dem_width = (prop.width() - 1) / roughening + 1 dem_height = (prop.height() - 1) / roughening + 1 # texture image size canvas_size = mapSettings.outputSize() hpw = float(canvas_size.height()) / canvas_size.width() if hpw < 1: image_width = settings.image_basesize image_height = round(image_width * hpw) #image_height = settings.image_basesize * max(1, int(round(1 / hpw))) # not rendered expectedly else: image_height = settings.image_basesize image_width = round(image_height / hpw) center = baseExtent.center() rotation = baseExtent.rotation() size2 = size * size for i in range(size2): progress(20 * i / size2 + 10) if i == (size2 - 1) / 2: # center (map canvas) continue # block extent sx = i % size - (size - 1) / 2 sy = i / size - (size - 1) / 2 block_center = QgsPoint(center.x() + sx * baseExtent.width(), center.y() + sy * baseExtent.height()) extent = RotatedRect(block_center, baseExtent.width(), baseExtent.height()).rotate(rotation, center) # warp dem dem_values = warp_dem.read(dem_width, dem_height, extent.geotransform(dem_width, dem_height)) if stats is None: stats = {"max": max(dem_values), "min": min(dem_values)} else: stats["max"] = max(max(dem_values), stats["max"]) stats["min"] = min(min(dem_values), stats["min"]) # shift and scale if mapTo3d.verticalShift != 0: dem_values = map(lambda x: x + mapTo3d.verticalShift, dem_values) if mapTo3d.multiplierZ != 1: dem_values = map(lambda x: x * mapTo3d.multiplierZ, dem_values) # generate javascript data file # dem block block = {"width": dem_width, "height": dem_height} block["plane"] = {"width": mapTo3d.planeWidth, "height": mapTo3d.planeHeight, "offsetX": mapTo3d.planeWidth * sx, "offsetY": mapTo3d.planeHeight * sy} # display type if properties.get("radioButton_MapCanvas", False): block["m"] = layer.materialManager.getMapImageIndex(image_width, image_height, extent, transparency, transp_background) elif properties.get("radioButton_LayerImage", False): layerids = properties.get("layerImageIds", []) block["m"] = layer.materialManager.getLayerImageIndex(layerids, image_width, image_height, extent, transparency, transp_background) elif properties.get("radioButton_SolidColor", False): block["m"] = layer.materialManager.getMeshLambertIndex(properties["lineEdit_Color"], transparency, True) # write block writer.write("bl = lyr.addBlock({0});\n".format(pyobj2js(block))) writer.write("bl.data = [{0}];\n".format(",".join(map(gdal2threejs.formatValue, dem_values))))