1 /// <summary>2 ///gets the polygon based on the ID of the polygon feature and determines whether the point is within the polygon3 /// </summary>4 /// <param name= "point" >to judge the point, the beginning of the Ray</param>5 /// <param name= "ID" >ID of the polygon</param>6 /// <param name= "Pfeaturelayer" >layer where polygon features are located</param>7 /// <returns></returns>8 Private BOOLPointisinpolygon (IPoint Point,intID, Ifeaturelayer pfeaturelayer)9 {TenIfeatureclass Pfeatureclass =Pfeaturelayer.featureclass; OneIpolygon Ppolygon = (pfeatureclass.getfeature (ID)). Shape asIpolygon; A //comparison to the maximum minimum xy value of a polygon -Ienvelope Penvelope =NewEnvelopeclass (); -Penvelope =Ppolygon.envelope; the if(Point. x<penvelope.xmin| | Point. x>penvelope.xmax| | Point. y<penvelope.ymin| | Point. Y>Penvelope.ymax) - return false; - //If, in this range, the left is the ray, determine the number of intersections according to the topology of the line and Polygon - Try { +IPoint Topoint =NewPointclass (); -Topoint.putcoords (Getxminvalue (Ppolygon)-20.00000000, point. Y); +Ipolyline PLine =NewPolylineclass ();//define Ray APline.topoint =Topoint; atPline.frompoint =Point ; - -Itopologicaloperator Ptopo = Ppolygon asItopologicaloperator; -Igeometrycollection Pgeocol = Ptopo.intersect ((igeometry) pLine, esrigeometrydimension.esrigeometry0dimension) asigeometrycollection; -Ipointcollection Ppointcol = Pgeocol asipointcollection; - if((ppointcol.pointcount)%2==0) in { - return false; to } + Else - { the return true; * } $ Panax Notoginseng } - Catch(Exception ee) the { + MessageBox.Show (EE. Message); A return false; the } + } - /// <summary> $ ///gets the X minimum value of the polygon $ /// </summary> - /// <param name= "Ppolygon" ></param> - /// <returns></returns> the Private DoubleGetxminvalue (Ipolygon ppolygon) - {WuyiIpointcollection ppointcollection = Ppolygon asipointcollection; the intn =Ppointcollection.pointcount; - Double[] Coordx =New Double[n]; Wu for(inti =0; I < n; i++) - { AboutIPoint point =Ppointcollection.get_point (i); $Coordx[i] =Point . X; - } - System.Array.Sort (COORDX); - returncoordx[0]; A}
AE Determines whether the point is inside the polygon