4

Say I have an ArcGIS Server GeometryService running, and a map service containing ZIP code polygons (all ArcGIS 10.1).

I want to pass a coordinate, and have it return which ZIP code contains that coordinate. There seem to be many ways to approach "does THIS point fall within THIS polygon?", but how would I find out which polygon among them all contains a point?

In other words, there's this example where, given two points and a polygon, it will return which of the points is contained by the polygon. But what if you only know the point, and the objective is to determine which polygon?

2
4

It looks like either the Query or the Identify tasks will do the trick.

I successfully adapted this sample to prototype this functionality using the ArcGIS JavaScript API:

 var qt1="http://localhost:6080/arcgis/rest/services/simple_ny_outline/MapServer/0"
    var queryTask = new esri.tasks.QueryTask(qt1);
    var query = new esri.tasks.Query();
    query.returnGeometry = true;
    query.outFields = ["*"];
    query.outSpatialReference = {"wkid":26918};


    var currentClick = null;
    dojo.connect(map, "onClick", function(evt) {
      map.graphics.clear();
      currentClick = query.geometry = evt.mapPoint;
      query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
      queryTask.execute(query);
      dojo.byId('messages').innerHTML = "<b>Executing Point Intersection Query...</b>";
    });

    var firstGraphic = null;

    dojo.connect(queryTask, "onComplete", function(graphics) {
      firstGraphic = graphics.features[0];

      console.log(firstGraphic.attributes.COUNTY);
      dojo.byId('messages').innerHTML = "<b>" + firstGraphic.attributes.COUNTY +"</b>";
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.