Select to view content in your preferred language

Select features within selected polygon(s) not working

1788
3
Jump to solution
09-29-2014 07:31 AM
RyanSellman
Deactivated User

I am working on a sample that performs an attribute query on one layer and uses the results as geometry for a second query, which does a spatial intersect on another layer.  The first query works just fine but the second does not.  I get no errors in the console and when looking at the network traffic, the second query doesn't appear to be firing.  Can someone take a look at this and help?  Thanks in advance!!

Here's the fiddle!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ryan,

  Here is your sample with the results of the first query being unioned before the second query is executed. You may want to add some indication to the user that the union operation is occurring.

<!DOCTYPE html>

<html>

<head>

    <title>Spatial Query</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css">

    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">

    <style>

        html,

        body,

        #mapDiv {

            padding: 0;

            margin: 0;

            height: 100%;

        }

    </style>

    <script src="http://js.arcgis.com/3.10/"></script>

    <script>

        var map;

        require([

                "dojo/parser",

                "esri/geometry/Extent",

                "esri/graphicsUtils",

                "esri/SpatialReference",

                "dojo/on", "dojo/dom",

                "dijit/registry",

                "esri/tasks/FindTask",

                "esri/tasks/QueryTask",

                "esri/tasks/GeometryService",

                "esri/graphicsUtils",

                "esri/tasks/FindParameters",

                "esri/map",

                "esri/layers/ArcGISDynamicMapServiceLayer",

                "esri/InfoTemplate",

                "dojo/dom-construct",

                "esri/dijit/Popup",

                "esri/tasks/IdentifyTask",

                "esri/tasks/IdentifyResult",

                "esri/tasks/IdentifyParameters",

                "esri/dijit/InfoWindow",

                "esri/dijit/HomeButton",

                "esri/layers/FeatureLayer",

                "esri/toolbars/navigation",

                "esri/dijit/Legend",

                "esri/dijit/Print",

                "esri/dijit/BasemapToggle",

                "dojo/_base/array",

                "dijit/form/CheckBox",

                "dijit/form/NumberTextBox",

                "esri/dijit/BasemapGallery",

                "esri/dijit/Geocoder",

                "dojo/_base/Color",

                "esri/graphic",

                "esri/tasks/Geoprocessor",

                "esri/symbols/SimpleMarkerSymbol",

                "esri/geometry/screenUtils",

                "esri/dijit/Measurement",

                "esri/dijit/OverviewMap",

                "esri/dijit/Bookmarks",

                "esri/dijit/BasemapLayer",

                "esri/dijit/Basemap",

                "esri/dijit/BookmarkItem",

                "esri/units",

                "esri/geometry/Geometry",

                "esri/geometry/Point",

                "esri/geometry/Polyline",

                "esri/geometry/Polygon",

                "esri/dijit/Scalebar",

                "esri/dijit/AttributeInspector",

                "esri/symbols/SimpleLineSymbol",

                "dojo/query",

                "esri/symbols/SimpleFillSymbol",

                "esri/layers/ArcGISTiledMapServiceLayer",

                "esri/layers/ImageParameters",

                "esri/config",

                "esri/tasks/query",

                "esri/symbols/TextSymbol",

                "esri/renderers/SimpleRenderer",

                "esri/layers/LabelLayer",

                "dijit/form/Button",

                "dijit/form/ComboBox",

                "dijit/Dialog",

                "esri/toolbars/draw",

                "dijit/layout/BorderContainer",

                "esri/tasks/GeometryService",

                "dijit/layout/ContentPane",

                "dijit/layout/AccordionContainer",

                "dijit/layout/TabContainer",

                "dijit/layout/SplitContainer",

                "dojox/layout/ExpandoPane",

                "dojox/grid/DataGrid",

                "dojo/data/ItemFileReadStore",

                "dojo/domReady!"

            ],

            function(

                parser,

                Extent,

                graphicsUtils,

                SpatialReference,

                on,

                dom,

                registry,

                FindTask,

                QueryTask,

                GeometryService,

                graphicsUtils,

                FindParameters,

                Map,

                ArcGISDynamicMapServiceLayer,

                InfoTemplate,

                domConstruct,

                Popup,

                IdentifyTask,

                IdentifyResult,

                IdentifyParameters,

                InfoWindow,

                HomeButton,

                FeatureLayer,

                Navigation,

                Legend,

                Print,

                BasemapToggle,

                arrayUtils,

                CheckBox,

                NumberTextBox,

                BasemapGallery,

                Geocoder,

                Color,

                Graphic,

                Geoprocessor,

                SimpleMarkerSymbol,

                screenUtils,

                Measurement,

                OverviewMap,

                Bookmarks,

                BasemapLayer,

                Basemap,

                BookmarkItem,

                Units,

                Geometry,

                Point,

                Polyline,

                Polygon,

                Scalebar,

                AttributeInspector,

                SimpleLineSymbol,

                query,

                SimpleFillSymbol,

                ArcGISTiledMapServiceLayer,

                ImageParameters,

                esriConfig,

                Query,

                TextSymbol,

                SimpleRenderer,

                LabelLayer,

                Button,

                ComboBox,

                Dialog,

                Draw,

                BorderContainer,

                GeometryService,

                ContentPane,

                AccordionContainer,

                TabContainer,

                SplitContainer,

                ExpandoPane,

                DataGrid,

                ItemFileReadStore

            ) {

                parser.parse()

                var twpQueryGraphic;

                map = new Map("mapDiv", {

                    center: [-81.646017, 41.100609],

                    zoom: 10,

                    basemap: "streets",

                });

                var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES_Mercator/MapServer");

                map.addLayer(layer);

                var twpQueryTask = new QueryTask("http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES_Mercator/MapServer/12");

                //build query filter

                var query = new Query();

                query.returnGeometry = true;

                query.where = "TYPE = 'TOWNSHIP'";

                query.outFields = ["*"];

                twpQueryTask.execute(query, function(featureSet) {

                    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100, 100, 100]), 2), new dojo.Color([0, 0, 255, 0.20]));

                    for (var i = 0, il = featureSet.features.length; i < il; i++) {

                        //Get the current feature from the featureSet. 

                        //Feature is a graphic 

                        var graphic = featureSet.features;

                        graphic.setSymbol(symbol);

                        map.graphics.add(graphic);

                    }

                    var geomServ = new GeometryService("http://summitgis.summitoh.net:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");

                    geomServ.union(graphicsUtils.getGeometries(featureSet.features),function(geom){

                      var plantQueryTask = new esri.tasks.QueryTask("http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES_Mercator/MapServer/8");

                      var query2 = new esri.tasks.Query();

                      query2.returnGeometry = true;

                      query2.geometry = geom;

                      query2.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;

                      plantQueryTask.execute(query2, showQueryTask2Result);

                      function showQueryTask2Result(featureSet2) {

                          console.log(featureSet2.features.length)

                          var symbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color("red"));

                          var resultFeatures = featureSet2.features;

                          for (var i = 0, il = featureSet2.features.length; i < il; i++) {

                              //Get the current feature from the featureSet. 

                              //Feature is a graphic 

                              var graphic = featureSet2.features;

                              graphic.setSymbol(symbol);

                              map.graphics.add(graphic);

                          }

                      }

                    }, function(error){})

                   

                });

            });

    </script>

</head>

<body class="claro">

    <div id="mapDiv"></div>

</body>

</html>

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Ryan,

   Feature 0 of the first queries FeatureSet does not seem to have an intersecting point in your second query. If I change it to twpQueryGraphic = featureSet.features[5]; then I do get a point in the second query.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ryan,

  Here is your sample with the results of the first query being unioned before the second query is executed. You may want to add some indication to the user that the union operation is occurring.

<!DOCTYPE html>

<html>

<head>

    <title>Spatial Query</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css">

    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">

    <style>

        html,

        body,

        #mapDiv {

            padding: 0;

            margin: 0;

            height: 100%;

        }

    </style>

    <script src="http://js.arcgis.com/3.10/"></script>

    <script>

        var map;

        require([

                "dojo/parser",

                "esri/geometry/Extent",

                "esri/graphicsUtils",

                "esri/SpatialReference",

                "dojo/on", "dojo/dom",

                "dijit/registry",

                "esri/tasks/FindTask",

                "esri/tasks/QueryTask",

                "esri/tasks/GeometryService",

                "esri/graphicsUtils",

                "esri/tasks/FindParameters",

                "esri/map",

                "esri/layers/ArcGISDynamicMapServiceLayer",

                "esri/InfoTemplate",

                "dojo/dom-construct",

                "esri/dijit/Popup",

                "esri/tasks/IdentifyTask",

                "esri/tasks/IdentifyResult",

                "esri/tasks/IdentifyParameters",

                "esri/dijit/InfoWindow",

                "esri/dijit/HomeButton",

                "esri/layers/FeatureLayer",

                "esri/toolbars/navigation",

                "esri/dijit/Legend",

                "esri/dijit/Print",

                "esri/dijit/BasemapToggle",

                "dojo/_base/array",

                "dijit/form/CheckBox",

                "dijit/form/NumberTextBox",

                "esri/dijit/BasemapGallery",

                "esri/dijit/Geocoder",

                "dojo/_base/Color",

                "esri/graphic",

                "esri/tasks/Geoprocessor",

                "esri/symbols/SimpleMarkerSymbol",

                "esri/geometry/screenUtils",

                "esri/dijit/Measurement",

                "esri/dijit/OverviewMap",

                "esri/dijit/Bookmarks",

                "esri/dijit/BasemapLayer",

                "esri/dijit/Basemap",

                "esri/dijit/BookmarkItem",

                "esri/units",

                "esri/geometry/Geometry",

                "esri/geometry/Point",

                "esri/geometry/Polyline",

                "esri/geometry/Polygon",

                "esri/dijit/Scalebar",

                "esri/dijit/AttributeInspector",

                "esri/symbols/SimpleLineSymbol",

                "dojo/query",

                "esri/symbols/SimpleFillSymbol",

                "esri/layers/ArcGISTiledMapServiceLayer",

                "esri/layers/ImageParameters",

                "esri/config",

                "esri/tasks/query",

                "esri/symbols/TextSymbol",

                "esri/renderers/SimpleRenderer",

                "esri/layers/LabelLayer",

                "dijit/form/Button",

                "dijit/form/ComboBox",

                "dijit/Dialog",

                "esri/toolbars/draw",

                "dijit/layout/BorderContainer",

                "esri/tasks/GeometryService",

                "dijit/layout/ContentPane",

                "dijit/layout/AccordionContainer",

                "dijit/layout/TabContainer",

                "dijit/layout/SplitContainer",

                "dojox/layout/ExpandoPane",

                "dojox/grid/DataGrid",

                "dojo/data/ItemFileReadStore",

                "dojo/domReady!"

            ],

            function(

                parser,

                Extent,

                graphicsUtils,

                SpatialReference,

                on,

                dom,

                registry,

                FindTask,

                QueryTask,

                GeometryService,

                graphicsUtils,

                FindParameters,

                Map,

                ArcGISDynamicMapServiceLayer,

                InfoTemplate,

                domConstruct,

                Popup,

                IdentifyTask,

                IdentifyResult,

                IdentifyParameters,

                InfoWindow,

                HomeButton,

                FeatureLayer,

                Navigation,

                Legend,

                Print,

                BasemapToggle,

                arrayUtils,

                CheckBox,

                NumberTextBox,

                BasemapGallery,

                Geocoder,

                Color,

                Graphic,

                Geoprocessor,

                SimpleMarkerSymbol,

                screenUtils,

                Measurement,

                OverviewMap,

                Bookmarks,

                BasemapLayer,

                Basemap,

                BookmarkItem,

                Units,

                Geometry,

                Point,

                Polyline,

                Polygon,

                Scalebar,

                AttributeInspector,

                SimpleLineSymbol,

                query,

                SimpleFillSymbol,

                ArcGISTiledMapServiceLayer,

                ImageParameters,

                esriConfig,

                Query,

                TextSymbol,

                SimpleRenderer,

                LabelLayer,

                Button,

                ComboBox,

                Dialog,

                Draw,

                BorderContainer,

                GeometryService,

                ContentPane,

                AccordionContainer,

                TabContainer,

                SplitContainer,

                ExpandoPane,

                DataGrid,

                ItemFileReadStore

            ) {

                parser.parse()

                var twpQueryGraphic;

                map = new Map("mapDiv", {

                    center: [-81.646017, 41.100609],

                    zoom: 10,

                    basemap: "streets",

                });

                var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES_Mercator/MapServer");

                map.addLayer(layer);

                var twpQueryTask = new QueryTask("http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES_Mercator/MapServer/12");

                //build query filter

                var query = new Query();

                query.returnGeometry = true;

                query.where = "TYPE = 'TOWNSHIP'";

                query.outFields = ["*"];

                twpQueryTask.execute(query, function(featureSet) {

                    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100, 100, 100]), 2), new dojo.Color([0, 0, 255, 0.20]));

                    for (var i = 0, il = featureSet.features.length; i < il; i++) {

                        //Get the current feature from the featureSet. 

                        //Feature is a graphic 

                        var graphic = featureSet.features;

                        graphic.setSymbol(symbol);

                        map.graphics.add(graphic);

                    }

                    var geomServ = new GeometryService("http://summitgis.summitoh.net:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");

                    geomServ.union(graphicsUtils.getGeometries(featureSet.features),function(geom){

                      var plantQueryTask = new esri.tasks.QueryTask("http://summitgis.summitoh.net:6080/arcgis/rest/services/DOES_Mercator/MapServer/8");

                      var query2 = new esri.tasks.Query();

                      query2.returnGeometry = true;

                      query2.geometry = geom;

                      query2.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;

                      plantQueryTask.execute(query2, showQueryTask2Result);

                      function showQueryTask2Result(featureSet2) {

                          console.log(featureSet2.features.length)

                          var symbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color("red"));

                          var resultFeatures = featureSet2.features;

                          for (var i = 0, il = featureSet2.features.length; i < il; i++) {

                              //Get the current feature from the featureSet. 

                              //Feature is a graphic 

                              var graphic = featureSet2.features;

                              graphic.setSymbol(symbol);

                              map.graphics.add(graphic);

                          }

                      }

                    }, function(error){})

                   

                });

            });

    </script>

</head>

<body class="claro">

    <div id="mapDiv"></div>

</body>

</html>

0 Kudos
RyanSellman
Deactivated User

Robert,

Thanks so much for the response.  With your adjustments, the sample seems to be working like I want it to.

I appreciate your help!!

Ryan

0 Kudos