query from Geometry

2658
18
Jump to solution
04-13-2020 10:33 AM
jaykapalczynski
Frequent Contributor
  1. I am quering a FC for a specific field value
  2. Returning the Feature and displaying it in a Graphic.  
  3. This works fine.
  4. I am  then attempting to do the same by calling another function to 
  5. Use the Geometry of the Graphic to select all the COunty Features that Intersect it...
  6. THis part if failing and I cant see why.

Both FC are Web Mercator Aux Sphere

The Map is defined as follows ---- I think this defaults to Web Mercator Web Aux?

        var mapright = new Map({
            basemap: "dark-gray",
            layers: [resultsLayer3, resultsLayer2, countyLayerWebMercator]
        });
        var viewright = new MapView({
            container: "viewDivright",
            map: mapright,
            center: [-77.05, 37.53308],
            zoom: 7
        });

PART ONE query, get geometry create Graphic

        function queryMultipartPolyongUniqueID3(feature) {
            var str = feature;
            var query = "";
            query = MultiPartPolygonsLayer.createQuery();
            query.where = "ADDRESSgeo  = '" + str + "'";
            return MultiPartPolygonsLayer.queryFeatures(query);
        }

// DISPLAY RESULTS IN GRAPHICS LAYER
        function displayResultsUniqueID(results) {

            resultsLayer2.removeAll();
            var features2 = results.features.map(function (graphic) {
                graphic.symbol = {
                    type: "simple-fill",
                    style: "solid",
                    color: [240, 248, 255, 0.9],
                    size: "10px", // pixels
                    outline: {
                        // autocasts as new SimpleLineSymbol()
                        color: [240, 248, 255, 0.9],
                        width: 1 // points
                    }
                };
                return graphic;
            });

            var numCounties2 = features2.length;
            resultsLayer2.addMany(features2);

            // CALL THE SECOND FUNCTION
            queryCountiesthatIntersect().then(displayResults2);
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

THEN Call the second function at the end ----

// CALL THE SECOND FUNCTION
queryCountiesthatIntersect().then(displayResults2);

1.  If I comment out the call to this 2nd function that code runs without error.

2.  If I run it with the call to the second function I get the below error.

ERROR

dojo.js:218 [esri.core.Accessor] Accessor#set Invalid property value, value needs to be one of 'esri.geometry.Extent', 'esri.geometry.Multipoint', 'esri.geometry.Point', 'esri.geometry.Polyline', 'esri.geometry.Polygon', or a plain object that can autocast (having .type = 'extent', 'multipoint', 'point', 'polyline', 'polygon')

QUESTIONS:

Am I getting this error because I am trying to use a Graphic Layer from the First Function Above?????

Can I use  graphic Layer?  If so do I need to define it differently?

Do I need to use a Feature Layer?

        function queryCountiesthatIntersect() {
            var query = countyLayerWebMercator.createQuery();
            query.geometry = resultsLayer2;
            query.spatialRelationship = "intersects";

            return countyLayerWebMercator.queryFeatures(query);
        }
        function displayResults2(results) {
            resultsLayer3.removeAll();
            var features3 = results.features.map(function (graphic) {
                graphic.symbol = {
                    type: "simple-fill",
                    style: "solid",
                    color: [240, 248, 255, 0.9],
                    size: "10px", // pixels
                    outline: {
                        // autocasts as new SimpleLineSymbol()
                        color: [191, 42, 18, 0.9],
                        width: 1 // points
                    }
                };
                return graphic;
            });
            var numCounties = features3.length;
            resultsLayer3.addMany(features3);
        }
0 Kudos
1 Solution

Accepted Solutions
jaykapalczynski
Frequent Contributor

I got it with this: i was missing the "items"

query.geometry = resultsLayer2.graphics.items[0].geometry; 

NOT

query.geometry = resultsLayer2.graphics[0].geometry; 

I had to walk the console.log of the Graphics layer a bit more

View solution in original post

0 Kudos
18 Replies
jaykapalczynski
Frequent Contributor

Funny thing is I get this error but the 2nd function still displays data but for some reason ALL of the County data....not the ones that are intersecting the Graphic Layer.  So I am assuming I might have to define the Geometry of the Graphic Layer?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

  The queries geometry property has to be a single geometry. You are currently attempting to pass a GraphicsLayer with possibly multiple graphics.

0 Kudos
jaykapalczynski
Frequent Contributor

query.geometry = resultsLayer2.geometry[0];  ????

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

query.geometry = resultsLayer2.graphics[0].geometry;

0 Kudos
jaykapalczynski
Frequent Contributor

Tried this and don't get to the second alert

function queryCountiesthatIntersect() {
   alert("1");
   var query = countyLayerWebMercator.createQuery();
   query.geometry = resultsLayer2.graphics[0].geometry;
   query.spatialRelationship = "intersects";
   alert("2");
   return countyLayerWebMercator.queryFeatures(query);
}

‍‍‍‍‍‍‍‍‍
0 Kudos
jaykapalczynski
Frequent Contributor

I changed the Graphic build to this as well

            resultsLayer2.add(features2);

NOT            

             resultsLayer2.addMany(features2);

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

 addmany would look like this. it is expecting an array.

resultsLayer2.addMany([features2]);

0 Kudos
jaykapalczynski
Frequent Contributor

This works fine and I get the 1st function to render the graphic layer properly

            resultsLayer2.addMany(features2);

This does NOT work...the graphic layer in the first function does not draw.

            resultsLayer2.addMany([features2]);

Still think there is an issue with this...when trying to use the geometry to find the counties that intersect the Graphic Layer 

written like this I get nothing

query.geometry = resultsLayer2.graphics[0].geometry;

written like this I get all 133 counties

query.geometry = resultsLayer2;

0 Kudos
jaykapalczynski
Frequent Contributor

I was using this ESRI Example:  ArcGIS API for JavaScript Sandbox 

towards the bottom

function displayResults(results) {
resultsLayer.removeAll();
var features = results.features.map(function(graphic) {
graphic.symbol = {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: "diamond",
size: 6.5,
color: "darkorange"
};
return graphic;
});
var numQuakes = features.length;
document.getElementById("results").innerHTML =
numQuakes + " earthquakes found";
resultsLayer.addMany(features);
}

0 Kudos