ThinkGeo.com    |     Documentation    |     Premium Support

WfsV2FeatureLayer vs WfsV2AsyncLayer

Hi,

We have been using WfsV2FeatureLayer for a while but now it’s marked as obsolete and WfsV2AsyncLayer should be used instead.

There are couple of problems related to this change from your POV.

  1. It seems that WfsV2AsyncLayer does not support QueryTools which we have been using to get features from WfsV2FeatureLayer in different scenarios. Is there some way to query features from WfsV2AsyncLayer or would it be possible to add support for QueryTools ?

  2. We have generic implementation for different layers which use FeatureLayer as base class (OgcApi/Wfs/WfsV2/etc.) for setting styles etc. Problem is that now WfsV2AsyncLayer has totally different inheritance and would mean that instead of common implementation handling FeatureLayer we would need own specific implementation for WfsV2AsyncLayer.

BTW, what is the reason for removing WfsV2FeatureLayer ? It has been working without issues on our case so far.

Br, Simo

Hi Simo,

Good points! Here is why we did it and how we are going to fix it:

Why async

  1. The sync path uses WebRequest, which is legacy and broken on some targets (Blazor WASM for example). Its replacement, HttpClient, exposes only async methods. That leaves two options: block on the async call (.Result), which deadlocks under a SynchronizationContext and wastes a thread-pool thread, or let async go all the way up.

  2. Async also handles cancellation properly, and an async signature is a more honest description of a class that fetches over the network.

What we got wrong

  1. The new async classes (WfsV2AsyncLayer, as well as other web-based async layers) have to pass through FeatureSource, whose core methods (GetAllFeaturesCore, GetFeaturesInsideBoundingBoxCore) are all synchronous. This answers your first question directly: QueryTools hangs off FeatureSource, and WfsV2AsyncLayer doesn’t have one.

  2. We only obsoleted it for WFS 2.0. WFS 1.0 and OGC API FeatureLayers are not deprecated. That’s exactly why your generic code works everywhere except WFS 2.0 — the inconsistency is ours.

What we’ll do

  1. Add an async FeatureSource (plus async feature layer and query surface) for the sources that talk over the network — giving the async model the same shape the sync one has.

  2. Then deprecate the sync network classes together — WFS 1.0, WFS 2.0, OGC API Features — pointing at a replacement that exists.

This will be added within a couple days. I’ll keep you posted

Thanks,
Ben

Hi,

Thanks for the explanation and for the upcoming changes.

Br, Simo

Hi Simo,

It’s fixed in 15.0.0-beta139 on NuGet.

Now there’s AsyncFeatureSource for each service:

var source = new WfsV2AsyncFeatureSource(url, "cp:CadastralParcel");
await source.OpenAsync();

await source.GetFeaturesInsideBoundingBoxAsync(extent, ct);                      // BBOX
await source.GetFeaturesPageAsync(extent, null, null, 1000, ct);                 // STARTINDEX/COUNT
await source.GetCountAsync(ct);                                                  // resultType=hits
await source.GetFeaturesByColumnValueAsync("municipality", "Helsinki", null, ct); // PropertyIsEqualTo
await source.GetFeaturesByIdsAsync(ids, null, ct);   / ResourceId

There is a new base layer: WebBasedAsyncFeatureLayer, and here are the old-new classes

Deprecated Use instead
WfsFeatureLayer / WfsFeatureSource WfsAsyncLayer / WfsAsyncFeatureSource
WfsV2FeatureLayer / WfsV2FeatureSource WfsV2AsyncLayer / WfsV2AsyncFeatureSource
OgcApiFeatureLayer / OgcApiFeatureSource OgcApiAsyncLayer / OgcApiAsyncFeatureSource

Let me know if you see any issues.

Thanks,
Ben

Hi,

Any change to support GetFeaturesWithinDistanceOf similar to QueryTools ? It has been handy to e.g get stuff near GPS location.

Of course there are lots of different APIs to query features in QueryTools which are now missing from WfsV2AsyncFeatureSource but that GetFeaturesWithinDistanceOf is something what we would need.

Br, Simo

Hi Simo,

They are now available in beta145:

// what you asked for
await source.GetFeaturesWithinDistanceOfAsync(gpsPoint, GeographyUnit.Meter, DistanceUnit.Meter, 500, ct);

// and the rest of the spatial predicates
await source.GetFeaturesIntersectingAsync(shape, ct);
await source.GetFeaturesContainingAsync(shape, ct);
await source.GetFeaturesCrossingAsync(shape, ct);
await source.GetFeaturesOverlappingAsync(shape, ct);
await source.GetFeaturesTouchingAsync(shape, ct);
await source.GetFeaturesWithinAsync(shape, ct);
await source.GetFeaturesTopologicalEqualAsync(shape, ct);

// nearest-N, within a radius you name
await source.GetFeaturesNearestToAsync(gpsPoint, GeographyUnit.Meter, 5, DistanceUnit.Meter, 1000, ct);

Each has the same four overloads QueryTools has — target as a BaseShape or a Feature, with or without a column list.

Two differences from the synchronous versions, both deliberate:

GetFeaturesNearestToAsync requires a search radius. Nearest-N over an unbounded area has no safe implementation against a service.

GetFeaturesDisjointed has no counterpart. It reads through “everything outside this box”, that cannot be done against a service.

Thanks,
Ben

1 Like

Hi,

How to use these new AsyncFeatureSource with GPU based rendering ? Examples in HowDol.15 are still using synchronous versions…

Br, Simo