Blend raster layer

Loading

Code

#include "BlendRasterLayer.h"

#include "Map.h"
#include "MapQuickView.h"
#include "Raster.h"
#include "RasterLayer.h"
#include "BlendRenderer.h"

#include <QQmlProperty>

using namespace Esri::ArcGISRuntime;

BlendRasterLayer::BlendRasterLayer(QQuickItem* parent /* = nullptr */):
  QQuickItem(parent)
{
}

BlendRasterLayer::~BlendRasterLayer()
{
}

void BlendRasterLayer::init()
{
  // Register the map view for QML
  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
  qmlRegisterType<BlendRasterLayer>("Esri.Samples", 1, 0, "BlendRasterLayerSample");
}

void BlendRasterLayer::componentComplete()
{
  QQuickItem::componentComplete();

  // find QML MapView component
  m_mapView = findChild<MapQuickView*>("mapView");
  m_mapView->setWrapAroundMode(WrapAroundMode::Disabled);

  // Create the raster and raster layer
  m_dataPath = QUrl(QQmlProperty::read(this, "dataPath").toString()).toLocalFile();

  Raster* raster = new Raster(m_dataPath + "/Shasta.tif", this);
  m_rasterLayer = new RasterLayer(raster, this);

  m_elevationRaster = new Raster(m_dataPath + "/Shasta_Elevation.tif", this);
  m_rasterLayerColorRamp = new RasterLayer(m_elevationRaster, this);

  // Add the raster to the map
  m_basemap = new Basemap(m_rasterLayer, this);
  m_basemapColorRamp = new Basemap(m_rasterLayerColorRamp, this);
  m_map = new Map(m_basemap, this);
  m_mapView->setMap(m_map);
}

void BlendRasterLayer::applyRenderSettings(double altitude, double azimuth, int slopeTypeVal, int colorRampTypeVal)
{
  PresetColorRampType colorRampType = static_cast<PresetColorRampType>(colorRampTypeVal);
  RasterLayer* rasterLyr = rasterLayer(colorRampType != PresetColorRampType::None);
  if (!rasterLyr)
    return;

  QList<double> outputMinValues{9};
  QList<double> outputMaxValues{255};
  QList<double> sourceMinValues;
  QList<double> sourceMaxValues;
  QList<double> noDataValues;
  QList<double> gammas;
  double zFactor = 1.;
  double pixelSizeFactor = 1.;
  double pixelSizePower = 1.;
  int outputBitDepth = 8;
  ColorRamp* colorRamp = ColorRamp::create(colorRampType, 800, this);
  SlopeType slopeType = static_cast<SlopeType>(slopeTypeVal);

  BlendRenderer* renderer = new BlendRenderer(m_elevationRaster,
                                              outputMinValues,
                                              outputMaxValues,
                                              sourceMinValues,
                                              sourceMaxValues,
                                              noDataValues,
                                              gammas,
                                              colorRamp,
                                              altitude,
                                              azimuth,
                                              zFactor,
                                              slopeType,
                                              pixelSizeFactor,
                                              pixelSizePower,
                                              outputBitDepth,
                                              this);

  rasterLyr->setRenderer(renderer);
}

RasterLayer* BlendRasterLayer::rasterLayer(bool useColorRamp)
{
  m_map->setBasemap(useColorRamp ? m_basemapColorRamp : m_basemap);
  return useColorRamp ? m_rasterLayerColorRamp : m_rasterLayer;
}


In this topic
  1. Code