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
Pan and zoom the map to view the custom renderer applied to the feature layer created from the shapefile.
How it works
- Create a
ShapefileFeatureTable
, providing the path to a shapefile. - Create a
FeatureLayer
and associate it with theShapeFileFeatureTable
. - Create a
SimpleRenderer
to override the default symbology. The simple renderer takes a symbol and applies that to all features in a layer. - Apply the renderer to the
FeatureLayer
by setting the renderer.
Relevant API
- FeatureLayer
- ShapefileFeatureTable
- SimpleFillSymbol
- SimpleLineSymbol
- SimpleRenderer
Offline data
This sample uses the Aurora Subdivisions Shapefile. It is downloaded from ArcGIS Online automatically.
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
// Copyright 2025 Esri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import ArcGIS
import SwiftUI
struct ApplySymbologyToShapefileView: View {
/// The map that will contain our shapefile.
@State private var map = {
// Create a map with a topographic basemap.
let map = Map(basemapStyle: .arcGISTopographic)
// Set an initial viewpoint.
map.initialViewpoint = Viewpoint(
center: Point(x: -11662054, y: 4818336, spatialReference: .webMercator),
scale: 200_000
)
// Create a shapefile feature table.
let featureTable = ShapefileFeatureTable(
fileURL: Bundle.main.url(forResource: "Subdivisions", withExtension: "shp", subdirectory: "Aurora_CO_shp")!
)
// And now create a layer from that shapefile feature table.
let layer = FeatureLayer(featureTable: featureTable)
// Setup the symbology.
let lineSymbol = SimpleLineSymbol(style: .solid, color: .red, width: 1.0)
let fillSymbol = SimpleFillSymbol(style: .solid, color: .yellow, outline: lineSymbol)
// Create a renderer and specify our symbology for that renderer.
layer.renderer = SimpleRenderer(symbol: fillSymbol)
// Add the feature layer to the map.
map.addOperationalLayer(layer)
return map
}()
var body: some View {
MapView(map: map)
}
}
#Preview {
ApplySymbologyToShapefileView()
}