Raster function (service)

Loading

Code

#include "RasterFunctionService.h"

#include "Map.h"
#include "MapQuickView.h"
#include "RasterLayer.h"
#include "Basemap.h"
#include "ImageServiceRaster.h"
#include "RasterFunction.h"

#include <QQmlProperty>

using namespace Esri::ArcGISRuntime;

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

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

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

  m_dataPath = QUrl(QQmlProperty::read(this, "dataPath").toString()).toLocalFile();

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

  // create a new tiled layer to add a basemap
  m_map = new Map(Basemap::streets(this), this);
  m_mapView->setMap(m_map);

  // create an image service raster
  m_imageServiceRaster = new ImageServiceRaster(QUrl("http://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer"), this);
  // zoom to the raster's extent once it's loaded
  connect(m_imageServiceRaster, &ImageServiceRaster::doneLoading, this, [this]()
  {
      m_mapView->setViewpoint(Viewpoint(m_imageServiceRaster->serviceInfo().fullExtent()));
  });

  // create a raster layer using the image service raster
  m_rasterLayer = new RasterLayer(m_imageServiceRaster, this);
  // add the raster layer to the map's operational layers
  m_map->operationalLayers()->append(m_rasterLayer);
}

void RasterFunctionService::applyRasterFunction()
{
  if (!QFile::exists(m_dataPath + "/hillshade_simplified.json"))
  {
      qDebug() << "JSON file for the raster function does not exist.";
      return;
  }

  RasterFunction* rasterFunction = new RasterFunction(m_dataPath + "/hillshade_simplified.json", this);
  RasterFunctionArguments* arguments = rasterFunction->arguments();
  arguments->setRaster("raster", m_imageServiceRaster);

  // create a new raster with the raster function and add to the operational layer
  Raster* raster = new Raster(rasterFunction, this);
  RasterLayer* rasterLayer = new RasterLayer(raster, this);

  m_map->operationalLayers()->clear();
  m_map->operationalLayers()->append(rasterLayer);
}


In this topic
  1. Code