/// <summary> /// 去掉图形中的Z值(高程值) /// </summary> /// <param name="geometry"></param> public static void DropZs(this IGeometry geometry) { IZAware pZaware = geometry as IZAware; pZaware.DropZs(); pZaware.ZAware = false; }
public static void MakeZMAware(IGeometry igeometry_0, bool bool_0) { if (igeometry_0 is IZAware) { IZAware igeometry0 = igeometry_0 as IZAware; if ((!igeometry0.ZAware ? false : !bool_0)) { igeometry0.DropZs(); } igeometry0.ZAware = bool_0; } if (igeometry_0 is IMAware) { IMAware bool0 = igeometry_0 as IMAware; if ((!bool0.MAware ? false : !bool_0)) { bool0.DropMs(); } bool0.MAware = bool_0; } }
public static void MakeZMAware(IGeometry igeometry_0, bool bool_0) { if (igeometry_0 is IZAware) { IZAware iZAware = igeometry_0 as IZAware; if (iZAware.ZAware && !bool_0) { iZAware.DropZs(); } iZAware.ZAware = bool_0; } if (igeometry_0 is IMAware) { IMAware iMAware = igeometry_0 as IMAware; if (iMAware.MAware && !bool_0) { iMAware.DropMs(); } iMAware.MAware = bool_0; } }
//输出单个图层中所有要素集合到shp文件中功能 OK public bool OutPut(IFeatureClass featclass, string outShapeFilePath) { bool rbc = false; if (System.IO.File.Exists(outShapeFilePath) == true) { //输出Shape文件 LocalShapeFileOperator delshpOp = new LocalShapeFileOperator(); delshpOp.LocalShapePathFileName = outShapeFilePath; delshpOp.DeleteShapeFile(); delshpOp.Dispose(); } esriGeometryType geoType = featclass.ShapeType; //创建新的Shape文件 LocalShapeFileOperator shpOp = new LocalShapeFileOperator(); shpOp.LocalShapePathFileName = outShapeFilePath; string dir = shpOp.getDir(outShapeFilePath); string name = shpOp.getFileName(outShapeFilePath); ShapefileWorkspaceFactoryClass objwsf = new ShapefileWorkspaceFactoryClass(); IWorkspace objws = objwsf.OpenFromFile(dir, 0); IFeatureWorkspace feaureWS = objws as IFeatureWorkspace; //设置投影 shpOp.ShapeSpatialReference = (featclass as IGeoDataset).SpatialReference; //设置shp文件的oid字段和几何字段 if (IsObjGeo == false) { if (featclass.HasOID == true) { this.OIDFieldName = featclass.OIDFieldName; } this.GeometryFieldName = featclass.ShapeFieldName; } shpOp.OIDFieldName = this.OIDFieldName; shpOp.GeometryFieldName = this.GeometryFieldName; //创建要素类 IFeatureClass fc = shpOp.CreateFeatureClass(feaureWS, name, esriFeatureType.esriFTSimple, geoType); if (fc != null) { TokayWorkspace.ComRelease(fc); fc = null; rbc = true; } TokayWorkspace.ComRelease(objws); feaureWS = null; objws = null; objwsf = null; //拷贝字段结构 IFeatureClass Dfeatclass = shpOp.getIFeatureClass(); ZhFeatureClass Szhfeatclass = new ZhPointFeatureClass(featclass); Szhfeatclass.CopyFieldsToObjectFeatureClass(Dfeatclass); //拷贝几何对象和属性数据 ZhFeature Szhfeat = null; IFeatureBuffer DfeatBuffer = null; ZhFeature Dzhfeat = null; IFeatureCursor featCurInsert = Dfeatclass.Insert(true); //获取总要素个数 int fIndex = 0; int tmpFCount = Szhfeatclass.FeatureClass.FeatureCount(null); frmProgressBar1 pb = new frmProgressBar1(); pb.Text = "正在输出shp文件..."; pb.Caption1.Text = "正在输出shp文件..."; pb.progressBar1.Maximum = tmpFCount + 1; pb.progressBar1.Value = 0; pb.Show(this.ParentForm); Application.DoEvents(); // IGeometry geo = null; // IFeatureCursor featcur = Szhfeatclass.FeatureClass.Search(null, false); IFeature feat = featcur.NextFeature(); while (feat != null) { fIndex += 1; if (fIndex % 500 == 0) { pb.Caption1.Text = "已输出要素个数:" + fIndex.ToString() + "/总" + tmpFCount.ToString(); pb.progressBar1.Value = fIndex; Application.DoEvents(); featCurInsert.Flush(); } DfeatBuffer = Dfeatclass.CreateFeatureBuffer(); //拷贝几何对象 geo = feat.ShapeCopy; //去掉Z值 IZAware pZaware = geo as IZAware; if (pZaware.ZAware == true) { pZaware.DropZs(); pZaware.ZAware = false; } // DfeatBuffer.Shape = geo; // //拷贝属性数据 Szhfeat = new ZHFeaturePoint(feat); Szhfeat.CopyField(ref DfeatBuffer); featCurInsert.InsertFeature(DfeatBuffer); feat = featcur.NextFeature(); } featCurInsert.Flush(); TokayWorkspace.ComRelease(featcur); featcur = null; TokayWorkspace.ComRelease(featCurInsert); featCurInsert = null; rbc = true; pb.Close(); pb.Dispose(); pb = null; return(rbc); }