// create a geometry object var geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(1, 1), new Coordinate(2, 2) }); // create a const pointer to the geometry data var constPtr = new ConstPointer(geometry.Coordinates.UnsafePtr, geometry.Coordinates.Count); // access the underlying data using the const pointer var startPoint = constPtr[0]; var endPoint = constPtr[2];
// create a polygon object var polygon = new Polygon(new LinearRing(new[] { new Coordinate(0, 0), new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(1, 0), new Coordinate(0, 0) })); // create a const pointer to the polygon data var constPtr = new ConstPointerIn this example, a Polygon object is created with a single LinearRing shell that contains five coordinate points. A ConstPointer object is created to reference the coordinate data for the shell. The const pointer is used to loop through the coordinate points and print their X and Y values to the console. This example also uses the NetTopologySuite package library.(polygon.Shell.Coordinates.UnsafePtr, polygon.Shell.Coordinates.Count); // loop through the coordinate points using the const pointer for (var i = 0; i < polygon.Shell.Coordinates.Count; i++) { var point = constPtr[i]; Console.WriteLine($"Point {i}: ({point.X}, {point.Y})"); }