public new RealtimeFeatureClass GetFeatureClass()
Public Shadows Function GetFeatureClass() As RealtimeFeatureClass
Return Value
A FeatureClass.
public new RealtimeFeatureClass GetFeatureClass()
Public Shadows Function GetFeatureClass() As RealtimeFeatureClass
| Exception | Description |
|---|---|
| ArcGIS.Core.CalledOnWrongThreadException | This method or property must be called within the lambda passed to QueuedTask.Run. |
{
await QueuedTask.Run(() =>
{
//Must be called on the feature class
using var rfc = streamLayer.GetFeatureClass();
rfc.Truncate();
});
}
{
//query filter can be null to search and retrieve all rows
//true means recycling cursor
using (var rc = await QueuedTask.Run(() => streamLayer.SearchAndSubscribe(qfilter, true)))
{
//waiting for new features to be streamed
//default is no cancellation
while (await rc.WaitForRowsAsync())
{
while (rc.MoveNext())
{
using (var row = rc.Current)
{
//determine the origin of the row event
switch (row.GetRowSource())
{
case RealtimeRowSource.PreExisting:
//pre-existing row at the time of subscribe
continue;
case RealtimeRowSource.EventInsert:
//row was inserted after subscribe
continue;
case RealtimeRowSource.EventDelete:
//row was deleted after subscribe
continue;
}
}
}
}
}//row cursor is disposed. row cursor is unsubscribed
//....or....
//Use the feature class instead of the layer
RealtimeFeatureClass rfc = null;
RealtimeCursor realtimeCursor = null;
await QueuedTask.Run(() =>
{
rfc = streamLayer.GetFeatureClass();
//non-recycling cursor - 2nd param "false"
realtimeCursor = rfc.SearchAndSubscribe(qfilter, false);
});
using (rfc)
using (realtimeCursor)
{
//waiting for new features to be streamed
//default is no cancellation
while (await realtimeCursor.WaitForRowsAsync())
{
//etc
}
}
}
{
await QueuedTask.Run(() =>
{
using var rfc = streamLayer.GetFeatureClass();
using var rfc_def = rfc.GetDefinition();
if (rfc_def.HasTrackIDField())
{
//Track aware
}
});
}
{
await QueuedTask.Run(() =>
{
using (var rfc = streamLayer.GetFeatureClass())
using (var rfc_def = rfc.GetDefinition())
{
if (rfc_def.HasTrackIDField())
{
var fld_name = rfc_def.GetTrackIDField();
}
}
});
}
{
//Note: with feature class we can also use a System Task to subscribe and
//process rows
RealtimeFeatureClass rfc = null;
RealtimeCursor rc = null;
await QueuedTask.Run(() =>
{
// or var rfc = realtimeDatastore.OpenTable(name) as RealtimeFeatureClass
rfc = streamLayer.GetFeatureClass();
//non-recycling cursor - 2nd param "false"
//subscribe, pre-existing rows are not searched
rc = rfc.Subscribe(qfilter, false);
});
using (rfc)
using (rc)
{
SpatialQueryFilter spatialFilter = new SpatialQueryFilter();
//waiting for new features to be streamed
//default is no cancellation
while (await rc.WaitForRowsAsync())
{
while (rc.MoveNext())
{
using (var row = rc.Current)
{
switch (row.GetRowSource())
{
case RealtimeRowSource.EventInsert:
//getting geometry from new events as they arrive
Polygon poly = ((RealtimeFeature)row).GetShape() as Polygon;
//using the geometry to select features from another feature layer
spatialFilter.FilterGeometry = poly;//project poly if needed...
await QueuedTask.Run(() => featureLayer.Select(spatialFilter));
continue;
default:
continue;
}
}
}
}
//row cursor is disposed. row cursor is unsubscribed
}
}
{
//Note we can use System Task with the Realtime feature class
//for subscribe
RealtimeFeatureClass rfc = null;
RealtimeCursor rc = null;
await QueuedTask.Run(() =>
{
rfc = streamLayer.GetFeatureClass();
//non-recycling cursor - 2nd param "false"
rc = rfc.SearchAndSubscribe(qfilter, false);
});
using (rfc)
using (rc)
{
//waiting for new features to be streamed
//default is no cancellation - use await in async method
while (await rc.WaitForRowsAsync())
{
//pre-existing rows will be retrieved that were searched
while (rc.MoveNext())
{
using RealtimeRow row = rc.Current;
var row_source = row.GetRowSource();
switch (row_source)
{
case RealtimeRowSource.EventDelete:
//TODO - handle deletes
break;
case RealtimeRowSource.EventInsert:
//TODO handle inserts
break;
case RealtimeRowSource.PreExisting:
//TODO handle pre-existing rows
break;
}
}
}
//row cursor is disposed. row cursor is unsubscribed
}
}
{
RealtimeFeatureClass rfc = null;
RealtimeCursor rc = null;
await QueuedTask.Run(() =>
{
rfc = streamLayer.GetFeatureClass();
//Recycling cursor - 2nd param "true"
rc = rfc.SearchAndSubscribe(qfilter, true);
});
using (rfc)
using (rc)
{
//auto-cancel after 20 seconds
var cancel = new CancellationTokenSource(new TimeSpan(0, 0, 20));
//catch TaskCanceledException
try
{
// Use await in async method
while (await rc.WaitForRowsAsync(cancel.Token))
{
//check for row events
while (rc.MoveNext())
{
using RealtimeRow record = rc.Current;
// Process the record
}
}
}
catch (TaskCanceledException)
{
//Handle cancellation as needed
}
cancel.Dispose();
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)