Select to view content in your preferred language

Valid geometry types for Query, Can input polygon have a hole in it?

1089
3
03-06-2013 05:06 AM
TracySchloss
Honored Contributor
I have a polygon layer I am using as a querytask based on regional boundaries.  The polygon layer is our state, cut into 5 large pieces.  The county where the state offices are is a region unto itself, called central, which is completely surrounded by northwest region.  I have verified that the northwest region does exclude this central region, so I would call this a polygon with a hole in it, or maybe a multipart polygon.

My problem is when I want to use the geometry of the northwest region polygon as input to a query and query task.  I'm first selecting the region from a pick list and determining the geometry.  This geometry is then used as input to a 2nd query task.

The callback function from the initial queryTask:
function showRegionResults (results) {
        region = results.features[0].geometry;
        map.setExtent(region.getExtent(), true);      
  findStaffInRegion(region);
    }


The 2nd query task which is populating a datagrid:

function findStaffInRegion(region) {
   var staffQueryTask = new esri.tasks.QueryTask(serverPathName + "/arcgis/rest/services/myService/MapServer/2"); //EUSstaff
   var staffQuery = new esri.tasks.Query;
   staffQuery.outFields = ["*"];
   if (region) {
   staffQuery.geometry = region;
   staffQuery.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
   staffQueryTask.execute(staffQuery);
   dojo.connect(staffQueryTask, "onComplete", function(results){
  var items = dojo.map(results.features, function(feature){
            return feature.attributes;
        });
        var data = {
                    identifier: "Contact_ContactId", //This field needs to have unique values
                    label: "ID", //Name field for display. Not pertinent to a grid but used elsewhere. 
                    items: items
                };
                //Create data store and bind to grid. 
                store = new dojo.data.ItemFileReadStore({
                    data: data
                });
                 var fp = dijit.byId('floater');
                        if (fp.style.visibility=="hidden") {
                            fp.style.visibility="";
                            fp.show();

                        }
                var staffGrid = dijit.byId('staffGrid');
                staffGrid.setStore(store);
                openFloatingPane();
       });
       }else{
           console.log("region variable not defined")
       }
}


This code works fine for all regions, except for the one that has the hole in it.  Is that type of polygon not a valid input geometry for a Query?  Am I misunderstanding what spatial relationship I should choose?  If I have to, I can run another function that excludes the features that are in the central region, but I'd rather not do that if I just have something wrong with this logic.
0 Kudos
3 Replies
JohnGravois
Deactivated User
check out the Buffer user-defined graphics sample, which uses the geometry service simplify() operation to break a polygon into legal, multipart features.
0 Kudos
TracySchloss
Honored Contributor
So my polygon with hole isn't going to be valid, but these are steps I can take to make it valid?  After I posted this,  I learned they are planning to redraw these boundaries so they don't look like this.
0 Kudos
JohnGravois
Deactivated User
i'm not sure whether your current geometry is valid or not.  i suggested testing the use of simplify() because it "guarantees" that the result geometry will be valid.
0 Kudos