Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Symbolize a shapefile

Sample Viewer View Sample on GitHub

Display a shapefile with custom symbology.

Use case

Feature layers created from shapefiles do not possess any rendering information, and will be assigned with a default symbology. You can apply custom styling to ensure that the content is visible and usable in the context of a specific map. For example, you could use this to visually differentiate between features originating from two different shapefiles, by applying a blue color to one, and a red color to the other.

How to use the sample

Click the button to apply a new symbology renderer to the feature layer created from the shapefile.

How it works

  1. Create a ShapefileFeatureTable, providing the path to a shapefile.
  2. Create a FeatureLayer and associate it with the ShapeFileFeatureTable.
  3. Create a SimpleRenderer to override the default symbology. The simple renderer takes a symbol and applies that to all features in a layer.
  4. Apply the renderer to the FeatureLayer by setting the renderer.

Relevant API

  • FeatureLayer
  • ShapefileFeatureTable
  • SimpleFillSymbol
  • SimpleLineSymbol
  • SimpleRenderer

Offline Data

Read more about how to set up the sample's offline data here.

Link Local Location
Aurora Subdivions Shapefile <userhome>/ArcGIS/Runtime/Data/shp/Subdivisions.shp

About the data

This sample displays a shapefile containing subdivisions in Aurora, CO.

Additional information

While shapefiles contain no rendering information, other data sources such as Service Feature Tables or Geodatabase Feature Tables can contain such information. As a result, the rendering properties of the other data sources can be pre-defined by the author.

Tags

package, shape file, shapefile, symbology, visualization

Sample Code

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.9
import Esri.ArcGISExtras 1.1

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    readonly property string dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/shp/"

    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            BasemapStreetsVector {}

            // Declare a FeatureLayer for displaying the shapefile
            FeatureLayer {
                id: featureLayer
                // Create a ShapefileFeatureTable pointing to the data location
                ShapefileFeatureTable {
                    path: dataPath + "Subdivisions.shp"
                }
            }

            // set an initial viewpoint
            ViewpointCenter {
                Point {
                    y: 4818336
                    x: -11662054
                    spatialReference: SpatialReference { wkid: 3857 }
                }
                targetScale: 200000
            }
        }
    }

    // Update the renderer on click
    Button {
        anchors {
            left: parent.left
            top: parent.top
            margins: 10
        }
        text: "Change Renderer"
        onClicked: {
            // apply the new renderer
            featureLayer.renderer = simpleRenderer;
            visible = false;
        }
    }

    // Create a SimpleRenderer
    SimpleRenderer {
        id: simpleRenderer

        SimpleFillSymbol {
            color: "yellow"
            style: Enums.SimpleFillSymbolStyleSolid

            SimpleLineSymbol {
                color: "red"
                style: Enums.SimpleLineSymbolStyleSolid
                width: 1
            }
        }
    }
}