0

I'm trying to get the geometry in an array from a queryTask using the Esri JavaScript API v4.7. I'm sure I'm missing something but I dont know what. I want to take geometry from this to then create a new record in another service.

require([
"esri/tasks/QueryTask", 
"esri/tasks/support/Query"
], 
function(
QueryTask, 
Query
){
 var LayerUrl = "https://services8.arcgis.com/R1PAHHLiCM5plgJt/arcgis/rest/services/MICC_Planning/FeatureServer/0";
 var queryTask = new QueryTask({
 url: LayerUrl
 });
 var lotp="15MPH7941";
 var q="Lotplan LIKE '"+lotp+"'";
 var query = new Query();
 query.returnGeometry = true;
 query.outFields = ["*"];
 query.where = q;
 queryTask.execute(query).then(function(results){
 console.log(4); 
 window.alert(results.features.geometry);
 });
 // When resolved, returns a count of the features that satisfy the query.
 queryTask.executeForCount(query).then(function(results){
 console.log(results);
 });
});
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked May 21, 2018 at 8:48

1 Answer 1

1

Your code is ok, the problem is that the QueryTask returns a result object, that contains a FeatureSet (which is an array of features). Then if you would like to get the first feature, you have to use results.features[0]

So instead of window.alert(results.features.geometry); you have to get the geometry from every result feature:

results.features.forEach(function (feature)
 window.alert(feature.geometry);
});

I have created a jsbin that you can check if you want.

answered May 21, 2018 at 12:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.