Select to view content in your preferred language

get vertex of polygon from point

1008
2
08-10-2010 03:47 PM
LisaT
by
Frequent Contributor
Hi,
I have a line and am looking at using "replacePointCollection" to replace the points in a polygon with the line.  However, I need to get the index of the beginning vertex in order to do this.  I am currently getting the toPoint and FromPoint of the line and enumerating through the vertices to get the index number in the polygon.  However, this is taking a long time.  Isn't there a better way to do an intersect to get the points? 

My current code:
                                IPointCollection pPolyPntCollection = (IPointCollection)edgeFeature.ShapeCopy;
                                IEnumVertex enumVertex = pPolyPntCollection.EnumVertices;

                                for(int vIndex = 0; vIndex<pPolyPntCollection.PointCount;vIndex++)
                                {
                                enumVertex.Next(out pPoint, out outIndex, out verIndex);
                               // Debug.Print outIndex & " " & verIndex & " "; pPoint.x & " " & pPoint.y
                                    if (pPoint.Compare(toPnt) == 0)
                                        toIndex = verIndex;
                                    else if (pPoint.Compare(fromPnt) == 0)
                                        fromIndex = verIndex;
                                }

                                if ((toIndex>=0) && (fromIndex>=0))


As an alternative, anyone who has code for a quick replace of a portion of a polygon with a few line segments, I am all ears!
0 Kudos
2 Replies
JanDuske
Emerging Contributor
Have you tried the IHitTest Interface yet? Its only function would return the Vertex of the Polygon closest to a given Point. I don't know if it would be faster than your approach, but i guess if your polygons have a large ammount of vertices, it might be.
0 Kudos
LisaT
by
Frequent Contributor
EDIT:  Nevermind!  This worked, I was just using the wrong point to query (pqpt below).  Thanks for pointing me in the right direction...


I have been trying to work with HitTest, and cannot get it to return the vertex ID of the original polygon, which is what I need in order to use replacePointCollection.  It returns partIndex=0 and segmentIndex=0.  I this is the part and segment of the newly created pointcollection from which the hittest is querying, not the actual polygon vertex ID.  From what I can gather, you can derive a geometry location from HitTest, but not the ACTUAL geometry (vertex) of the polygon.  Am I doing something wrong?

IGeometryCollection pPolColl = (IGeometryCollection)edgeFeature.Shape;
                                IPolygon pPol = (IPolygon)pPolColl;
                                IHitTest pHitTest = (IHitTest)pPolColl;
                                IPoint pqpt = (IPoint)pPol.FromPoint;
                                double dr = 1;
                                double dht = 0;
                                int lPart = 0;
                                int lVertex = 0;
                                bool bright = false;
                                IPointCollection pPathColl;

                                ITransform2D pTrans2D;


                                IPoint pHit = new PointClass();
                                pHitTest.HitTest(pqpt, dr, esriGeometryHitPartType.esriGeometryPartVertex, pHit, ref dht, ref lPart, ref lVertex, ref bright);

    Debug.Print("Part:" + lPart.ToString() + "Seg:" + lVertex.ToString()); //returns:  0, 0
           pPathColl = (IPointCollection)pPolColl.get_Geometry(lPart);
                                //pTrans2D = pPathColl.get_Point(lVertex)
   Debug.Print("Vertex:" + pPathColl.get_Point(lVertex).get_VertexAttribute(esriGeometryAttributes.esriAttributeID));   //returns 0
0 Kudos