<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why was the DynamicWorkspaceShapefile sample removed? in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1379732#M12520</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Displaying Shapefiles should work fine using Local Server and the API type&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netfx/LocalServices/Esri.ArcGISRuntime.LocalServices.ShapefileWorkspace.html" target="_blank"&gt;Class ShapefileWorkspace (arcgis.com)&lt;/A&gt;&amp;nbsp;although the reason the sample for that type was removed is because it's no longer the promoted workflow. Instead, best practice is to use the API directly via the&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netfx/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Data.ShapefileFeatureTable.html" target="_blank"&gt;Class ShapefileFeatureTable (arcgis.com)&lt;/A&gt;&amp;nbsp;type as shown by sample&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/wpf/sample-code/symbolize-shapefile/" target="_blank"&gt;Symbolize shapefile | ArcGIS Maps SDK for .NET | ArcGIS Developers&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2024 15:55:10 GMT</pubDate>
    <dc:creator>MichaelBranscomb</dc:creator>
    <dc:date>2024-02-08T15:55:10Z</dc:date>
    <item>
      <title>Why was the DynamicWorkspaceShapefile sample removed?</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1378537#M12514</link>
      <description>&lt;P&gt;I am looking into loading a local shape file (as well as file geodatabase) using a local server. Initially, I just used the ArcGISRuntime.ShapefileFeatureTable to display a shapefile and I was successful in doing that. However, file geodatabase is not supported and I need to use the local server.&lt;/P&gt;&lt;P&gt;I saw a post regardingthat makes use of&amp;nbsp;ShapefileWorkspace but I wasn't able to make it work. I noticed that the&amp;nbsp;DynamicWorkspaceShapefile&amp;nbsp; was removed in the latest code in the sample git repository. Is there a reason that it was removed?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 06:29:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1378537#M12514</guid>
      <dc:creator>MarkReyes11</dc:creator>
      <dc:date>2024-02-06T06:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why was the DynamicWorkspaceShapefile sample removed?</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1378588#M12515</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/762429"&gt;@MarkReyes11&lt;/a&gt;&amp;nbsp;thank you for your question.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Could you give me a little more information on the problem you are seeing?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What did you find prevented ShapefileWorkspace working?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 12:11:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1378588#M12515</guid>
      <dc:creator>HamishDuff</dc:creator>
      <dc:date>2024-02-06T12:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why was the DynamicWorkspaceShapefile sample removed?</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1378606#M12516</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/755586"&gt;@HamishDuff&lt;/a&gt;&amp;nbsp;, thank you for answering. Basically, I'm unable to display the shapefile when I use Local Server and ShapeFileWorkspace though I was able to display it using &lt;SPAN&gt;ShapefileFeatureTable&amp;nbsp;&lt;/SPAN&gt;. Here's an screenshot of my test app after selecting the subdivision.shp file. I actually copied the code from the DynamicWOrkspaceShapeFile sample. I'm also wondering why this sample was removed from the main branch of the git repo.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MarkReyes11_0-1707226470057.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/93820iD007814264096F72/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MarkReyes11_0-1707226470057.png" alt="MarkReyes11_0-1707226470057.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is my code.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// Copyright 2017 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: http://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.


using Esri.ArcGISRuntime.LocalServices;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Drawing;
using Esri.ArcGISRuntime.Data;

namespace ArcGisLocal
{
    public partial class DynamicWorkspaceShapefile
    {
        // Hold a reference to the local map service
        private LocalMapService _localMapService;

        // Hold a reference to the layer that will display the shapefile data
        private ArcGISMapImageSublayer _shapefileSublayer;

        public DynamicWorkspaceShapefile()
        {
            InitializeComponent();
            
            Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "MY_API_KEY";

            // Create the UI, setup the control references and execute initialization
            Initialize();
        }

        private async void Initialize()
        {
            // Create a map and add it to the view
            MyMapView.Map = new Map(BasemapStyle.ArcGISStreets);

            try
            {
                // LocalServer must not be running when setting the data path.
                if (LocalServer.Instance.Status == LocalServerStatus.Started)
                {
                    await LocalServer.Instance.StopAsync();
                }

                // Set the local data path - must be done before starting. On most systems, this will be C:\EsriSamples\AppData.
                // This path should be kept short to avoid Windows path length limitations.
                string tempDataPathRoot = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.Windows)).FullName;
                string tempDataPath = Path.Combine(tempDataPathRoot, "EsriSamples", "AppData");
                Directory.CreateDirectory(tempDataPath); // CreateDirectory won't overwrite if it already exists.
                LocalServer.Instance.AppDataPath = tempDataPath;

                // Start the local server instance
                await LocalServer.Instance.StartAsync();

                // Load the sample data
                LoadShapefilePaths();

                // Enable the 'choose shapefile' button
                MyChooseButton.IsEnabled = true;
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(String.Format("Please ensure that local server is installed prior to using the sample. See instructions in readme.md. Message: {0}", ex.Message), "Local Server failed to start");
            }
        }

        private async void StartLocalMapService(string filename, string path)
        {

            #region Using ShapefileFeatureTable
            // Open the shapefile
            //ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(Path.Combine(path, filename));

            //// Create a feature layer to display the shapefile
            //FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile);
            //await newFeatureLayer.LoadAsync();

            //MyMapView.Map.OperationalLayers.Clear();

            //// Zoom the map to the extent of the shapefile
            //MyMapView.SetViewpoint(new Viewpoint(newFeatureLayer.FullExtent));

            //// Add the layer to the map
            //MyMapView.Map.OperationalLayers.Add(newFeatureLayer);

            #endregion

            #region Using Local Server
            // Start a service from the blank MPK
            string mapServiceUrl = GetMpkPath();

            // Create the local map service
            _localMapService = new LocalMapService(mapServiceUrl);

            // Create the shapefile workspace
             ShapefileWorkspace shapefileWorkspace = new ShapefileWorkspace("shp_wkspc", path);
            // Create the layer source that represents the shapefile on disk
            TableSublayerSource source = new TableSublayerSource(shapefileWorkspace.Id, filename);

            // Create a sublayer instance from the table source
            _shapefileSublayer = new ArcGISMapImageSublayer(0, source);

            // Add the dynamic workspace to the map service
            _localMapService.SetDynamicWorkspaces(new List&amp;lt;DynamicWorkspace&amp;gt;() { shapefileWorkspace });

            // Subscribe to notifications about service status changes
            _localMapService.StatusChanged += _localMapService_StatusChanged;

            try
            {
                // Start the map service
                await _localMapService.StartAsync();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error");
            }
            #endregion
        }

        private async void _localMapService_StatusChanged(object sender, StatusChangedEventArgs e)
        {
            // Add the shapefile layer to the map once the service finishes starting
            if (e.Status == LocalServerStatus.Started)
            {
                // Create the imagery layer
                ArcGISMapImageLayer imageryLayer = new ArcGISMapImageLayer(_localMapService.Url);

                // Subscribe to image layer load status change events
                // Only set up the sublayer renderer for the shapefile after the parent layer has finished loading
                imageryLayer.LoadStatusChanged += (q, ex) =&amp;gt;
                {
                    // Add the layer to the map once loaded
                    if (ex.Status == Esri.ArcGISRuntime.LoadStatus.Loaded)
                    {
                        // Create a default symbol style
                        SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Red, 3);

                        // Apply the symbol style with a renderer
                        _shapefileSublayer.Renderer = new SimpleRenderer(lineSymbol);

                        // Add the shapefile sublayer to the imagery layer
                        imageryLayer.Sublayers.Add(_shapefileSublayer);
                    }
                };

                try
                {
                    // Load the layer
                    await imageryLayer.LoadAsync();

                    // Clear any existing layers
                    MyMapView.Map.OperationalLayers.Clear();

                    // Add the image layer to the map
                    MyMapView.Map.OperationalLayers.Add(imageryLayer);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
            }
        }

        private static string GetMpkPath()
        {
            // Gets the path to the blank map package
            return @"D:\Repos\playground\wpfapp1\ArcGisLocal\mpks\blankMap.mpkx";
        }

        private static string LoadShapefilePaths()
        {
            // Gets the path to the shapefile package
            return @"D:\Repos\playground\wpfapp1\ArcGisLocal\shapefiles";
        }

        private void MyChooseButton_Click(object sender, RoutedEventArgs e)
        {
            // Allow the user to specify a file path - create the dialog
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog()
            {
                DefaultExt = ".shp",
                Filter = "Shapefiles|*.shp",
                InitialDirectory = Path.GetDirectoryName(LoadShapefilePaths())
            };

            // Show the dialog and get the results
            bool? result = dlg.ShowDialog();

            // Take action if the user selected a file
            if (result == true)
            {
                string filename = Path.GetFileName(dlg.FileName);
                string path = Path.GetDirectoryName(dlg.FileName);
                StartLocalMapService(filename, path);
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 13:40:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1378606#M12516</guid>
      <dc:creator>MarkReyes11</dc:creator>
      <dc:date>2024-02-06T13:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why was the DynamicWorkspaceShapefile sample removed?</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1379732#M12520</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Displaying Shapefiles should work fine using Local Server and the API type&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netfx/LocalServices/Esri.ArcGISRuntime.LocalServices.ShapefileWorkspace.html" target="_blank"&gt;Class ShapefileWorkspace (arcgis.com)&lt;/A&gt;&amp;nbsp;although the reason the sample for that type was removed is because it's no longer the promoted workflow. Instead, best practice is to use the API directly via the&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netfx/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Data.ShapefileFeatureTable.html" target="_blank"&gt;Class ShapefileFeatureTable (arcgis.com)&lt;/A&gt;&amp;nbsp;type as shown by sample&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/wpf/sample-code/symbolize-shapefile/" target="_blank"&gt;Symbolize shapefile | ArcGIS Maps SDK for .NET | ArcGIS Developers&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 15:55:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/why-was-the-dynamicworkspaceshapefile-sample/m-p/1379732#M12520</guid>
      <dc:creator>MichaelBranscomb</dc:creator>
      <dc:date>2024-02-08T15:55:10Z</dc:date>
    </item>
  </channel>
</rss>

