ArcGIS Runtime SDK for .NET problem loading shapefile

4263
2
Jump to solution
08-02-2015 12:27 AM
EgilRasmussen1
New Contributor

I am moving from ArcGIS WPF to  ArcGIS .NET.

When I add  shapefiles to the map layer in the .NET version the  backdrop ArcGISTiledMapServiceLayer disappears.

Can anybody tell me how to correct it?

I use Visual Studio 2013, VB.NET and Esri.ArcGISRuntime 10.2.6.0.

Here is the code:

XAML

<Window x:Class="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>

                <!-- A MapView Control to display various GIS layers. -->

        <esri:MapView x:Name="MapView1" Width="662" Height="507" VerticalAlignment="Top" Margin="2,2,2,2">

            <!-- A Map. -->

            <esri:Map  x:Name="Map1" >

                <!-- Add a backdrop ArcGISTiledMapServiceLayer-->

                <esri:ArcGISTiledMapServiceLayer ID="myArcGISTiledMapServiceLayer"

                    ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer" />

            </esri:Map>

        </esri:MapView>

    </Grid>

</Window>

VB

' 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.

Class MainWindow

    Public Sub New()

        ' This call is required by the designer.

        InitializeComponent()

        ' Set the initial extent to that of the continental US.

        Dim myEnvelope As Esri.ArcGISRuntime.Geometry.Envelope = 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)

    End Sub

    Private Async Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

        ' Create a ShapefileTable from the .shp file.

        Dim myShapefileTable As Esri.ArcGISRuntime.Data.ShapefileTable = Await Esri.ArcGISRuntime.Data.ShapefileTable.OpenAsync("C:\TestData\State_2010Census_DP1\State_2010Census_DP1.shp")

        ' Create a new FeatureLayer based upon the ShapefileTable. Set its .ID and .DisplayName properties.

        Dim myFeatureLayer As Esri.ArcGISRuntime.Layers.FeatureLayer = New Esri.ArcGISRuntime.Layers.FeatureLayer(myShapefileTable)

        myFeatureLayer.ID = "States"

        myFeatureLayer.DisplayName = "States"

        ' Add the FeatureLayer to the Map.

        MapView1.Map.Layers.Add(myFeatureLayer)

    End Sub

End Class

0 Kudos
1 Solution

Accepted Solutions
FreddieGibson
Regular Contributor II

I believe your problem is that you're using ArcGISTiledMapServiceLayer for your basemap instead of ArcGISDynamicMapServiceLayer. I would think you'd need to use the latter because you're needing your basemap to be projected on the server from 3857 to 4269.

I've included a copy of the project I tested this with. You'll see that if you change line 33 to ArcGISTiledMapServerLayer that you can replicate your issue, which is that when the feature layer is added and the coordinate for the map is changed to 4269 the basemap no longer renders.

Step One. Click the Add Shapefile button to add the shapefile to the map. This will set the coordinate system of the map to 4269.

2015-09-16_1522.png

Step Two. Click the Add Basemap tool to insert the basemap into the map. Note that if you use ArcGISDynamicMapServerLayer that the server will handle projecting the basemap from 3857 to 4269 and it will still be visible in the map. If you use ArcGISTiledMapServiceLayer the layer will not project the basemap. As a result the basemap will not be visible.

2015-09-16_1522_001.png

*** Below is the relevant logic in case you don't want to download the attachment ***

private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            string tag = (sender as Button).Tag.ToString();


            switch (tag)
            {
                case "basemap":
                    var basemap = new ArcGISDynamicMapServiceLayer(new Uri("http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer"));
                    MyMapView.Map.Layers.Insert(0, basemap);
                    break;
                case "shapefile":
                    var table = await ShapefileTable.OpenAsync(_shpPath);
                    var layer = new FeatureLayer
                    {
                        ID = table.Name,
                        DisplayName = table.Name,
                        FeatureTable = table
                    };
                    MyMapView.Map.Layers.Add(layer);
                    break;
                default:
                    MyMapView.Map = new Map();
                    break;
            }
        }

View solution in original post

0 Kudos
2 Replies
FreddieGibson
Regular Contributor II

I believe your problem is that you're using ArcGISTiledMapServiceLayer for your basemap instead of ArcGISDynamicMapServiceLayer. I would think you'd need to use the latter because you're needing your basemap to be projected on the server from 3857 to 4269.

I've included a copy of the project I tested this with. You'll see that if you change line 33 to ArcGISTiledMapServerLayer that you can replicate your issue, which is that when the feature layer is added and the coordinate for the map is changed to 4269 the basemap no longer renders.

Step One. Click the Add Shapefile button to add the shapefile to the map. This will set the coordinate system of the map to 4269.

2015-09-16_1522.png

Step Two. Click the Add Basemap tool to insert the basemap into the map. Note that if you use ArcGISDynamicMapServerLayer that the server will handle projecting the basemap from 3857 to 4269 and it will still be visible in the map. If you use ArcGISTiledMapServiceLayer the layer will not project the basemap. As a result the basemap will not be visible.

2015-09-16_1522_001.png

*** Below is the relevant logic in case you don't want to download the attachment ***

private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            string tag = (sender as Button).Tag.ToString();


            switch (tag)
            {
                case "basemap":
                    var basemap = new ArcGISDynamicMapServiceLayer(new Uri("http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer"));
                    MyMapView.Map.Layers.Insert(0, basemap);
                    break;
                case "shapefile":
                    var table = await ShapefileTable.OpenAsync(_shpPath);
                    var layer = new FeatureLayer
                    {
                        ID = table.Name,
                        DisplayName = table.Name,
                        FeatureTable = table
                    };
                    MyMapView.Map.Layers.Add(layer);
                    break;
                default:
                    MyMapView.Map = new Map();
                    break;
            }
        }
0 Kudos
EgilRasmussen1
New Contributor

Freddie

Thank you very much for your detailed explanation that solved my problem.

Best regards

Egil

0 Kudos