Click or drag to resize
ShapefileTable Class
Represents a Shapefile table
Inheritance Hierarchy

Namespace: Esri.ArcGISRuntime.Data
Assembly: Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 10.2.7.0 (10.2.7.1234)
Syntax
public sealed class ShapefileTable : FeatureTable

The ShapefileTable type exposes the following members.

Methods
  NameDescription
Public methodAddAsync(Feature)
Adds the specified feature to the table.
(Inherited from FeatureTable.)
Public methodAddAsync(IEnumerableFeature)
Adds the specified features to the table in a single transaction. The transactional edit is only applied if adding all features succeed. Otherwise, the transactional edit will rollback.
(Inherited from FeatureTable.)
Public methodAddAsync(IEnumerableKeyValuePairString, Object, Geometry)
Adds a new row to the table.
(Inherited from FeatureTable.)
Public methodDeleteAsync(IEnumerableInt64)
Deletes a rows from the table with the specified feature ids.
(Inherited from FeatureTable.)
Public methodDeleteAsync(Int64)
Deletes a row from the table with the specified feature id.
(Inherited from FeatureTable.)
Public methodDeleteAsync(Feature)
Deletes a feature from the table.
(Inherited from FeatureTable.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStatic memberOpenAsync
Creates and initializes a ShapefileTable from a file.
Public methodQueryAsync(Int64)
Get a features from the table based on its row id.
(Inherited from FeatureTable.)
Public methodQueryAsync(IEnumerableInt64)
Gets features from the table based on their row ids.
(Overrides FeatureTableQueryAsync(IEnumerableInt64).)
Public methodQueryAsync(QueryFilter)
Queries the specified query filter.
(Overrides FeatureTableQueryAsync(QueryFilter).)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodUpdateAsync(Feature)
Updates the specified feature in the table.
(Inherited from FeatureTable.)
Public methodUpdateAsync(IEnumerableFeature)
Updates the specified features of the table in a single transaction. The transactional edit is only applied if update to all features succeed. Otherwise, the transactional edit will rollback.
(Inherited from FeatureTable.)
Top
Properties
  NameDescription
Public propertyExtent
Gets the spatial extent of the feature table.
(Inherited from FeatureTable.)
Public propertyGeometryType
Gets the geometry type of the geometry (if any) in this table
(Inherited from FeatureTable.)
Public propertyIsReadOnly
Gets a value indicating whether the table supports editing.
(Inherited from FeatureTable.)
Public propertyName
Gets the name of the table.
(Inherited from FeatureTable.)
Public propertyObjectIDField
Gets the object ID field.
(Inherited from FeatureTable.)
Public propertyRowCount
Gets the number of rows in the table
(Inherited from FeatureTable.)
Public propertySchema
Gets the schema for the table if any.
(Inherited from FeatureTable.)
Public propertySpatialReference
Gets the spatial reference of the feature table.
(Inherited from FeatureTable.)
Public propertySupportsQuery
Gets a value indicating whether the table supports querying.
(Inherited from FeatureTable.)
Top
Remarks

The minimum required files needed to open a shapefile is the main ".shp" file (specified in OpenAsync(String), the ".dbf" file and the ".shx" files.

Shapefiles do not support editing, and calls to add/update/delete operations will throw a NotSupportedException. When performing edits on tables, check the IsReadOnly property, which will return false for this table type.

It is recommended to always set the SpatialReference for the Map when using a FeatureLayer based on a local disk based FeatureTable such as a ShapefileTable. The reason is that the visual elements of the FeatureLayer may not display if the Shapefile is not based on the SpatialReference WKID of 3787 (aka. Web Mercator). By specifying the Map's SpatialReference to be exactly the same at the ShapefileTable, you will be assured that it displays visually in the Map.

Examples

Demonstrates creating a FeatureLayer from a ShapefileTable that is stored locally on disk.

Adding a FeatureLayer to a Map based on a Shapefile in disk.

XAML
<Window x:Class="FeatureLayerViaShapefile.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="600" Width="800" 
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">

    <Grid>

        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Vertical">

                <!-- TextBlock to provide the instructions on how to use the sample code. It will be 
                populated with instructions in the code-behind when the application loads. -->
                <TextBlock Height="58" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" 
                           Width="770" TextWrapping="Wrap"  Margin="10,2,0,0" />

            </StackPanel>
            <StackPanel Orientation="Vertical">

                <!-- Button to add an FeatureLayer via code-behind. -->
                <Button Content="Add FeatureLayer to Map" 
                        x:Name="Button1" Click="Button1_Click" Width="780" HorizontalAlignment="Left"/>

            </StackPanel>
            <StackPanel Orientation="Horizontal">

                <!-- A MapView Control to display various GIS layers. -->
                <esri:MapView x:Name="MapView1" Width="780" Height="480" VerticalAlignment="Top" Margin="2,2,2,2">
                    <!-- Add a Map. -->
                    <esri:Map x:Name="Map1"/>
                </esri:MapView>

            </StackPanel>
        </StackPanel>
    </Grid>

</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "FeatureLayerViaShapefile.MainWindow" to be just "MainWindow".

// NOTE: The Shapefile that was used in this sample was obtained from the US Census at the following Url:
// http://www.census.gov/geo/maps-data/data/tiger-data.html <-- expand the '2010 Census' | 'Demographic Profile1 - Shapefile Format' section and click on the 'States' link   
// The downloaded file (State_2010Census_DP1.zip) was then unzipped to reveal the 'C:\TestData\State_2010Census_DP1' directory structure that contains 
// the Shapefile (.shp, .dbf, .shx, and .prj) and a metadata file (DP_TableDescriptions.xls) that describes the attributes fields in the Shapefile.

namespace FeatureLayerViaShapefile
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // Add the instructions on how to use this example code to the TextBlock.
            TextBlock1.Text = "After downloading the 2010 Census Demographic Profile 1 Shapefile for States from the web site: http://www.census.gov/geo/maps-data/data/tiger-data.html " + 
                "and unzipping the contents on disk, click the button to load the FeatureLayer based upon a ShapefileTable. A ClassBreaksRenderer will be used to colorize the " + 
                "states according to the population field: DP0080001.";

            // Set the initial extent to that of the continental US.
            Esri.ArcGISRuntime.Geometry.Envelope myEnvelope = new Esri.ArcGISRuntime.Geometry.Envelope(-125.72, 18.73, -66.3, 55.29);
            MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myEnvelope);

            // CAUTION: Local disk based FeatureLayers DO NOT re-project to match the Map's SpatialReference!
            // It is recommended to always set the SpatialReference for the Map when using a FeatureLayer based on a local disk based FeatureTable such as
            // a ShapefileTable or a GeodatabaseFeatureTable. The reason is that the visual elements of the FeatureLayer may not display if the Shapefile or
            // GeodatabaseFeatureTable are not based on the SpatialReference WKID of 3787 (aka. Web Mercator). By specifying the Map's SpatialReference to 
            // be exactly the same at the ShapefileTable or GeodatabaseFeatureTable, you will be assured that it displays visually in the Map. 
            // NOTE: If the FeatureLayer is based on an ArcGIS Server web ServiceFeatureTable, then re-projection of the data automatically occurs 
            // to match the SpatialReference of the Map.
            MapView1.Map.SpatialReference = Esri.ArcGISRuntime.Geometry.SpatialReference.Create(4269);
        }

        private async void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // Create a ShapefileTable from the .shp file. 
            Esri.ArcGISRuntime.Data.ShapefileTable myShapefileTable = await Esri.ArcGISRuntime.Data.ShapefileTable.OpenAsync("C:\\TestData\\State_2010Census_DP1\\State_2010Census_DP1.shp");

            // While specifying a QueryFilter is not necessary to restrict the number of records from the ShapefileTable, it is a good coding practice 
            // if there are thousands of records returned. The more records displayed the less performant the application will be.
            Esri.ArcGISRuntime.Data.QueryFilter myQueryFilter = new Esri.ArcGISRuntime.Data.QueryFilter();
            myQueryFilter.WhereClause = "1=1"; // Get all of the records. There are only 50 states.
            var _x = await myShapefileTable.QueryAsync(myQueryFilter);

            // Create a new FeatureLayer based upon the ShapefileTable. Set its .ID and .DisplayName properties.
            Esri.ArcGISRuntime.Layers.FeatureLayer myFeatureLayer = new Esri.ArcGISRuntime.Layers.FeatureLayer(myShapefileTable);
            myFeatureLayer.ID = "States";
            myFeatureLayer.DisplayName = "States";

            // To make the display of the states polygons more interesting visually, call the custom MakeClassBreaksRenderer_Fill function which will 
            // render the states categorically based upon population values in the field 'DP0080001'. Read the metadata file 'DP_TableDescriptions.xls'
            // that comes with the downloaded Census Shapefile to play with other attribute fields.
            myFeatureLayer.Renderer = MakeClassBreaksRenderer_Fill("DP0080001");

            // Add the FeatureLayer to the Map.
            MapView1.Map.Layers.Add(myFeatureLayer);
        }

        public Esri.ArcGISRuntime.Symbology.ClassBreaksRenderer MakeClassBreaksRenderer_Fill(string theFieldName)
        {
            // Create a ClassBreaksRenderer using what is specified for theFieldName as the Field to  perform the Rendering. In our case the 
            // various ClassBreakInfo objects have hard-coded  .MinimumValue and .MaximumValue settings that are appropriate for the .Field. 
            // If you use a attribute field you will need to adjust these values accordingly.
            Esri.ArcGISRuntime.Symbology.ClassBreaksRenderer myClassBreaksRenderer = new Esri.ArcGISRuntime.Symbology.ClassBreaksRenderer();
            myClassBreaksRenderer.Field = theFieldName; // Requires a numeric Field

            // Define the outline Symbol for the Fills
            Esri.ArcGISRuntime.Symbology.SimpleLineSymbol myBlackSolidOutline = new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol();
            myBlackSolidOutline.Color = System.Windows.Media.Colors.Black;
            myBlackSolidOutline.Style = Esri.ArcGISRuntime.Symbology.SimpleLineStyle.Solid;
            myBlackSolidOutline.Width = 1;

            // Group #1
            Esri.ArcGISRuntime.Symbology.ClassBreakInfo myClassBreakInfo1 = new Esri.ArcGISRuntime.Symbology.ClassBreakInfo();
            myClassBreakInfo1.Minimum = 0;
            myClassBreakInfo1.Maximum = 1000000;
            Esri.ArcGISRuntime.Symbology.SimpleFillSymbol mySimpleFillSymbol1 = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol();
            mySimpleFillSymbol1.Color = System.Windows.Media.Colors.Yellow;
            mySimpleFillSymbol1.Outline = myBlackSolidOutline;
            mySimpleFillSymbol1.Style = Esri.ArcGISRuntime.Symbology.SimpleFillStyle.Solid;
            myClassBreakInfo1.Symbol = mySimpleFillSymbol1;
            myClassBreaksRenderer.Infos.Add(myClassBreakInfo1);

            // Group #2
            Esri.ArcGISRuntime.Symbology.ClassBreakInfo myClassBreakInfo2 = new Esri.ArcGISRuntime.Symbology.ClassBreakInfo();
            myClassBreakInfo2.Minimum = 1000001;
            myClassBreakInfo2.Maximum = 10000000;
            Esri.ArcGISRuntime.Symbology.SimpleFillSymbol mySimpleFillSymbol2 = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol();
            mySimpleFillSymbol2.Color = System.Windows.Media.Colors.Green;
            mySimpleFillSymbol2.Outline = myBlackSolidOutline;
            mySimpleFillSymbol2.Style = Esri.ArcGISRuntime.Symbology.SimpleFillStyle.Solid;
            myClassBreakInfo2.Symbol = mySimpleFillSymbol2;
            myClassBreaksRenderer.Infos.Add(myClassBreakInfo2);

            // Group #3
            Esri.ArcGISRuntime.Symbology.ClassBreakInfo myClassBreakInfo3 = new Esri.ArcGISRuntime.Symbology.ClassBreakInfo();
            myClassBreakInfo3.Minimum = 10000001;
            myClassBreakInfo3.Maximum = 100000000;
            Esri.ArcGISRuntime.Symbology.SimpleFillSymbol mySimpleFillSymbol3 = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol();
            mySimpleFillSymbol3.Color = System.Windows.Media.Colors.Red;
            mySimpleFillSymbol3.Outline = myBlackSolidOutline;
            mySimpleFillSymbol3.Style = Esri.ArcGISRuntime.Symbology.SimpleFillStyle.Solid;
            myClassBreakInfo3.Symbol = mySimpleFillSymbol3;
            myClassBreaksRenderer.Infos.Add(myClassBreakInfo3);

            return myClassBreaksRenderer;
        }
    }
}
See Also
Supported Platforms
This type is supported on the following ArcGIS Runtime .NET SDK platforms:
Windows Desktop
Windows Phone
Windows Store
Additional Examples
Hyperlink to ExampleDescription
FeatureLayerViaShapefileDemonstrates creating a FeatureLayer from a ShapefileTable that is stored locally on disk.