//从符号创建几何形体 private static IGeometry CreateGeometryFromSymbol(ISymbol sym, IEnvelope env) { if (sym is IMarkerSymbol) { IArea area = (IArea)env; return((IGeometry)area.Centroid); } else if (sym is ILineSymbol || sym is ITextSymbol) { IPolyline line = new PolylineClass(); IPoint pt = new PointClass(); pt.PutCoords(env.LowerLeft.X, (env.LowerLeft.Y + env.UpperRight.Y) / 2); line.FromPoint = pt; pt = new PointClass(); pt.PutCoords(env.UpperRight.X, (env.LowerLeft.Y + env.UpperRight.Y) / 2); line.ToPoint = pt; return((IGeometry)line); } else if (sym is IFillSymbol) { IPolygon polygon = new PolygonClass(); IPointCollection ptCol = (IPointCollection)polygon; IPoint pt = new PointClass(); pt.PutCoords(env.LowerLeft.X, env.LowerLeft.Y); ptCol.AddPoints(1, ref pt); pt.PutCoords(env.UpperLeft.X, env.UpperLeft.Y); ptCol.AddPoints(1, ref pt); pt.PutCoords(env.UpperRight.X, env.UpperRight.Y); ptCol.AddPoints(1, ref pt); pt.PutCoords(env.LowerRight.X, env.LowerRight.Y); ptCol.AddPoints(1, ref pt); pt.PutCoords(env.LowerLeft.X, env.LowerLeft.Y); ptCol.AddPoints(1, ref pt); return((IGeometry)polygon); } else { return(null); } }
private static IGeometry CreateGeometryFromSymbol(ISymbol sym, IEnvelope env) { IPoint point; if (sym is IMarkerSymbol) { IArea area = (IArea)env; return(area.Centroid); } if ((sym is ILineSymbol) || (sym is ITextSymbol)) { IPolyline polyline = new PolylineClass(); point = new PointClass(); point.PutCoords(env.LowerLeft.X, (env.LowerLeft.Y + env.UpperRight.Y) / 2.0); polyline.FromPoint = point; point = new PointClass(); point.PutCoords(env.UpperRight.X, (env.LowerLeft.Y + env.UpperRight.Y) / 2.0); polyline.ToPoint = point; if (sym is ITextSymbol) { (sym as ITextSymbol).Text = "样本字符"; } return(polyline); } if (sym is IFillSymbol) { IPolygon polygon = new PolygonClass(); IPointCollection points = (IPointCollection)polygon; point = new PointClass(); point.PutCoords(env.LowerLeft.X, env.LowerLeft.Y); points.AddPoints(1, ref point); point.PutCoords(env.UpperLeft.X, env.UpperLeft.Y); points.AddPoints(1, ref point); point.PutCoords(env.UpperRight.X, env.UpperRight.Y); points.AddPoints(1, ref point); point.PutCoords(env.LowerRight.X, env.LowerRight.Y); points.AddPoints(1, ref point); point.PutCoords(env.LowerLeft.X, env.LowerLeft.Y); points.AddPoints(1, ref point); return(polygon); } return(null); }
/// <summary> /// 转化包络为几何面形状 /// </summary> /// <param name="geometry">ESRI几何形状接口</param> /// <returns>ESRI几何形状(面)接口</returns> public static IGeometry ConvertEnvelopeToPolygon(IGeometry geometry) { if ((IsValidGeometry(geometry)) && (geometry is IEnvelope)) { IEnvelope envelope = (IEnvelope)geometry; IGeometry polygon = new Polygon() as IGeometry; IPointCollection pointCollection = (IPointCollection)polygon; IPoint point = envelope.LowerLeft; pointCollection.AddPoints(1, ref point); point = envelope.LowerRight; pointCollection.AddPoints(1, ref point); point = envelope.UpperRight; pointCollection.AddPoints(1, ref point); point = envelope.UpperLeft; pointCollection.AddPoints(1, ref point); ITopologicalOperator topoOp = (ITopologicalOperator)polygon; topoOp.Simplify(); return(polygon); } else { return(null); } }