Select to view content in your preferred language

Load FileGDB (export from ArcGIS Pro) via Map SDK

127
1
06-17-2024 09:09 AM
Labels (1)
JunGuan
Emerging Contributor

We use ArcGIS Pro to export a group layer into a lyrx file. This layer file indicates a FileGDB in the dataConnection:

 "dataConnection" : {
"type" : "CIMStandardDataConnection",
"workspaceConnectionString" : "DATABASE=C:\\Users\\****\\****\\Documents\\ArcGIS\\Packages\\KEk_GIS_20230414a_ajs_for_Geosoft_1ff973\\p20\\ek_map_20220622_ajs.gdb",
"workspaceFactory" : "FileGDB",
"dataset" : "DescriptionOfMapUnits",
"datasetType" : "esriDTTable"
}, 

We try to load this fileGDB with Map SDK based on this post https://community.esri.com/t5/net-maps-sdk-questions/have-to-add-feature-classes-from-file-geodataba.... But the sample in this post is for v100.7, and does exist in the current version(>100.15).

1) I try to add the sample into the current version. and get the following error when run it

---------------------------
Error
---------------------------
Esri.ArcGISRuntime.Http.ArcGISWebException: Failed to create service mpk_blank MapServer. Wrong package type used to start service

at Esri.ArcGISRuntime.Http.HttpDispatcher.SendAsync(HttpRequestMessage request, HandlerOptions options, CancellationToken cancellationToken)

at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)

at Esri.ArcGISRuntime.LocalServices.LocalService.StartServiceInternal(IDictionary`2 serviceSpecificParams, CancellationToken cancellationToken)

at ArcGISRuntime.WPF.Samples.DynamicWorkspaceShapefile.DynamicWorkspaceShapefile.StartLocalMapService(String filename, String path) in D:\others\arcgis-maps-sdk-dotnet-samples\src\WPF\WPF.Viewer\Samples\LocalServer\DynamicWorkspaceShapefile\DynamicWorkspaceShapefile.xaml.cs:line 107
---------------------------
OK
---------------------------

 

2) I try to update the "Local Server Image Map Layer" sample to load the FileGDB as the following

 

JunGuan_0-1718640213198.png

But I got the following error at line 106. 

Esri.ArcGISRuntime.Http.ArcGISWebException
HResult=0x00000000
Message=Unable to find the specified 'dataSourceName' in 'dataSource' for dynamic dataLayer with 'id': 0.
Source=Esri.ArcGISRuntime
StackTrace:
at Esri.ArcGISRuntime.Http.HttpDispatcher.<SendAsync>d__14.MoveNext()
at Esri.ArcGISRuntime.Internal.RequestHandler.<IssueRequestAndRespond>d__4.MoveNext()
at ArcGIS.WPF.Samples.LocalServerMapImageLayer.LocalServerMapImageLayer.<Initialize>d__2.MoveNext() in D:\others\arcgis-maps-sdk-dotnet-samples\src\WPF\WPF.Viewer\Samples\LocalServer\LocalServerMapImageLayer\LocalServerMapImageLayer.xaml.cs:line 125

This exception was originally thrown at this call stack:
[External Code]
ArcGIS.WPF.Samples.LocalServerMapImageLayer.LocalServerMapImageLayer.Initialize() in LocalServerMapImageLayer.xaml.cs

 

My question is:

Is Map SDK able to load a FileGDB from ArcGIS Pro? if it is, would you please provide a sample code for this issue? 

Thanks. 

 

Tags (1)
0 Kudos
1 Reply
MichaelBranscomb
Esri Frequent Contributor

Do you have strong requirement to use File Geodatabase? If not, then I recommend changing to using mobile geodatabases and mobile map packages that are supported directly by the API. 

But, if you do need to continue supporting File Geodatabase, then the Local Server is currently your only option. 

You should be able to follow this sample: arcgis-maps-sdk-dotnet-samples/src/WPF/ArcGISRuntime.WPF.Viewer/Samples/Local Server/DynamicWorkspac... (we removed the sample after 100.7 because it's no longer the promoted workflow).

I've used code like this:

...
// Add the dataset to a new dynamic map service layer instance.
await AddDatasetToMapImageLayer(
	WorkspaceType.FileGeodatabase, 
	SelectedGeodatabasePath,
	SelectedDataset.Name);
...

 

Which calls this function:

private async Task AddDatasetToMapImageLayer(WorkspaceType workspaceType, string directoryPath, string fileName)
{
	try
	{
		// Create a new LocalMapService instance using the empty Map Package.
		LocalMapService localMapService = new LocalMapService(_emptyMapPackage);

		// Create a new WorkspaceInfo object with a unique ID.
		string uniqueId = Guid.NewGuid().ToString();

		// Create a raster workspace or file geodatabase workspace.
		DynamicWorkspace dynamicWorkspace = null;
		switch (workspaceType)
		{
			case WorkspaceType.Raster:
				dynamicWorkspace = new RasterWorkspace(uniqueId, directoryPath);
				break;
			case WorkspaceType.FileGeodatabase:
				dynamicWorkspace = new FileGeodatabaseWorkspace(uniqueId, directoryPath);
				break;
		}

		// Add the dynamic workspace to the new local map service.
		localMapService.SetDynamicWorkspaces(new List<DynamicWorkspace> { dynamicWorkspace });

		// Start the service.
		await localMapService.StartAsync();

		// Create a new ArcGISLocalDynamicMapServiceLayer from the local service.
		ArcGISMapImageLayer arcGISMapImageLayer = new ArcGISMapImageLayer(localMapService.Url)
		{
			Id = "Workspace: " + (new DirectoryInfo(directoryPath)).Name,
		};

		// Clear any existing sub layers.
		arcGISMapImageLayer.Sublayers.Clear();

		// Create a sub layer source to represent the specific file/dataset in the workspace. 
		SublayerSource sublayerSource = null;
		if (SelectedDataset.Datatype == "Feature Class")
		{
			sublayerSource = new TableSublayerSource(dynamicWorkspace.Id, fileName);
		}
		else
		{
			sublayerSource = new RasterSublayerSource(dynamicWorkspace.Id, fileName);
		}

		// Create a new map image sub layer referencing the source.
		ArcGISMapImageSublayer arcGISMapImageSublayer = new ArcGISMapImageSublayer(0, sublayerSource);

		// Add the sublayer to the sub layers collection on the map image layer
		arcGISMapImageLayer.Sublayers.Add(arcGISMapImageSublayer);

		// Set the top level name on the map image layer (for the TOC).
		arcGISMapImageLayer.Name = arcGISMapImageLayer.Sublayers[0].Name;

		// Add the sublayer to the operational layers collection on the map.
		Map.OperationalLayers.Add(arcGISMapImageLayer);

		// Load the raster sub layer to get the extent from the service info.
		await arcGISMapImageSublayer.LoadAsync();

		// Invoke the set viewpoint event to update the UI.
		SetViewpointRequested?.Invoke(this, new Viewpoint(arcGISMapImageSublayer.MapServiceSublayerInfo.Extent));
	}
	catch (Exception ex)
	{
		DisplayStatus?.Invoke(this, ex.Message);
	}
}

 

0 Kudos