ArcEngine Geometry库定义了基本几何图形的矢量表达形式,顶级的几何图形有Points、Multipoints、Polylines、Polygons、Multipatches,Geodatabase和绘图系统使用这些几何图形来定义其他各种形状的特征和图形,提供了编辑图形的操作方法和地图符号系统符号化特征数据的途径。
Geometry库中几个核心类和接口构成了Geometry对象的基本框架。
GeometryEnvironment
GeometryEnvironment提供了从不同的输入、设置或获取全局变量来创建几何图形的方法,以便控制geometry方法的行为。GeometryEnvironment对象是一个单例对象。
public
IPolyline TestGeometryEnvironment()
{
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
//Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N) as ISpatialReferenceResolution;
spatialReferenceResolution.ConstructFromHorizon();
ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
spatialReferenceTolerance.SetDefaultXYTolerance();
ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;
//Create an array of WKSPoint structures starting in the middle of the x,y domain of the
//projected coordinate system.
double xMin;
double xMax;
double yMin;
double yMax;
spatialReference.GetDomain(out xMin, out xMax, out yMin, out yMax);
double xFactor = (xMin + xMax) * 0.5;
double yFactor = (yMin + yMax) * 0.5;
WKSPoint[] wksPoints = new WKSPoint[10];
for (int i = 0; i < wksPoints.Length; i++)
{
wksPoints[i].X = xFactor + i;
wksPoints[i].Y = yFactor + i;
}
IPointCollection4 pointCollection = new PolylineClass();
IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass();
geometryBridge.AddWKSPoints(pointCollection, ref wksPoints);
IPolyline polyline = pointCollection as IPolyline;
polyline.SpatialReference =
{
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
//Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N) as ISpatialReferenceResolution;
spatialReferenceResolution.ConstructFromHorizon();
ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
spatialReferenceTolerance.SetDefaultXYTolerance();
ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;
//Create an array of WKSPoint structures starting in the middle of the x,y domain of the
//projected coordinate system.
double xMin;
double xMax;
double yMin;
double yMax;
spatialReference.GetDomain(out xMin, out xMax, out yMin, out yMax);
double xFactor = (xMin + xMax) * 0.5;
double yFactor = (yMin + yMax) * 0.5;
WKSPoint[] wksPoints = new WKSPoint[10];
for (int i = 0; i < wksPoints.Length; i++)
{
wksPoints[i].X = xFactor + i;
wksPoints[i].Y = yFactor + i;
}
IPointCollection4 pointCollection = new PolylineClass();
IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass();
geometryBridge.AddWKSPoints(pointCollection, ref wksPoints);
IPolyline polyline = pointCollection as IPolyline;
polyline.SpatialReference =