Select to view content in your preferred language

ArcGIS JS query from geometry

616
4
06-19-2023 02:09 AM
Wade
by
Occasional Contributor

I drew a range on the map, and used query to query which objects are in the geometry, but the result was not very accurate.

 

 

 

 

// evt.vertices draw-complete
let polygon = new Polygon({
                        type: "polygon",
                        rings: evt.vertices,
                        spatialReference: {
                            wkid: 3826
                        }
                    });

let drawExtent = new Graphic({
                    geometry: polygon,
                    symbol: {
                        type: "polygon-3d",
                        symbolLayers: [{
                            type: "fill",
                            material: {
                                color: [0, 0, 0, 0]
                            },
                            outline: {
                                color: "red",
                                width: 1
                            },
                        }]
                    }
                });


Promise.all(sceneView.map.allLayers.map(function (view) {
         if (view.type === "scene") {
                            const query = view.createQuery();
                            query.geometry = drawExtent.geometry;
                            query.spatialRelationship = "intersects";
                            query.returnGeometry = true;

                            return view.queryFeatures(query)
                                .then(function (result) {
                                    let queryResultLayer = [];

                                    if (result.features.length > 0) {
                                        result.features.forEach(function (item) {
                                           queryResultLayer.push(item.layer.title);
                                        });
                                    }
                                    return queryResultLayer;
                                });
                        }
                    }))
                        .then(function (results) {
                            // results
                        });
                });

 

 

 

0 Kudos
4 Replies
Sage_Wall
Esri Contributor

Hi @Wade , it looks like you are passing in a graphic as the `query.geometry` instead of a Geometry object (or one of it's subclasses.)

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-Query.html#geometry

0 Kudos
Wade
by
Occasional Contributor

Hi @Sage_Wall  
The above is just part of my program, when I query, I pass drawExtent.geometry.

0 Kudos
Sage_Wall
Esri Contributor

What is the geometry you are passing into the query?  Does it have a spatial reference defined? Would it be possible to create a codepen or provide a complete example showing how the expected results differ from the query result?

0 Kudos
Wade
by
Occasional Contributor

The code update, polygons are generated after my drawing is done, Mainly drawing objects in range queries.

Excuse me, the query range is XYmin XYmax, not the range of 3D objects, so it will be inaccurate?

0 Kudos