Hello! I need an offline syncable geodatabase. I am trying to read fields from a geodatabase, but the results are empty. None of the fields load.
The table has fields, I'd expect to see these headers:
My code is effectively the same as the sample from the ArcGIS.WinUI.Samples.GeodatabaseTransactions
private async Task GetLocalGeodatabase()
{
// Get the path to the local geodatabase for this platform (temp directory, for example).
string localGeodatabasePath = GetGdbPath();
try
{
// See if the geodatabase file is already present.
if (File.Exists(localGeodatabasePath))
{
// If the geodatabase is already available, open it, hide the progress control, and update the message.
_localGeodatabase = await Geodatabase.OpenAsync(localGeodatabasePath);
LoadingProgressBar.Visibility = Visibility.Collapsed;
MessageTextBlock.Text = "Using local geodatabase from '" + _localGeodatabase.Path + "'";
}
else
{
// Create a new GeodatabaseSyncTask with the uri of the feature server to pull from.
Uri uri = new Uri(SyncServiceUrl);
GeodatabaseSyncTask gdbTask = await GeodatabaseSyncTask.CreateAsync(uri);
// Create parameters for the task: layers and extent to include, out spatial reference, and sync model.
GenerateGeodatabaseParameters gdbParams = await gdbTask.CreateDefaultGenerateGeodatabaseParametersAsync(_extent);
gdbParams.OutSpatialReference = MyMapView.SpatialReference;
gdbParams.SyncModel = SyncModel.Layer;
gdbParams.LayerOptions.Clear();
gdbParams.LayerOptions.Add(new GenerateLayerOption(0));
gdbParams.LayerOptions.Add(new GenerateLayerOption(1));
// Create a geodatabase job that generates the geodatabase.
GenerateGeodatabaseJob generateGdbJob = gdbTask.GenerateGeodatabase(gdbParams, localGeodatabasePath);
// Handle the job changed event and check the status of the job; store the geodatabase when it's ready.
generateGdbJob.StatusChanged += (s, e) =>
{
// See if the job succeeded.
if (generateGdbJob.Status == JobStatus.Succeeded)
{
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
{
// Hide the progress control and update the message.
LoadingProgressBar.Visibility = Visibility.Collapsed;
MessageTextBlock.Text = "Created local geodatabase";
});
}
else if (generateGdbJob.Status == JobStatus.Failed)
{
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
{
// Hide the progress control and report the exception.
LoadingProgressBar.Visibility = Visibility.Collapsed;
MessageTextBlock.Text = "Unable to create local geodatabase: " + generateGdbJob.Error.Message;
});
}
};
// Start the generate geodatabase job.
_localGeodatabase = await generateGdbJob.GetResultAsync();
}
}
catch (Exception ex)
{
// Show a message for the exception encountered.
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
{
_ = new MessageDialog2("Unable to create offline database: " + ex.Message).ShowAsync();
});
}
}
Strangely enough it seems to loaded the Domains , so I know its downloaded the correct table:
Editing is enabled in the service, and all users should be able to view features:
Solved! Go to Solution.
So I have tried to make a smaller test case using ServiceFeatureTable or through ServiceGeodatabase:. Results are same: empty table
public static async Task ServiceGeodatabase() {
var serviceGeodatabase = new ServiceGeodatabase(new Uri(featureServiceUri));
await serviceGeodatabase.LoadAsync();
ServiceFeatureTable table = serviceGeodatabase.GetTable(0);
_ = table.Fields; //breakpoint here, why this is empty?
}
-or-
public static async Task GetServiceTable() {
ServiceFeatureTable table = new(new Uri(featureServiceUri));
var layer = new FeatureLayer(table);
_ = table.Fields; //breakpoint here, why this is empty?
}
That was it. Thank you!
Follow up question, not sure if I should make a new topic, but now I am trying to read the fields / attributes from the table after it has been loaded. I keep getting "null" as a response. There is data in the table. Is there something else I need to call to load the actual values themselves?
edit: solved