How to symbolize a feature layer


Summary
This topic describes how to symbolize a feature layer. The relationship between a layer's geometry type and its corresponding symbol type is discussed. Code examples are included to show how to symbolize a FeatureLayer, including working with the FeatureRenderer class.

In this topic


To use the code in this topic, add references to System.Drawing.dll, ESRI.ArcGISExplorer.dll, and ESRI.ArcGISExplorer.Application.dll. Add the following namespace references via using (C#) or Imports (VB .NET) statements:
  • ESRI.ArcGISExplorer.Mapping
  • ESRI.ArcGISExplorer.Data
  • ESRI.ArcGISExplorer.Application

About symbolizing a feature layer

The ArcGIS Explorer application programming interface (API) allows you to control how a feature layer is symbolized on the map, for example, symbolizing airport locations using a plane symbol, highways with a thick red line, or national parks with a solid green fill.
There are three Symbol types (that is, marker, line, and fill) that can be used to symbolize a FeatureLayer, each of which relates to the type of geometries stored in a layer. See the following table:
Feature layer geometry type
Symbol type
Point or multipoint
Marker
Polyline
Line
Polygon or multipatch
Fill

Creating a feature layer

The most straightforward method to symbolizing a feature layer is to create a FeatureLayer object and to specify a Symbol type in the class constructor. See the following code example:
[C#]
//Create a feature layer and symbolize points.
FeatureLayer pointLayer = new FeatureLayer(new DataSourceProperties(@
    "C:\Data\mountains.shp"), Symbol.Marker.Pushpin.Red);
//Create a feature layer and symbolize polylines.
FeatureLayer lineLayer = new FeatureLayer(new DataSourceProperties(@
    "C:\Data\roads.shp"), Symbol.Line.Solid.Green);
//Create a feature layer and symbolize polygons.
FeatureLayer polygonLayer = new FeatureLayer(new DataSourceProperties(@
    "C:\Data\regions.shp"), Symbol.Fill.Outline.Green);
[VB.NET]
'Create a feature layer and symbolize points.
Dim pointLayer As FeatureLayer = New FeatureLayer(New DataSourceProperties("C:\Data\mountains.shp"), Symbol.Marker.Pushpin.Red)
'Create a feature layer and symbolize polylines.
Dim lineLayer As FeatureLayer = New FeatureLayer(New DataSourceProperties("C:\Data\roads.shp"), Symbol.Line.Solid.Green)
'Create a feature layer and symbolize polygons.
Dim polygonLayer As FeatureLayer = New FeatureLayer(New DataSourceProperties("C:\Data\regions.shp"), Symbol.Fill.Outline.Green)
If you create a FeatureLayer using the previously described method but do not specify a Symbol type, a default symbol is assigned when the layer is added to the map.
When using the ArcGIS Explorer API, all features in a layer are drawn with the same symbol, for example, you cannot symbolize features differently based on column values. Package layers and layer files, which can be created in ArcGIS Desktop and added to ArcGIS Explorer, allow a wider selection of symbology.
A FeatureLayer stores its symbology in an associated FeatureRenderer object that can be accessed from the FeatureLayer.Renderer property. The FeatureRenderer class allows you to get or set the symbol for the layer using the GetSymbol and SetSymbol methods, respectively.
The following code example shows how to change the symbol for an existing layer by accessing its FeatureRenderer and uses the SetSymbol method to specify a new symbol:
[C#]
//Return the feature layer.
FeatureLayer campsitesLayer = Application.ActiveMapDisplay.Map.FindByName(
    "Campsites")as FeatureLayer;
//Return the renderer associated with the layer.
FeatureRenderer renderer = campsitesLayer.Renderer;
//Assign a new symbol to the layer.
renderer.SetSymbol(Symbol.Marker.Recreation.Camping);
[VB.NET]
'Return the feature layer.
Dim campsitesLayer As FeatureLayer = DirectCast(Application.ActiveMapDisplay.Map.FindByName("Campsites"), FeatureLayer)
'Return the renderer associated with the layer.
Dim renderer As FeatureRenderer = campsitesLayer.Renderer
'Assign a new symbol to the layer.
renderer.SetSymbol(Symbol.Marker.Recreation.Camping)
The following are additional symbology options when working with feature layers that store points:
  • Specify whether to billboard symbols in 3D, using the BillboardSymbols property. When set to true (true in VB .NET) the symbols appear to stand up perpendicular to the earth's surface; otherwise, the symbols appear flat and are parallel with the earth's surface.
  • Symbolize features using a custom symbol. Use the Symbol.CreateMarker method to create a marker symbol from a path to an image file or from an in-memory Microsoft .NET bitmap. For a list of supported formats, see Types of Bitmaps on the Microsoft Developer Network (MSDN) Web site.

    See the following code example:
[C#]
//Create a new feature layer.
FeatureLayer phonemastsLayer = FeatureLayer.OpenFileGeodatabaseTable(@
    "C:\Data\Forestry.gdb", "Phonemasts");
//Set billboarding to false in 3D.
phonemastsLayer.Renderer.BillboardSymbols = false;
//Create a custom symbol and associate it with the layer.
phonemastsLayer.Renderer.SetSymbol(Symbol.CreateMarker(@
                                   "C:\Data\Symbols\masts.png"));
[VB.NET]
'Create a new feature layer.
Dim phonemastsLayer As FeatureLayer = FeatureLayer.OpenFileGeodatabaseTable("C:\Data\Forestry.gdb", "Phonemasts")
'Set billboarding to false in 3D.
phonemastsLayer.Renderer.BillboardSymbols = False
'Create a custom symbol and associate it with the layer.
phonemastsLayer.Renderer.SetSymbol(Symbol.CreateMarker("C:\Data\Symbols\masts.png"))
Of the types of geometry stored in a FeatureLayer, only layers storing points can use custom symbols.
Although not directly related to symbolizing a feature layer, it is worth mentioning that you can set the transparency for a layer using the Layer.Transparency property.