0

Does anyone know how to access local file geodatabase from ArcGIS Runtime API using Local Server?

Are there any samples for that?

  • 2
    Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour. Thanks. Where have you looked already? – PolyGeo Oct 22 '18 at 3:26
  • saeid, This dynamic approach seems to work fine when displaying the gdb table on the map. Do you know of a way to perform queries against the gdb table and iterate through the results? It's not immediately obvious how that might be accomplished. Thanks. – ChannelingMyInnerBeer Jan 31 at 21:29
  • Which runtime? With WPF I found the File Geodatabase API very helpful. github.com/Esri/file-geodatabase-api – Kirk Kuykendall Jan 31 at 23:13
0

I just found one way of accessing file geodatabase through the local server as follows.

    private ArcGISMapImageSublayer _fileGeodatabaseSublayer;
    private LocalServer _LocalServer;

    public MainWindow()
    {
        InitializeComponent();
        Initialize();
    } 
    private async void Initialize()
    {
        // Create a map and add it to the view
        MyMapView.Map = new Map(BasemapType.Topographic, 39.7294, -104.8319, 12);

        try
        {
            // Start the local server instance
            await LocalServer.Instance.StartAsync();
        }
        catch (InvalidOperationException ex)
        {
            MessageBox.Show(String.Format("Please ensure that local server is installed prior to using the sample. See instructions in readme.md or metadata.json. Message: {0}", ex.Message), "Local Server failed to start");
        }
    }
    private void m_Button_Click(object sender, RoutedEventArgs e)
    {
         string filePath = "D:\\test\\test.gdb";
        string fileName = "featureclass1";
        StartLocalMapService(fileName, filePath);
    }
    private async void StartLocalMapService(string fileName, string filePath)
    {
        // any mpk file -  don't know why
        string mapServiceUrl = System.IO.Path.GetDirectoryName(filePath) + "\\mpk_blank.mpk";

        // Create the local map service
        var localMapService = new LocalMapService(mapServiceUrl);
        FileGeodatabaseWorkspace ws = new FileGeodatabaseWorkspace("file_wkspc", filePath);
        TableSublayerSource source = new TableSublayerSource(ws.Id, fileName);
        _fileGeodatabaseSublayer = new ArcGISMapImageSublayer(0, source);
        localMapService.SetDynamicWorkspaces(new List<DynamicWorkspace>()
        {
            ws
        });
        localMapService.StatusChanged += localMapService_StatusChanged;
        await localMapService.StartAsync();
    }
    private async void localMapService_StatusChanged(object sender, StatusChangedEventArgs e)
    {
        if (e.Status == LocalServerStatus.Started)
        {
            if (!(sender is LocalMapService localService))
            {
                return;
            }
            ArcGISMapImageLayer imageryLayer = new ArcGISMapImageLayer(localService.Url);
            imageryLayer.LoadStatusChanged += (q, ex) =>
            {
                // 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, System.Drawing.Color.Red, 3);
                    // Apply the symbol style with a renderer
                    _fileGeodatabaseSublayer.Renderer = new SimpleRenderer(lineSymbol);
                    imageryLayer.Sublayers.Add(_fileGeodatabaseSublayer);
                }
            };
            await imageryLayer.LoadAsync();
            MyMapView.Map.OperationalLayers.Clear();
           // Add the image layer to the map
            MyMapView.Map.OperationalLayers.Add(imageryLayer);
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.