示例#1
0
  def addDEMBlock(quad_rect, dem_width, dem_height, dem_values, image_width, image_height):
    planeWidth = quad_rect.width() * mapTo3d.planeWidth
    planeHeight = quad_rect.height() * mapTo3d.planeHeight
    extent = baseExtent.subrectangle(quad_rect)
    npt = baseExtent.normalizePoint(extent.center().x(), extent.center().y())
    offsetX = (npt.x() - 0.5) * mapTo3d.planeWidth
    offsetY = (npt.y() - 0.5) * mapTo3d.planeHeight

    block = DEMBlock(dem_width, dem_height, dem_values, planeWidth, planeHeight, offsetX, offsetY)
    #block.zShift(mapTo3d.verticalShift)
    #block.zScale(mapTo3d.multiplierZ)
    block.set("m", materialIndex(extent, image_width, image_height))

    blocks.appendBlock(block)
示例#2
0
  def addDEMBlock(quad_rect, dem_width, dem_height, dem_values, image_width, image_height):
    planeWidth = quad_rect.width() * mapTo3d.planeWidth
    planeHeight = quad_rect.height() * mapTo3d.planeHeight
    extent = baseExtent.subrectangle(quad_rect)
    npt = baseExtent.normalizePoint(extent.center().x(), extent.center().y())
    offsetX = (npt.x() - 0.5) * mapTo3d.planeWidth
    offsetY = (npt.y() - 0.5) * mapTo3d.planeHeight

    block = DEMBlock(dem_width, dem_height, dem_values, planeWidth, planeHeight, offsetX, offsetY)
    #block.zShift(mapTo3d.verticalShift)
    #block.zScale(mapTo3d.multiplierZ)
    block.set("m", materialIndex(extent, image_width, image_height))

    blocks.appendBlock(block)
示例#3
0
def surroundingDEMBlocks(writer, layer, provider, properties, progress=None):
    settings = writer.settings
    canvas_size = settings.mapSettings.outputSize()
    mapTo3d = settings.mapTo3d()
    baseExtent = settings.baseExtent
    progress = progress or dummyProgress

    # options
    size = properties["spinBox_Size"]
    roughening = properties["spinBox_Roughening"]
    texture_scale = properties.get("comboBox_TextureSize", 100) / 100
    transparency = properties.get("spinBox_demtransp", 0)
    transp_background = properties.get("checkBox_TransparentBackground", False)

    prop = DEMPropertyReader(properties)
    dem_size = prop.demSize(canvas_size)
    dem_width = (dem_size.width() - 1) / roughening + 1
    dem_height = (dem_size.height() - 1) / roughening + 1

    # texture size
    image_width = canvas_size.width() * texture_scale
    image_height = canvas_size.height() * texture_scale

    center = baseExtent.center()
    rotation = baseExtent.rotation()

    blocks = []
    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)

        # display type
        if properties.get("radioButton_MapCanvas", False):
            mat = layer.materialManager.getMapImageIndex(
                image_width, image_height, extent, transparency,
                transp_background)

        elif properties.get("radioButton_LayerImage", False):
            layerids = properties.get("layerImageIds", [])
            mat = layer.materialManager.getLayerImageIndex(
                layerids, image_width, image_height, extent, transparency,
                transp_background)

        else:  #.get("radioButton_SolidColor", False)
            mat = layer.materialManager.getMeshLambertIndex(
                properties.get("lineEdit_Color", ""), transparency, True)

        # DEM block
        dem_values = provider.read(dem_width, dem_height, extent)
        planeWidth, planeHeight = mapTo3d.planeWidth, mapTo3d.planeHeight
        offsetX, offsetY = planeWidth * sx, planeHeight * sy

        block = DEMBlock(dem_width, dem_height, dem_values, planeWidth,
                         planeHeight, offsetX, offsetY)
        block.zShift(mapTo3d.verticalShift)
        block.zScale(mapTo3d.multiplierZ)
        block.set("m", mat)

        blocks.append(block)

    return blocks
示例#4
0
def writeSimpleDEM(writer, properties, progress=None):
    settings = writer.settings
    mapTo3d = settings.mapTo3d()
    progress = progress or dummyProgress

    prop = DEMPropertyReader(properties)

    # DEM provider
    provider = settings.demProviderByLayerId(prop.layerId)
    if isinstance(provider, GDALDEMProvider):
        demLayer = QgsMapLayerRegistry.instance().mapLayer(prop.layerId)
        layerName = demLayer.name()
    else:
        demLayer = None
        layerName = provider.name()

    # layer
    layer = DEMLayer(writer, demLayer, prop)
    lyr = layer.layerObject()
    lyr.update({"name": layerName})
    writer.writeLayer(lyr)

    # material option
    texture_scale = properties.get("comboBox_TextureSize", 100) / 100
    transparency = properties.get("spinBox_demtransp", 0)
    transp_background = properties.get("checkBox_TransparentBackground", False)

    # display type
    canvas_size = settings.mapSettings.outputSize()
    if properties.get("radioButton_MapCanvas", False):
        if texture_scale == 1:
            mat = layer.materialManager.getCanvasImageIndex(
                transparency, transp_background)
        else:
            mat = layer.materialManager.getMapImageIndex(
                canvas_size.width() * texture_scale,
                canvas_size.height() * texture_scale, settings.baseExtent,
                transparency, transp_background)

    elif properties.get("radioButton_LayerImage", False):
        layerids = properties.get("layerImageIds", [])
        mat = layer.materialManager.getLayerImageIndex(
            layerids,
            canvas_size.width() * texture_scale,
            canvas_size.height() * texture_scale, settings.baseExtent,
            transparency, transp_background)

    elif properties.get("radioButton_ImageFile", False):
        filepath = properties.get("lineEdit_ImageFile", "")
        mat = layer.materialManager.getImageFileIndex(filepath, transparency,
                                                      transp_background, True)

    else:  #.get("radioButton_SolidColor", False)
        mat = layer.materialManager.getMeshLambertIndex(
            properties.get("lineEdit_Color", ""), transparency, True)

    #elif properties.get("radioButton_Wireframe", False):
    #  block["m"] = layer.materialManager.getWireframeIndex(properties["lineEdit_Color"], transparency)

    # get DEM values
    dem_size = prop.demSize(settings.mapSettings.outputSize())
    dem_width, dem_height = dem_size.width(), dem_size.height()
    dem_values = provider.read(dem_width, dem_height, settings.baseExtent)

    # DEM block
    block = DEMBlock(dem_width, dem_height, dem_values, mapTo3d.planeWidth,
                     mapTo3d.planeHeight, 0, 0)
    block.zShift(mapTo3d.verticalShift)
    block.zScale(mapTo3d.multiplierZ)
    block.set("m", mat)

    surroundings = properties.get("checkBox_Surroundings",
                                  False) if prop.layerId else False
    if surroundings:
        blocks = DEMBlocks()
        blocks.appendBlock(block)
        blocks.appendBlocks(
            surroundingDEMBlocks(writer, layer, provider, properties,
                                 progress))
        blocks.processEdges()
        blocks.write(writer)

        writer.write("lyr.stats = {0};\n".format(pyobj2js(blocks.stats())))

    else:
        # clipping
        clip_option = properties.get("checkBox_Clip", False)
        if clip_option:
            clip_layerId = properties.get("comboBox_ClipLayer")
            clip_layer = QgsMapLayerRegistry.instance().mapLayer(
                clip_layerId) if clip_layerId else None
            if clip_layer:
                block.setClipGeometry(
                    dissolvePolygonsOnCanvas(writer, clip_layer))

        # sides and bottom
        if properties.get("checkBox_Sides", False):
            block.set("sides", True)

        # frame
        if properties.get("checkBox_Frame", False) and not clip_option:
            block.set("frame", True)

        block.write(writer)

        writer.write("lyr.stats = {0};\n".format(pyobj2js(block.orig_stats)))

    # materials
    writer.writeMaterials(layer.materialManager)
示例#5
0
def surroundingDEMBlocks(writer, layer, provider, 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"]
  texture_scale = properties["comboBox_TextureSize"] / 100
  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 size
  canvas_size = mapSettings.outputSize()
  image_width = canvas_size.width() * texture_scale
  image_height = canvas_size.height() * texture_scale

  center = baseExtent.center()
  rotation = baseExtent.rotation()

  blocks = []
  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)

    # display type
    if properties.get("radioButton_MapCanvas", False):
      mat = layer.materialManager.getMapImageIndex(image_width, image_height, extent, transparency, transp_background)

    elif properties.get("radioButton_LayerImage", False):
      layerids = properties.get("layerImageIds", [])
      mat = layer.materialManager.getLayerImageIndex(layerids, image_width, image_height, extent, transparency, transp_background)

    else:     #.get("radioButton_SolidColor", False)
      mat = layer.materialManager.getMeshLambertIndex(properties["lineEdit_Color"], transparency, True)

    # DEM block
    dem_values = provider.read(dem_width, dem_height, extent)
    planeWidth, planeHeight = mapTo3d.planeWidth, mapTo3d.planeHeight
    offsetX, offsetY = planeWidth * sx, planeHeight * sy

    block = DEMBlock(dem_width, dem_height, dem_values, planeWidth, planeHeight, offsetX, offsetY)
    block.zShift(mapTo3d.verticalShift)
    block.zScale(mapTo3d.multiplierZ)
    block.set("m", mat)

    blocks.append(block)

  return blocks
示例#6
0
def writeSimpleDEM(writer, properties, progress=None):
  settings = writer.settings
  mapTo3d = settings.mapTo3d
  progress = progress or dummyProgress

  prop = DEMPropertyReader(properties)

  # DEM provider
  provider = settings.demProviderByLayerId(prop.layerId)
  if isinstance(provider, GDALDEMProvider):
    demLayer = QgsMapLayerRegistry.instance().mapLayer(prop.layerId)
    layerName = demLayer.name()
  else:
    demLayer = None
    layerName = provider.name()

  # layer
  layer = DEMLayer(writer, demLayer, prop)
  lyr = layer.layerObject()
  lyr.update({"name": layerName})
  lyrIdx = writer.writeLayer(lyr)

  # material option
  texture_scale = properties["comboBox_TextureSize"] / 100
  transparency = properties["spinBox_demtransp"]
  transp_background = properties.get("checkBox_TransparentBackground", False)

  # display type
  canvas_size = settings.mapSettings.outputSize()
  if properties.get("radioButton_MapCanvas", False):
    if texture_scale == 1:
      mat = layer.materialManager.getCanvasImageIndex(transparency, transp_background)
    else:
      mat = layer.materialManager.getMapImageIndex(canvas_size.width() * texture_scale, canvas_size.height() * texture_scale, settings.baseExtent, transparency, transp_background)

  elif properties.get("radioButton_LayerImage", False):
    layerids = properties.get("layerImageIds", [])
    mat = layer.materialManager.getLayerImageIndex(layerids, canvas_size.width() * texture_scale, canvas_size.height() * texture_scale, settings.baseExtent, transparency, transp_background)

  elif properties.get("radioButton_ImageFile", False):
    filepath = properties.get("lineEdit_ImageFile", "")
    mat = layer.materialManager.getImageFileIndex(filepath, transparency, transp_background, True)

  else:   #.get("radioButton_SolidColor", False)
    mat = layer.materialManager.getMeshLambertIndex(properties["lineEdit_Color"], transparency, True)

  #elif properties.get("radioButton_Wireframe", False):
  #  block["m"] = layer.materialManager.getWireframeIndex(properties["lineEdit_Color"], transparency)

  # get DEM values
  dem_width, dem_height = prop.width(), prop.height()
  dem_values = provider.read(dem_width, dem_height, settings.baseExtent)

  # DEM block
  block = DEMBlock(dem_width, dem_height, dem_values, mapTo3d.planeWidth, mapTo3d.planeHeight, 0, 0)
  block.zShift(mapTo3d.verticalShift)
  block.zScale(mapTo3d.multiplierZ)
  block.set("m", mat)

  surroundings = properties.get("checkBox_Surroundings", False) if prop.layerId else False
  if surroundings:
    blocks = DEMBlocks()
    blocks.appendBlock(block)
    blocks.appendBlocks(surroundingDEMBlocks(writer, layer, provider, properties, progress))
    blocks.processEdges()
    blocks.write(writer)

    writer.write("lyr.stats = {0};\n".format(pyobj2js(blocks.stats())))

  else:
    # clipping
    if properties.get("checkBox_Clip", False):
      clip_layerId = properties.get("comboBox_ClipLayer")
      clip_layer = QgsMapLayerRegistry.instance().mapLayer(clip_layerId) if clip_layerId else None
      if clip_layer:
        block.setClipGeometry(dissolvePolygonsOnCanvas(writer, clip_layer))

    # sides and bottom
    if properties.get("checkBox_Sides", False):
      block.set("sides", True)

    # frame
    if properties.get("checkBox_Frame", False) and not clip_option:
      block.set("frame", True)

    block.write(writer)

    writer.write("lyr.stats = {0};\n".format(pyobj2js(block.orig_stats)))

  # materials
  writer.writeMaterials(layer.materialManager)