Skip to content

Instantly share code, notes, and snippets.

@blah238
Last active December 12, 2015 02:49
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save blah238/4702432 to your computer and use it in GitHub Desktop.
LINQPad IGeometryBridge.QueryPoints() example
<Query Kind="Program">
<Reference>&lt;ProgramFilesX86&gt;\ArcGIS\DeveloperKit10.1\DotNet\ESRI.ArcGIS.Geometry.dll</Reference>
<Reference>&lt;ProgramFilesX86&gt;\ArcGIS\DeveloperKit10.1\DotNet\ESRI.ArcGIS.System.dll</Reference>
<Reference>&lt;ProgramFilesX86&gt;\ArcGIS\DeveloperKit10.1\DotNet\ESRI.ArcGIS.Version.dll</Reference>
<Namespace>ESRI.ArcGIS.Geometry</Namespace>
<Namespace>ESRI.ArcGIS.esriSystem</Namespace>
</Query>
void Main()
{
if (ESRI.ArcGIS.RuntimeManager.ActiveRuntime == null)
ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
var polygon = CreatePolygonByPoints();
polygon.GetVertices2().Dump();
}
internal static class ExtensionMethods
{
internal static IPoint[] GetVertices2(this IPolygon singlepartPolygon)
{
var pointCollection = (IPointCollection4)singlepartPolygon;
var points = new IPoint[pointCollection.PointCount];
for (int i = 0; i < points.Length; i++)
{
points[i] = new PointClass();
}
var geometryBridge = (IGeometryBridge)new GeometryEnvironmentClass();
geometryBridge.QueryPoints(pointCollection, 0, ref points);
return points;
}
internal static IPoint[] GetVertices(this IPolygon singlepartPolygon)
{
var pointCollection = (IPointCollection4)singlepartPolygon;
var points = new IPoint[pointCollection.PointCount];
var geometryBridge = (IGeometryBridge2)new GeometryEnvironmentClass();
geometryBridge.GetPoints(pointCollection, 0, ref points);
return points;
}
}
private static IPolygon CreatePolygonByPoints()
{
IGeometryBridge2 geometryBridge2 = new GeometryEnvironmentClass();
IPointCollection4 pointCollection4 = new PolygonClass();
var aWKSPointBuffer = new WKSPoint[5];
aWKSPointBuffer[0].X = 0;
aWKSPointBuffer[0].Y = 0;
aWKSPointBuffer[1].X = 0;
aWKSPointBuffer[1].Y = 1;
aWKSPointBuffer[2].X = 1;
aWKSPointBuffer[2].Y = 1;
aWKSPointBuffer[3].X = 1;
aWKSPointBuffer[3].Y = 0;
aWKSPointBuffer[4].X = 0;
aWKSPointBuffer[4].Y = 0;
geometryBridge2.SetWKSPoints(pointCollection4, ref aWKSPointBuffer);
return pointCollection4 as IPolygon;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment