LINQPad IGeometryBridge.QueryPoints() example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Query Kind="Program"> | |
<Reference><ProgramFilesX86>\ArcGIS\DeveloperKit10.1\DotNet\ESRI.ArcGIS.Geometry.dll</Reference> | |
<Reference><ProgramFilesX86>\ArcGIS\DeveloperKit10.1\DotNet\ESRI.ArcGIS.System.dll</Reference> | |
<Reference><ProgramFilesX86>\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