query from Geometry

2653
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
18 Replies
RobertScheitlin__GISP
MVP Emeritus

That makes sense because the features var is an array of graphics.

Re-looking at your code  can you colsole.log(resultsLayer2.graphics) and make sure you have something there.

0 Kudos
jaykapalczynski
Frequent Contributor

0 Kudos
jaykapalczynski
Frequent Contributor

Both my datasets are Web Mercator Aux Sphere....

My map does not define a spatial reference....Could the Graphics be in a different projection and causing an issue?

0 Kudos
jaykapalczynski
Frequent Contributor

Looking at the console.log of the 1st Graphic Layer It appears to be in Web Mercator .... 

Spatial Reference: 102100 / 3857

Why the heck cant I use this to query another FC with geometry and write that to a graphic...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

  Put an else in here and see if you can get a clue as to what is going wrong.

queryCountiesthatIntersect().then(displayResults2).else(function(err){
  console.log(err)
});
0 Kudos
jaykapalczynski
Frequent Contributor

Dosent give me anything...Add alert in there "In the Intersect" to make sure it was in the function

Nothing in the Console Error wise...

queryCountiesthatIntersect().then(displayResults2).else(function (err) {
console.log(err);
});

function queryCountiesthatIntersect() {
         console.log("In the Intersect");
          console.log(resultsLayer2.graphics);

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Change.else to .catch

queryCountiesthatIntersect().then(displayResults2).catch(function (err) {
console.log(err);
});

0 Kudos
jaykapalczynski
Frequent Contributor

Thanks Robert Scheitlin, GISP‌ for steering me in the right direction......much appreciated.

0 Kudos
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

0 Kudos