Select to view content in your preferred language

Query same layer w/ overlapping polygons

1311
4
01-07-2011 11:00 AM
TrentReeder
Frequent Contributor
Hello,

Curious if the Query Task will return overlapping polygons in the same feature layer?  I know the Identify Task will do this, but I am working with data that contain relationship classes to SDE tables.  From what I've read, the Identify Task is not able to reveal related data, unless I am mistaken.

What I am trying to do is select features using a box and returning related attributes to a DataGrid table.  So far, I've only been able to pass the top most polygon within the same feature layer and not any underlying polgyons.

Your help and suggestions are greatly appreciated!

Trent
0 Kudos
4 Replies
HemingZhu
Frequent Contributor
Hello,

Curious if the Query Task will return overlapping polygons in the same feature layer?  I know the Identify Task will do this, but I am working with data that contain relationship classes to SDE tables.  From what I've read, the Identify Task is not able to reveal related data, unless I am mistaken.

What I am trying to do is select features using a box and returning related attributes to a DataGrid table.  So far, I've only been able to pass the top most polygon within the same feature layer and not any underlying polgyons.

Your help and suggestions are greatly appreciated!

Trent


The featureSet from the query task results should contain all the features(featureSet.features) that meet your query parameters. You just have to loop through the featureSet.features to get all the features.
0 Kudos
TrentReeder
Frequent Contributor
Thanks for your suggestion.

I have combined the "Select Features" and "Query Related Records" examples for my test web application.  I am a little confused in where I should put the loop featureSet.features code.  Using a function calling esri.toolbars.Draw(map) to draw my selection rectangle, would I add the loop code to this function?  Or add the loop code to the function calling a esri.tasks.RelationshipQuery()?

Here's my code below:

<script type="text/javascript">
        dojo.require("esri.map");
        dojo.require("esri.layers.FeatureLayer");
        dojo.require("esri.tasks.query");
        dojo.require("dojox.grid.DataGrid");
        dojo.require("dojo.data.ItemFileReadStore");
        dojo.require("dijit.layout.BorderContainer");
        dojo.require("dijit.layout.ContentPane");
        
        var selectionToolbar, featureLayer, grid, store, selectionLayer;

        function init() {

            var initialExtent = new esri.geometry.Extent({ "xmin": -107.75, "ymin": 30, "xmax": -105, "ymax": 40, "spatialReference": { "wkid": 4269} });
            var map = new esri.Map("map", { extent: esri.geometry.geographicToWebMercator(initialExtent), slider: true, nav: true });
            map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));

            var imageParams = new esri.layers.ImageParameters();
            imageParams.layerIds = [0];
            imageParams.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
            var dynamicLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gis1ace/ArcGIS10/rest/services/MRG_select_box_test/MapServer", { imageParameters: imageParams });
            map.addLayer(dynamicLayer);            

            var selectionLayer = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255, 255, 0, 0.5]));
            selectionLayer.setOutline(new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255, 0, 0]), 2));
            
            var content = "<b>Feature ID</b>: ${FeatureID}";
            var infoTemplate = new esri.InfoTemplate("${FeatureID}", content);

            featureLayer = new esri.layers.FeatureLayer("http://gis1ace/ArcGIS10/rest/services/MRG_select_box_test/MapServer/0", {
                mode: esri.layers.FeatureLayer.MODE_SELECTION,
                infoTemplate: infoTemplate,
                outFields: ["*"]
            });
            featureLayer.setSelectionSymbol(selectionLayer);

            map.addLayer(featureLayer);

            dojo.connect(map, "onLoad", initSelectToolbar)
               
            dojo.connect(featureLayer, "onSelectionComplete", findRelatedRecords);

        }

        function initSelectToolbar(map) {
            selectionToolbar = new esri.toolbars.Draw(map);
            var selectQuery = new esri.tasks.Query();
            dojo.connect(selectionToolbar, "onDrawEnd", function (geometry) {
                selectionToolbar.deactivate();
                selectQuery.geometry = geometry;
                featureLayer.selectFeatures(selectQuery, esri.layers.FeatureLayer.SELECTION_NEW);
            });
        }

        for (var i = 0, il = featureSet.features.length; i < il; i++) {
        //Get the current feature from the featureSet.
         var graphic = featureSet.features;



        //Relationship query
        function findRelatedRecords(features) {
            var relatedDocQuery = new esri.tasks.RelationshipQuery();
            relatedDocQuery.outFields = ["*"];
            relatedDocQuery.relationshipId = 1;
            relatedDocQuery.objectIds = [features[0].attributes.OBJECTID];
            featureLayer.queryRelatedFeatures(relatedDocQuery, function (relatedRecords) {
                var fset = relatedRecords[features[0].attributes.OBJECTID];
                var items = dojo.map(fset.features, function (feature) {
                    return feature.attributes;
                });

                //Create data object to be used in store
                var data = {
                    identifier: "OBJECTID",  //This field needs to have unique values
                    label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
                    items: items
                };

                //Create data store and bind to grid.
                store = new dojo.data.ItemFileReadStore({ data: data });
                grid.setStore(store);
                grid.setQuery({ OBJECTID: '*' });
                });
        }
       dojo.addOnLoad(init);
  </script>


Thanks for your help again!

Trent
0 Kudos
TrentReeder
Frequent Contributor
I am still having a rather difficult time in my efforts to show related data on the dataGrid from a selection box querying overlapping/multiple polygons. I have tried modifying the code many times from other samples to loop through the features, but to no avail.

Are there any example maps or code out there that would point me in the right direction?

Thanks for time!

Trent
0 Kudos
TrentReeder
Frequent Contributor
Ok, last post for this thread as I will be creating a new thread for another, semi related, question.  To follow up this thread though, I was able to figure out that the overlapping polygons were being selected originally and returning values from the polygons underneath. I just created a simple map without the relationshipQuery task for which revealed that the selection function does select multiple/overlapping features.

It seems the way I have the relationshipQuery task scripted, the task is not returning the related values of multiple features.  Here's the link to the new thread http://forums.arcgis.com/threads/21911-relationshipQuery-not-returning-multiple-related-overlapping-...

Thanks for the help!

Trent
0 Kudos