Determine if a point lies inside a polygon

10493
3
02-04-2015 09:06 AM
EdwardSohn2
New Contributor III

Is there an API available for determining if a point lies inside a polygon geometry determined by a  ring?

To do so for a rectangle is simple, but for a ring of points which determines a polygon, what is the best way?

Thanks.

0 Kudos
3 Replies
RandyBonds_Jr_
Occasional Contributor

I use this to see in my app if a point is in City Limits (a polygon)

yakimaCL = new esri.layers.FeatureLayer("http://gis.yakimawa.gov/arcgis101/rest/services/General/YakimaLayers/MapServer/9", {

          mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,

          outFields: ["*"],

   opacity: .4

        });

//the point

var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(candidate.location.x.toFixed(6),candidate.location.y.toFixed(6)));

  // Check to see if the point is in the  City Limits

  var isYakima = yakimaCL.graphics[0].geometry.contains(pt);

KellyHutchins
Esri Frequent Contributor

Randy's approach of using geometry.contains is a great one. Here's another option that uses the Geometry Service.

Point in polygon search | ArcGIS API for JavaScript

JakeSkinner
Esri Esteemed Contributor

Hi Edward,

You could create a Polygon from the points XY coordinates, and then use the Polygon to determine if it contains the point.

0 Kudos