Select to view content in your preferred language

Add Vertex to Polygon

289
4
10-01-2024 06:20 AM
sonj
by
Occasional Contributor

To add a vertex to the polygon, we are creating an application. After a few runs, the application displays the error message "Attempt to read and write protected memory."

download.png

IHitTest hitTest = polygon.ShapeCopy as IHitTest;
bool result = hitTest.HitTest(, searchRadius, esriGeometryHitPartType.esriGeometryPartBoundary, hitPoint, ref hitDist, ref hitPartIndex, ref hitSegmentIndex, ref bTrue);
 
if (result)
{
IGeometryCollection geometryCol = polygon.ShapeCopy as IGeometryCollection;
IPointCollection pathOrRingPointCollection = geometryCol.get_Geometry(hitPartIndex) as IPointCollection;
 
object hitSegmentIndexObject = new object();
hitSegmentIndexObject = hitSegmentIndex;
 
object partIndexObject = new object();
partIndexObject = hitPartIndex;
 
if(hitSegmentIndex == 0)
{
pathOrRingPointCollection.AddPoint(point, 1, Type.Missing);
}
else if(hitSegmentIndex > 0)
{
pathOrRingPointCollection.AddPoint(point, Type.Missing, hitSegmentIndexObject);
}
 
 
 
//remove the old PointCollection from the GeometryCollection and replace with the new one
geometryCol.RemoveGeometries(hitPartIndex, 1);
geometryCol.AddGeometry(pathOrRingPointCollection as IGeometry, ref partIndexObject, Type.Missing);
 
polygon.Shape = geometryCol as IGeometry;
invalidArea.Invalidate(2);
polygon.Store();
 
}
 
Any recommendations or an alternative interface would be much appreciated.
0 Kudos
4 Replies
sonj
by
Occasional Contributor

Is anyone here to help 🤔

0 Kudos
DuncanHornby
MVP Notable Contributor

I'm surprised the HitTest() even works as the help file indicates the first parameter is a point object which in your code you don't supply?

0 Kudos
sonj
by
Occasional Contributor

I apologize; it was overlooked during copy and paste. Points are collected throughout the process, and each repetition will send a point. The polygon vertex count is approximately 8 to 9 million.

0 Kudos
DuncanHornby
MVP Notable Contributor

Sorry are you saying you are trying to insert a vertex into a polygon that is composed of 8 million vertices? I would imagine any sort of spatial processing would be quite slow and you would need to dice up your data?

0 Kudos