在ArcGIS Engine下如何实现矩形外扩指定距离?其实已经提供了相关的接口 ITransform2D,里面有个scale方法可以进行多边形缩放 ,参数如下
ITransform2D.Scale(IPointOrigin,doublesx,doublesy);
其中 Origin为缩放基点、sx与sy分别是X、Y方向的缩放因子。在开发帮助中我们可以下面的描述:
where sX is the ratio of Old Width to New Width, and sY is the ratio of Old Height to New Height(sX是原始宽度与新宽度的比例,sY是原始高度与新高度的比例)
如果原始宽度和高度分别为dWidth、dHeight,将矩形外扩50米,新的宽度和高度分别为dWidth+1000、dHeight+100,缩放传值为如下
ITransform2D.Scale(IPoint Origin,dWidth/(dWidth+100),dHeight/(dHeight+100) );
但实际得出的结果与我们所期望的恰好相反,经反复实验正确的传值如下所示
ITransform2D.Scale(IPoint Origin,(dWidth+100)/dWidth,(dHeight+100)/dHeight );
IPolygon pPolygon = pFeature.ShapeCopy as IPolygon;
IPoint pCenter = new PointClass();
pCenter.PutCoords((pPolygon.Envelope.XMin+pPolygon.Envelope.XMax)/2,
(pPolygon.Envelope.YMin+pPolygon.Envelope.YMax)/2);
pCenter.SpatialReference = pPolygon.SpatialReference;
ITransform2D pTran = pPolygon as ITransform2D;
pTran.Scale(pCenter, (pPolygon.Envelope.Width + dis * 2) / pPolygon.Envelope.Width,
(pPolygon.Envelope.Height + dis * 2) / pPolygon.Envelope.Height);
pPolygon = pTran as IPolygon;
pFeature.Shape = pPolygon;
pFeature.Store();
pFeature = pFeatureCursor.NextFeature();