ArcRuntime QueryFeaturesAsync does not return M value

573
3
Jump to solution
09-03-2020 07:52 AM
KoryKarr
New Contributor

Hello,

I am using ArcRuntime 100.9.0 .NET sdk, and I'm querying a ServiceFeatureTable that contains polylines. The query works, but when I inspect the geometry of the feature, the M values are all NaN.  I know the feature does have M values by inspecting the same feature in ArcPro. Also, if I just use a browser to the go to the uri and query (i.e. http/{myserviceURI}/query) , I can set ReturnM to true, and see the M values in the geometry.

Code:

//Get layer and add to map...
Uri serviceUri = new Uri(/**uri string**/);
CenterlineLayer = new FeatureLayer(serviceUri);
_map.OperationalLayers.Add(CenterlineLayer);

...

//Query service 
QueryParameters queryParams = new QueryParameters();
 queryParams.WhereClause = "CENTERLINE_HISTORY_ID = 5";
 queryParams.ReturnGeometry = true;

FeatureQueryResult queryResult = await CenterlineLayer.FeatureTable.QueryFeaturesAsync(queryParams);

SelectedCenterline = queryResult.First();

//See screenshot to see NaN as the M Value

In a browser I can go to 

uri_string/query?where=CENTERLINE_HISTORY_ID+%3D+5&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRel...

 I get the M values:

{ ... "features": [ { "attributes": { "COMPANY_NAME": "HEC" }, "geometry": { "hasM": true, "paths": [ [ [ -10194353.727657143, 3462589.2523800787, 0 ], [ -10194351.748618515, 3462584.1271569589, 15.600000000005821 ], [ -10193529.228768408, 3460914.2605744163, 5303.8999999999942 ], [ -10191907.687540743, 3458520.5200898903, 13524.100000000006 ], [ -10191835.948896401, 3458416.2688311678, 13883.940000000002 ], .....}

Is there something I need to set on the QueryParameters? I explicitly set ReturnGeometry to true, although it looks like it defaults to true.

0 Kudos
1 Solution

Accepted Solutions
MichaelBranscomb
Esri Frequent Contributor

Hi,

To get the M values you can load the feature e.g.

var feature = polylinesQueryResult.First();
await (feature as ArcGISFeature).LoadAsync();‍‍‍‍

Or alternatively load all the features in one operation e.g.

await polylinesTable.LoadOrRefreshFeaturesAsync(polylinesQueryResult);

Thanks

Mike

View solution in original post

3 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

To get the M values you can load the feature e.g.

var feature = polylinesQueryResult.First();
await (feature as ArcGISFeature).LoadAsync();‍‍‍‍

Or alternatively load all the features in one operation e.g.

await polylinesTable.LoadOrRefreshFeaturesAsync(polylinesQueryResult);

Thanks

Mike

KoryKarr
New Contributor

Thank you! That fixed the issue.

0 Kudos
dotMorten_esri
Esri Frequent Contributor

You can also in the query itself specify to load it all:

FeatureQueryResult queryResult = await ((ServiceFeatureTable)CenterlineLayer.FeatureTable).QueryFeaturesAsync(queryParams, QueryFeatureFields.LoadAll);

One thing to note is that we only load the very minimum required to render the features. That might mean we drop Z and M values, as well as generalize geometry, and exclude attributes not needed for the renderer or labels. This improves query performance dramatically - however if you know you'll be needing all that info up-front, you might as well load it all up-front with the above code.

However if you query to display a set of features, and then want to "click" on one feature and get its details, it's more efficient to just query the bare minimum first, and then use the feature's LoadAsync() prior to displaying the details for that one feature.

A little more generic way to do this for any feature is using:

if(feature is ILoadable loadable)

     await loadable.LoadAsync();

0 Kudos