ArcGIS Runtime SDK for Qt

Symbolize a shapefile

Loading

Code

#include "SymbolizeShapefile.h"

#include "Map.h"
#include "MapQuickView.h"
#include "ShapefileFeatureTable.h"
#include "FeatureLayer.h"
#include "SimpleRenderer.h"
#include "SimpleFillSymbol.h"
#include "SimpleLineSymbol.h"

#include <QQmlProperty>
#include <QUrl>

using namespace Esri::ArcGISRuntime;

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

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

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

  // find QML MapView component
  m_mapView = findChild<MapQuickView*>("mapView");

  // Create a map using the streets vector basemap
  m_map = new Map(Basemap::streetsVector(this), this);

  // Set an initial viewpoint
  const Point pt(-11662054, 4818336, SpatialReference(3857));
  const Viewpoint vp(pt, 200000);
  m_map->setInitialViewpoint(vp);

  // Create the ShapefileFeatureTable
  const QString dataPath = QQmlProperty::read(m_mapView, "dataPath").toUrl().toLocalFile();
  ShapefileFeatureTable* shp = new ShapefileFeatureTable(dataPath + "Subdivisions.shp", this);

  // Create the FeatureLayer
  m_featureLayer = new FeatureLayer(shp, this);
  m_map->operationalLayers()->append(m_featureLayer);

  // Set map to map view
  m_mapView->setMap(m_map);
}

void SymbolizeShapefile::updateRenderer()
{
  // Create the Symbol
  SimpleFillSymbol* sfs = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor("yellow"), this);
  SimpleLineSymbol* sls = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("red"), 1.0f, this);
  sfs->setOutline(sls);

  // Create the Renderer
  SimpleRenderer* simpleRenderer = new SimpleRenderer(sfs, this);

  // Set the Renderer on the Layer
  m_featureLayer->setRenderer(simpleRenderer);
}


In this topic
  1. Code