Hi,
I am trying to load feature classes from local GeoDatabase to map.
I can load feature classes from local MobileGDB. It's difficult to load it from local File GDB.
But I have to load feature classes from local FileGDB to map.
If anyone has any reference on this, please help me out.
It would be great pleasure if anyone helps me out in this!
Solved! Go to Solution.
Your example was missing the code to add a FileGeodatabaseworkspace.
For example:
try
{
// Path to File Geodatabase (from your user input from folder browser dialog))
string path = "";
// The feature class name to add
string featureClassName = ""
// Start a service from the blank MPK
string mapPackagePath = @"..\..\mpk_blank.mpk";
// Create the local map service
LocalMapService localMapService = new LocalMapService(mapPackagePath);
// Create the shapefile workspace
FileGeodatabaseWorkspace fileGeodatabaseWorkspace = new FileGeodatabaseWorkspace("FileGeodatabaseWorkspace1", path);
// Add the dynamic workspace to the map service
localMapService.SetDynamicWorkspaces(new List<DynamicWorkspace>() { fileGeodatabaseWorkspace });
// Start the map service
await localMapService.StartAsync();
// Create the ArcGISMapImageLayer layer
ArcGISMapImageLayer arcGISMapImageLayer = new ArcGISMapImageLayer(localMapService.Url);
// Load the layer
await arcGISMapImageLayer.LoadAsync();
// Create the layer source that represents the shapefile on disk
TableSublayerSource source = new TableSublayerSource(fileGeodatabaseWorkspace.Id, featureClassName);
// Create a sublayer instance from the table source
ArcGISMapImageSublayer fileGeodatabaseSublayer = new ArcGISMapImageSublayer(0, source);
// Apply renderer to layer to symbolize if not default
// ...
// Add the shapefile sublayer to the imagery layer
arcGISMapImageLayer.Sublayers.Add(fileGeodatabaseSublayer);
// Add the image layer to the map
MyMapView.Map.OperationalLayers.Add(arcGISMapImageLayer);
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error");
}
File Geodatabases are not supported directly by ArcGIS Runtime, but it is possible to use them with the ArcGIS Runtime Local Server component. When using ArcGIS Runtime SDK for .NET, the Local Server is only available with the WPF API and on Windows (not supported when usinf the Android, iOS, or UWP APIs).
You can follow the same workflow as shown in this sample, but instead of creating a `ShapefileWorkspace`, you will create a `FileGeodatabaseWorkspace`. Note, you will need to know in advance the name of the data set within the file geodatabase that you want to add. You can achieve this by also writing a python script in ArcGIS Pro which would take an input string that is the file geodatabase path and return a list of datasets ad a geoprocessing recordset.
API Ref:
Sample (Shapefile):
Creating a geoprocessing package for Local Server:
https://developers.arcgis.com/labs/pro/prepare-a-geoprocessing-service-for-offline-use/
Python script example:
# Import necessary modules
import arcpy
import os
# Set variables from input parameters.
workspace = arcpy.GetParameterAsText(0)
# Set the current workspace
arcpy.env.workspace = str(workspace)
# Create the output table.
outTableFc = arcpy.CreateTable_management('in_memory', 'datasets')
# Set the field names and definitions for the output table.
arcpy.AddField_management(outTableFc, 'NAME', 'TEXT', '', '', 256)
arcpy.AddField_management(outTableFc, 'DATATYPE', 'TEXT', '', '', 256)
# Create an insert cursor to insert rows into the output table.
fields = ['NAME', 'DATATYPE']
cur = arcpy.da.InsertCursor(outTableFc, fields)
# Feature
datasets = arcpy.ListFeatureClasses()
# For each dataset insert the name into a new row in the table.
for dataset in datasets:
cur.insertRow((dataset, 'Feature Class'))
# Mosaic
datasets = arcpy.ListDatasets(feature_type='mosaic')
# For each dataset insert the name into a new row in the table.
for dataset in datasets:
cur.insertRow((dataset, 'Mosaic'))
# Raster
datasets = arcpy.ListDatasets(feature_type='raster')
# For each dataset insert the name into a new row in the table.
for dataset in datasets:
cur.insertRow((dataset, 'Raster'))
# Raster
datasets = arcpy.ListDatasets(feature_type='rastercatalog')
# For each dataset insert the name into a new row in the table.
for dataset in datasets:
cur.insertRow((dataset, 'Raster Catalog'))
del cur
# Set the output parameter.
arcpy.SetParameterAsText(1,outTableFc)
Hi,
Thank you for your response.
I have tried the sample which you are given. In this sample, the layer is added in the map, but it's not displaying in the map.
Also I have attached the output screenshot below.
It would be great pleasure if there is a solution for this!
It looks like you have a standalone test app - can you share your code?
Hi,
Kindly share me if any solutions are there.
It would be great help
Your example was missing the code to add a FileGeodatabaseworkspace.
For example:
try
{
// Path to File Geodatabase (from your user input from folder browser dialog))
string path = "";
// The feature class name to add
string featureClassName = ""
// Start a service from the blank MPK
string mapPackagePath = @"..\..\mpk_blank.mpk";
// Create the local map service
LocalMapService localMapService = new LocalMapService(mapPackagePath);
// Create the shapefile workspace
FileGeodatabaseWorkspace fileGeodatabaseWorkspace = new FileGeodatabaseWorkspace("FileGeodatabaseWorkspace1", path);
// Add the dynamic workspace to the map service
localMapService.SetDynamicWorkspaces(new List<DynamicWorkspace>() { fileGeodatabaseWorkspace });
// Start the map service
await localMapService.StartAsync();
// Create the ArcGISMapImageLayer layer
ArcGISMapImageLayer arcGISMapImageLayer = new ArcGISMapImageLayer(localMapService.Url);
// Load the layer
await arcGISMapImageLayer.LoadAsync();
// Create the layer source that represents the shapefile on disk
TableSublayerSource source = new TableSublayerSource(fileGeodatabaseWorkspace.Id, featureClassName);
// Create a sublayer instance from the table source
ArcGISMapImageSublayer fileGeodatabaseSublayer = new ArcGISMapImageSublayer(0, source);
// Apply renderer to layer to symbolize if not default
// ...
// Add the shapefile sublayer to the imagery layer
arcGISMapImageLayer.Sublayers.Add(fileGeodatabaseSublayer);
// Add the image layer to the map
MyMapView.Map.OperationalLayers.Add(arcGISMapImageLayer);
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Error");
}
Hi,
Thank you for your solution!
But I just need to add file geo database without mentioning the feature class name in the code.
Is there any possibility for this?
It would be great pleasure if it is there.