Engine中如何为不含Z值的Polyline设置Z值?

Engine中如何为不含Z值的Polyline设置Z值?
已邀请:

朱新颖

赞同来自:

【解决办法】:
1,首先获取不带Z值的IPolyline,遍历其Part,获取IPoint,将IPoint转为IZAware,设置其ZAware = true; 然后为点赋z值;
2,将新的Point重新构建成IPolyline,将该IPolyline转为IZAware,设置其ZAware = true 即可

注:IPolygon的方法与IPolyline一样, 将Path换为Ring即可。可参考下面代码:


private IPolyline addZValue(IPolyline polyline) 

if (polyline != null) 

IGeometryCollection geoCol = new PolylineClass(); 
IGeometryCollection geoColNew = new PolylineClass(); 
geoCol = polyline as IGeometryCollection; 

for (int i = 0; i < geoCol.GeometryCount; i++) 

IPointCollection pointCol = geoCol.get_Geometry(i) as IPointCollection; 
IPointCollection pointColNew = new PathClass(); 
for (int j = 0; j < pointCol.PointCount; j++) 

IPoint point = pointCol.get_Point(j); 
IZAware zAware = point as IZAware; 
zAware.ZAware = true; 
point.Z = 0; //Z值
pointColNew.AddPoint(point); 

IPath path = pointColNew as IPath; 
geoColNew.AddGeometry(path as IGeometry); 

IPolyline polylineNew = new PolylineClass(); 
polylineNew = geoColNew as IPolyline; 
IZAware zAwareNew = polylineNew as IZAware; 
zAwareNew.ZAware = true; 
return polylineNew; 

else 
return null; 

}

要回复问题请先登录注册