Query Extent

2747
5
10-23-2015 07:42 AM
MarkCederholm
Occasional Contributor III

Is there a way in .NET that I can use a QueryTask to executeForExtent as in the JavaScript API?

0 Kudos
5 Replies
ChrisSmith7
Frequent Contributor

Looking at the API documentation, I don't see it as a listed method:

QueryTask Class

0 Kudos
ChrisSmith7
Frequent Contributor

That being said, though, I wonder if you could get the extent from the query FeatureSet...

FeatureSet Class

I didn't see an extent property, however, so you may need some code to get the extent.

0 Kudos
ThadTilton
Esri Contributor

Hi Mark -

You can achieve the same result with a few extra lines of code. The example below will loop thru the results of a query and union the extents of all features to build the overall extent:

Envelope resultExtent = null;

var filter = new Query("areaname LIKE '%red%'");

var queryTask = new QueryTask(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"));

var results = await queryTask.ExecuteAsync(filter);

var resultCount = results.FeatureSet.Features.Count;

foreach (var f in results.FeatureSet.Features)

{

    var ext = f.Geometry.Extent;

    if (resultExtent == null)

    {

        resultExtent = ext;

    }

    else

    {

        resultExtent = resultExtent.Union(ext);

    }              

}

MyMapView.SetViewAsync(resultExtent);

ChrisSmith7
Frequent Contributor

Cool, I was thinking we may need to do something like this!

0 Kudos
MarkCederholm
Occasional Contributor III

I'm trying to avoid unnecessary network traffic.  It turns out, however, that in the REST API the returnExtentOnly option is only available on feature service layers.  Hopefully that will change in the next version of Server.

0 Kudos