/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { try { //ILayer player = ClsGlobal.GetSelectedLayer(m_hookHelper); IBasicMap map = null; ILayer layer = null; ClsGlobal.GetSelectedMapAndLayer(m_pTocCtl, ref map, ref layer); if (map == null || layer == null) { return; } IFeatureLayer pFLayer = (IFeatureLayer)layer; IFeatureLayerDefinition pFLDef = (IFeatureLayerDefinition)pFLayer; IFeatureSelection pFSel = (IFeatureSelection)pFLayer; ISelectionSet pSSet = pFSel.SelectionSet; if (pSSet.Count > 0) { IFeatureLayer pSelFL = pFLDef.CreateSelectionLayer(layer.Name + "Selection", true, null, null); map.AddLayer(pSelFL); IActiveView activiView = map as IActiveView; activiView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); m_pTocCtl.Update(); } } catch (Exception ex) { ; } }
/// <summary> /// 把图层添加到地图中 /// </summary> /// <param name="basicMap"></param> /// <param name="addedLayer"></param> public static void AddLyrToBasicMap(IBasicMap basicMap, ILayer addedLayer) { try { //判断空间参考是否一致 IDataset dataSet = addedLayer as IDataset; if (dataSet is IGeoDataset) { IGeoDataset geoDataset = dataSet as IGeoDataset; if (geoDataset.SpatialReference != null && basicMap.SpatialReference != null) { //这里只是通过名称进行下比较 如果说想要比较的严格的话 可以通过克隆的方法进行 if (blnEditMapSpatial == true && geoDataset.SpatialReference.Name != basicMap.SpatialReference.Name) { if (MessageBox.Show("当前加载图层的空间参考与地图空间参考不一致,是否更改地图空间参考?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { basicMap.SpatialReference = geoDataset.SpatialReference; } else { //不进行比较了 blnEditMapSpatial = false; } } } basicMap.AddLayer(addedLayer); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }
/// <summary> /// Add Data to the Map /// </summary> private void cmdAddData_Click(object sender, EventArgs e) { if (_basicMap == null) { return; } _basicMap.AddLayer(); }
public static void AddFeatureLayer(IBasicMap ibasicMap_0, IFeatureClass ifeatureClass_0) { IFeatureLayer pLayer = new FeatureLayer { FeatureClass = ifeatureClass_0, Name = ifeatureClass_0.AliasName }; ibasicMap_0.AddLayer(pLayer); }
public static void AddFeatureLayer(IBasicMap compLayer, IFeatureClass pFClass) { IFeatureLayer featureLayerClass = new FeatureLayerClass() { FeatureClass = pFClass, Name = pFClass.AliasName }; compLayer.AddLayer(featureLayerClass); }
public bool AddDatasetLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, IDataset pDataset) { try { if ((pBasicMap == null) & (pParentLayer == null)) { return(false); } if (pDataset == null) { return(false); } Collection pLayersColl = new Collection(); if (!this.GetLayerFormDataset(pDataset, pLayersColl)) { return(false); } if (pLayersColl.Count <= 0) { return(false); } IMapLayers layers = pBasicMap as IMapLayers; foreach (ILayer layer in pLayersColl) { if (layer != null) { if (pParentLayer != null) { pParentLayer.Add(layer); } else { pBasicMap.AddLayer(layer); } if (pParentLayer == null) { layers.MoveLayer(layer, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, layer, 0); } } } pLayersColl = null; return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddDataLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public static void AddFeatureLayer(IBasicMap compLayer, IFeatureClass[] pFClasses) { for (int i = 0; i < (int)pFClasses.Length; i++) { IFeatureLayer featureLayerClass = new FeatureLayerClass() { FeatureClass = pFClasses[i], Name = pFClasses[i].AliasName }; compLayer.AddLayer(featureLayerClass); } }
public static void AddFeatureLayer(IBasicMap ibasicMap_0, IFeatureClass[] ifeatureClass_0) { for (int i = 0; i < ifeatureClass_0.Length; i++) { IFeatureLayer pLayer = new FeatureLayer { FeatureClass = ifeatureClass_0[i], Name = ifeatureClass_0[i].AliasName }; ibasicMap_0.AddLayer(pLayer); } }
public bool AddGroupLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sLayerName) { try { if (sLayerName == null) { sLayerName = ""; } if (pBasicMap == null) { return(false); } if (string.IsNullOrEmpty(sLayerName)) { sLayerName = "新建图层组"; } IGroupLayer pLayer = null; pLayer = new GroupLayerClass { Name = sLayerName }; if (pParentLayer == null) { pBasicMap.AddLayer(pLayer); } else { pParentLayer.Add(pLayer); } IMapLayers layers = pBasicMap as IMapLayers; if (pParentLayer == null) { layers.MoveLayer(pLayer, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, pLayer, 0); } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGroupLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
private void method_4(IBasicMap ibasicMap_0, ILayer ilayer_0, bool bool_1) { try { if (bool_1) { bool flag = true; if (ilayer_0 is IGeoFeatureLayer) { IFeatureClass featureClass = (ilayer_0 as IGeoFeatureLayer).FeatureClass; flag = featureClass.FeatureCount(null) > 0; } else if (ilayer_0 is IFDOGraphicsLayer) { ITable attributeTable = (ilayer_0 as IAttributeTable).AttributeTable; flag = attributeTable.RowCount(null) > 0; } if (flag) { if (this.ienvelope_0 != null) { IEnvelope areaOfInterest = ilayer_0.AreaOfInterest; if ((areaOfInterest.SpatialReference is IUnknownCoordinateSystem || this.ienvelope_0.SpatialReference is IUnknownCoordinateSystem || this.ienvelope_0.SpatialReference == null ? false : areaOfInterest.SpatialReference != null)) { areaOfInterest.Project(this.ienvelope_0.SpatialReference); this.ienvelope_0.Union(areaOfInterest); } } else { this.ienvelope_0 = ilayer_0.AreaOfInterest; } } } ibasicMap_0.AddLayer(ilayer_0); } catch (Exception exception) { } }
public bool AddGraphicsLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sLayerName) { try { if (sLayerName == null) { sLayerName = ""; } if (pBasicMap == null) { return(false); } if (string.IsNullOrEmpty(sLayerName)) { sLayerName = "<新建图像图层>"; } IGraphicsLayer layer = null; if (this.FindGraphicsLayer(pBasicMap, sLayerName) == null) { layer = new CompositeGraphicsLayerClass(); ILayer layer2 = null; layer2 = layer as ILayer; layer2.Name = sLayerName; pBasicMap.AddLayer(layer as ILayer); IMapLayers layers = pBasicMap as IMapLayers; if (pParentLayer == null) { layers.MoveLayer(layer2, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, layer2, 0); } } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGraphicsLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
//用于往MAP中添加图层 比较空间参考是否一致 public static void AddLyrToBasicMap(ref IBasicMap pMap, ILayer pLayer) { //WHFErrorHandle.clsErrorHandle pdisplayinfo = new WHFErrorHandle.clsErrorHandle(); IGeoDataset pGeoDataset = default(IGeoDataset); try { pMap.AddLayer(pLayer); //先把图层加进去再说 //判断空间参考是否一致 if (pLayer is IGeoFeatureLayer) { pGeoDataset = (IGeoDataset)pLayer; if (((pGeoDataset.SpatialReference != null)) & ((pMap.SpatialReference != null))) { //这里只是通过名称进行下比较 如果说想要比较的严格的话 可以通过克隆的方法进行 if ((blnEditMapSpatial == true) & (pGeoDataset.SpatialReference.Name != pMap.SpatialReference.Name)) { //if (pdisplayinfo.DisplayInformation("当前加载图层的空间参考与地图空间参考不一致," + "是否更改地图空间参考?", true, " 是 ", " 否 ") == true) if (MessageBoxEx.Show("当前加载图层的空间参考与地图空间参考不一致," + "是否更改地图空间参考?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { pMap.SpatialReference = pGeoDataset.SpatialReference; } else { //不进行比较了 blnEditMapSpatial = false; } } } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }
public bool AddGxFileLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sFileName) { try { if (sFileName == null) { sFileName = ""; } if (pBasicMap == null) { return(false); } if (string.IsNullOrEmpty(sFileName)) { OpenFileDialog dialog = new OpenFileDialog { Filter = "图层文件 (*.lyr)|*.lyr", Multiselect = false, Title = "选择输入的图层文件" }; if (dialog.ShowDialog() != DialogResult.OK) { return(false); } sFileName = dialog.FileName; dialog = null; } if (string.IsNullOrEmpty(sFileName)) { return(false); } if (!File.Exists(sFileName)) { Interaction.MsgBox("地图图层加载失败,图层文件 " + sFileName + " 不存在。", MsgBoxStyle.Exclamation, "错误警告"); return(false); } IMapDocument document = null; document = new MapDocumentClass(); if (!document.get_IsMapDocument(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是 MapDocument 文件。", MsgBoxStyle.Exclamation, "失败"); return(false); } if (document.get_IsRestricted(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件受到限制,无权使用。", MsgBoxStyle.Exclamation, "失败"); return(false); } document.Open(sFileName, null); ILayer pLayer = null; if (document.DocumentType == esriMapDocumentType.esriMapDocumentTypeLyr) { pLayer = document.get_Layer(0, 0); if (pLayer == null) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n图层文件或数据错误。", MsgBoxStyle.Exclamation, "加载失败"); } } else { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是地图图层文件。", MsgBoxStyle.Exclamation, "加载失败"); } document.Close(); document = null; if (pLayer == null) { return(false); } if (pParentLayer == null) { pBasicMap.AddLayer(pLayer); } else { pParentLayer.Add(pLayer); } IMapLayers layers = pBasicMap as IMapLayers; if (pParentLayer == null) { layers.MoveLayer(pLayer, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, pLayer, 0); } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGxFileLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public static void AddDataset(IBasicMap pMap, IDataset pDataset, string dsName) { IFeatureLayer fDOGraphicsLayerClass; IFeatureClass j; IFeatureLayer featureLayerClass; if (dsName == null) { dsName = ""; } switch (pDataset.Type) { case esriDatasetType.esriDTFeatureDataset: { IEnumDataset subsets = pDataset.Subsets; subsets.Reset(); for (IDataset i = subsets.Next(); i != null; i = subsets.Next()) { MapHelper.AddDataset(pMap, i, dsName); } return; } case esriDatasetType.esriDTFeatureClass: { IFeatureClass idataset0 = (IFeatureClass)pDataset; if (idataset0.FeatureType == esriFeatureType.esriFTAnnotation) { fDOGraphicsLayerClass = new FDOGraphicsLayerClass(); try { fDOGraphicsLayerClass.FeatureClass = idataset0; fDOGraphicsLayerClass.Name = string.Concat(dsName, idataset0.AliasName); pMap.AddLayer(fDOGraphicsLayerClass); return; } catch (Exception exception) { exception.ToString(); return; } } else if (idataset0.FeatureType != esriFeatureType.esriFTDimension) { fDOGraphicsLayerClass = new FeatureLayerClass() { FeatureClass = idataset0, Name = string.Concat(dsName, idataset0.AliasName) }; pMap.AddLayer(fDOGraphicsLayerClass); return; } else { fDOGraphicsLayerClass = new DimensionLayerClass() { FeatureClass = idataset0, Name = string.Concat(dsName, idataset0.AliasName) }; pMap.AddLayer(fDOGraphicsLayerClass); return; } break; } case esriDatasetType.esriDTPlanarGraph: case esriDatasetType.esriDTText: case esriDatasetType.esriDTRelationshipClass: { return; } case esriDatasetType.esriDTGeometricNetwork: { IGeometricNetwork geometricNetwork = pDataset as IGeometricNetwork; if (geometricNetwork == null) { return; } IEnumFeatureClass classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleJunction]; classesByType.Reset(); for (j = classesByType.Next(); j != null; j = classesByType.Next()) { featureLayerClass = new FeatureLayerClass() { FeatureClass = j, Name = string.Concat(dsName, (j as IDataset).Name) }; pMap.AddLayer(featureLayerClass); } classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexJunction]; classesByType.Reset(); for (j = classesByType.Next(); j != null; j = classesByType.Next()) { featureLayerClass = new FeatureLayerClass() { FeatureClass = j, Name = string.Concat(dsName, (j as IDataset).Name) }; pMap.AddLayer(featureLayerClass); } classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleEdge]; classesByType.Reset(); for (j = classesByType.Next(); j != null; j = classesByType.Next()) { featureLayerClass = new FeatureLayerClass() { FeatureClass = j, Name = string.Concat(dsName, (j as IDataset).Name) }; pMap.AddLayer(featureLayerClass); } classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexEdge]; classesByType.Reset(); for (j = classesByType.Next(); j != null; j = classesByType.Next()) { featureLayerClass = new FeatureLayerClass() { FeatureClass = j, Name = string.Concat(dsName, (j as IDataset).Name) }; pMap.AddLayer(featureLayerClass); } return; } case esriDatasetType.esriDTTopology: { ITopologyLayer topologyLayerClass = new TopologyLayerClass() { Topology = pDataset as ITopology }; (topologyLayerClass as ILayer).Name = string.Concat(dsName, pDataset.Name); pMap.AddLayer(topologyLayerClass as ILayer); return; } case esriDatasetType.esriDTTable: { try { IRasterCatalogTable rasterCatalogTableClass = new RasterCatalogTable() { Table = (ITable)pDataset }; rasterCatalogTableClass.Update(); IRasterCatalogLayer rasterCatalogLayerClass = new RasterCatalogLayerClass(); rasterCatalogLayerClass.Create(rasterCatalogTableClass); rasterCatalogLayerClass.Name = string.Concat(dsName, pDataset.BrowseName); pMap.AddLayer(rasterCatalogLayerClass); return; } catch { try { IStandaloneTableCollection ibasicMap0 = pMap as IStandaloneTableCollection; IPropertySet connectionProperties = pDataset.Workspace.ConnectionProperties; bool flag = false; int num = 0; while (true) { if (num < ibasicMap0.StandaloneTableCount) { ITable table = ibasicMap0.StandaloneTable[num].Table; if ( !connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) || !((table as IDataset).Name == pDataset.Name)) { num++; } else { flag = true; break; } } else { break; } } if (!flag) { ibasicMap0.AddStandaloneTable(new StandaloneTableClass() { Table = pDataset as ITable }); } } catch (Exception exception1) { Logger.Current.Write(exception1.Message, LogLevel.Error, null); } return; } break; } case esriDatasetType.esriDTRasterDataset: case esriDatasetType.esriDTRasterBand: { IRasterLayer rasterLayerClass = new RasterLayerClass(); rasterLayerClass.CreateFromDataset((IRasterDataset)pDataset); rasterLayerClass.Name = string.Concat(dsName, pDataset.Name); pMap.AddLayer(rasterLayerClass); return; } case esriDatasetType.esriDTTin: { ITinLayer tinLayerClass = new TinLayerClass() { Dataset = (ITin)pDataset, Name = string.Concat(dsName, pDataset.Name) }; pMap.AddLayer(tinLayerClass); return; } case esriDatasetType.esriDTCadDrawing: { ICadLayer cadLayerClass = new CadLayerClass() { CadDrawingDataset = pDataset as ICadDrawingDataset, Name = pDataset.Name }; pMap.AddLayer(cadLayerClass); return; } default: { return; } } }
public static void AddDataset(IBasicMap ibasicMap_0, IDataset idataset_0, string string_0) { if (string_0 == null) { string_0 = ""; } switch (idataset_0.Type) { case esriDatasetType.esriDTFeatureDataset: { IEnumDataset subsets = idataset_0.Subsets; subsets.Reset(); for (IDataset dataset2 = subsets.Next(); dataset2 != null; dataset2 = subsets.Next()) { AddDataset(ibasicMap_0, dataset2, string_0); } break; } case esriDatasetType.esriDTFeatureClass: { IFeatureLayer layer; IFeatureClass class2 = (IFeatureClass)idataset_0; if (class2.FeatureType != esriFeatureType.esriFTAnnotation) { if (class2.FeatureType == esriFeatureType.esriFTDimension) { IFeatureLayer dimensionLayer = new DimensionLayer() as IFeatureLayer; dimensionLayer.FeatureClass = class2; dimensionLayer.Name = string_0 + class2.AliasName; layer = dimensionLayer as IFeatureLayer; ibasicMap_0.AddLayer(layer); } else { layer = new FeatureLayer { FeatureClass = class2, Name = string_0 + class2.AliasName }; ibasicMap_0.AddLayer(layer); } break; } layer = new FDOGraphicsLayer() as IFeatureLayer; try { layer.FeatureClass = class2; layer.Name = string_0 + class2.AliasName; ibasicMap_0.AddLayer(layer); } catch (Exception exception) { exception.ToString(); } break; } case esriDatasetType.esriDTGeometricNetwork: { IGeometricNetwork network = idataset_0 as IGeometricNetwork; if (network != null) { IFeatureLayer layer7; IEnumFeatureClass class3 = network.get_ClassesByType(esriFeatureType.esriFTSimpleJunction); class3.Reset(); IFeatureClass class4 = class3.Next(); while (class4 != null) { layer7 = new FeatureLayer { FeatureClass = class4, Name = string_0 + (class4 as IDataset).Name }; ibasicMap_0.AddLayer(layer7); class4 = class3.Next(); } class3 = network.get_ClassesByType(esriFeatureType.esriFTComplexJunction); class3.Reset(); for (class4 = class3.Next(); class4 != null; class4 = class3.Next()) { layer7 = new FeatureLayer { FeatureClass = class4, Name = string_0 + (class4 as IDataset).Name }; ibasicMap_0.AddLayer(layer7); } class3 = network.get_ClassesByType(esriFeatureType.esriFTSimpleEdge); class3.Reset(); for (class4 = class3.Next(); class4 != null; class4 = class3.Next()) { layer7 = new FeatureLayer { FeatureClass = class4, Name = string_0 + (class4 as IDataset).Name }; ibasicMap_0.AddLayer(layer7); } class3 = network.get_ClassesByType(esriFeatureType.esriFTComplexEdge); class3.Reset(); for (class4 = class3.Next(); class4 != null; class4 = class3.Next()) { layer7 = new FeatureLayer { FeatureClass = class4, Name = string_0 + (class4 as IDataset).Name }; ibasicMap_0.AddLayer(layer7); } } break; } case esriDatasetType.esriDTTopology: { ITopologyLayer layer = new TopologyLayer() as ITopologyLayer; layer.Topology = idataset_0 as ITopology; ITopologyLayer layer3 = layer as ITopologyLayer; (layer3 as ILayer).Name = string_0 + idataset_0.Name; ibasicMap_0.AddLayer(layer3 as ILayer); break; } case esriDatasetType.esriDTTable: try { IRasterCatalogTable pCatalog = new RasterCatalogTable { Table = (ITable)idataset_0 }; pCatalog.Update(); IRasterCatalogLayer pLayer = new RasterCatalogLayer() as IRasterCatalogLayer; pLayer.Create(pCatalog); pLayer.Name = string_0 + idataset_0.BrowseName; ibasicMap_0.AddLayer(pLayer); } catch { try { IStandaloneTableCollection tables = ibasicMap_0 as IStandaloneTableCollection; IPropertySet connectionProperties = idataset_0.Workspace.ConnectionProperties; bool flag = false; for (int i = 0; i < tables.StandaloneTableCount; i++) { ITable table = tables.get_StandaloneTable(i).Table; if (connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) && ((table as IDataset).Name == idataset_0.Name)) { goto Label_03E1; } } goto Label_03E4; Label_03E1: flag = true; Label_03E4: if (!flag) { IStandaloneTable table3 = new StandaloneTable { Table = idataset_0 as ITable }; tables.AddStandaloneTable(table3); } } catch (Exception exception2) { CErrorLog.writeErrorLog(null, exception2, ""); } } break; case esriDatasetType.esriDTRasterDataset: case esriDatasetType.esriDTRasterBand: { IRasterLayer layer5 = new RasterLayer(); layer5.CreateFromDataset((IRasterDataset)idataset_0); layer5.Name = string_0 + idataset_0.Name; ibasicMap_0.AddLayer(layer5); break; } case esriDatasetType.esriDTTin: { ITinLayer layer4 = new TinLayer { Dataset = (ITin)idataset_0, Name = string_0 + idataset_0.Name }; ibasicMap_0.AddLayer(layer4); break; } case esriDatasetType.esriDTCadDrawing: { ICadLayer layer2 = new CadLayer() as ICadLayer; layer2.CadDrawingDataset = idataset_0 as ICadDrawingDataset; layer2.Name = idataset_0.Name; ibasicMap_0.AddLayer(layer2); break; } } }
public void ExportDatatoShape() { ClsGDBDataCommon comm = new ClsGDBDataCommon(); if (!txtOutData.Text.EndsWith("shp")) { //timerShow.Start(); MessageBox.Show("输出文件名不是shp文件!"); return; } // String strFullName = txtOutData.Text; string strPath = System.IO.Path.GetDirectoryName(strFullName); string strName = System.IO.Path.GetFileName(strFullName); //导出数据 IFeatureLayer pFtlayer = (IFeatureLayer)m_pLayer; IFeatureClass pFtClass = pFtlayer.FeatureClass; //IFields pFields = pFtClass.Fields; //设置空间参考 ISpatialReference pSpatialRef; if (rdoLayer.Checked) { IGeoDataset pGeo = (IGeoDataset)pFtlayer; pSpatialRef = pGeo.SpatialReference; } else { pSpatialRef = m_pMap.SpatialReference; } //创建fields IFields pFields = ClsGDBDataCommon.CopyFeatureField(pFtClass, pSpatialRef); if (pFields == null) { MessageBox.Show("拷贝图形字段失败!"); return; } #region //IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields; ////设置字段 //IField pField = new FieldClass(); //IFieldEdit pFieldEdit = (IFieldEdit)pField; //pFieldEdit.Name_2 = "shape"; //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; //IGeometryDef pGeoDef = new GeometryDefClass(); //IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef; //pGeoDefEdit.GeometryType_2 = pFtClass.ShapeType; //pGeoDefEdit.SpatialReference_2 = pSpatialRef; //pGeoDefEdit.HasM_2 = false; //pGeoDefEdit.HasZ_2 = false; //pFieldEdit.GeometryDef_2 = pGeoDef; //pFieldEdit.IsNullable_2 = true; //pFieldEdit.Required_2 = true; //pFieldsEdit.AddField(pField); //复制pFtClass的字段给fields //IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields; //for (int i = 0; i < pFtClass.Fields.FieldCount; i++) //{ // if (pFtClass.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry && // pFtClass.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeOID) // { // IField pfieldcopy = new FieldClass(); // pfieldcopy = pFtClass.Fields.get_Field(i); // pFieldsEdit.AddField(pfieldcopy); // } //} #endregion //创建新的FeatureClass IFeatureClass pFtClassNew = comm.CreateShapefile(strPath, strName, pFields, pSpatialRef); if (pFtClassNew == null) { MessageBox.Show("创建shp文件失败!"); return; } bool bSel = false; if (cmbData.SelectedIndex == 0) { bSel = true; } if (ClsGDBDataCommon.CopyFeatures(pFtlayer, pFtClassNew, bSel) == false) { MessageBox.Show("拷贝失败!"); } #region 拷贝Feature //// //////////////////////////////////////////////////////////////////////////// //IDataset dataset = (IDataset)pFtClassNew; //IWorkspace workspace = dataset.Workspace; ////Cast for an IWorkspaceEdit //IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace; //workspaceEdit.StartEditing(true); //workspaceEdit.StartEditOperation(); //IFeatureBuffer featureBuffer; //IFeatureCursor featureCursor = null; //object featureOID; //////////////////////////////////////////////////////////////////////////// //IFeature pFeature; //long nCount; //long nProcess = 0; //if (cmbData.SelectedIndex == 0)//选中要素 //{ // IFeatureSelection pFtSel = (IFeatureSelection)pFtlayer; // ISelectionSet pSelSet = pFtSel.SelectionSet; // nCount = pSelSet.Count; // if (nCount < 1) // { // //timerShow.Start(); // MessageBox.Show("没有选中对象!"); // return; // } // ICursor pCursor; // pSelSet.Search(null, false, out pCursor); // IFeatureCursor pFtCur = (IFeatureCursor)pCursor; // pFeature = pFtCur.NextFeature(); // while (pFeature != null) // { // ////////////////////////////////////////////////////////////////////////// // featureBuffer = pFtClassNew.CreateFeatureBuffer(); // featureCursor = pFtClassNew.Insert(true); // featureBuffer.Shape = pFeature.ShapeCopy; // ClsGDBDataCommon.CopyFeatureFieldValue(pFeature, (IFeature)featureBuffer); // featureOID = featureCursor.InsertFeature(featureBuffer); // //featureCursor.Flush(); // nProcess++; // this.Text = string.Format("共有:{0}条数据,已处理:{1}条", nCount, nProcess); // pFeature = pFtCur.NextFeature(); // } //} //else//全部要素 //{ // ITable pTable = (ITable)m_pLayer; // nCount = pTable.RowCount(null); // IFeatureCursor pFtCursor = pFtlayer.Search(null, true); // if (pFtCursor == null) return; // pFeature = pFtCursor.NextFeature(); // while (pFeature != null) // { // ////////////////////////////////////////////////////////////////////////// // featureBuffer = pFtClassNew.CreateFeatureBuffer(); // featureCursor = pFtClassNew.Insert(true); // featureBuffer.Shape = pFeature.ShapeCopy; // ClsGDBDataCommon.CopyFeatureFieldValue(pFeature, (IFeature)featureBuffer); // featureOID = featureCursor.InsertFeature(featureBuffer); // nProcess++; // this.Text = string.Format("共有:{0}条数据,已处理:{1}条", nCount, nProcess); // pFeature = pFtCursor.NextFeature(); // } //} //featureCursor.Flush(); //workspaceEdit.StopEditOperation(); //workspaceEdit.StopEditing(true); #endregion //将导出数据添加到地图 IFeatureLayer pOutFL = new FeatureLayerClass(); pOutFL.FeatureClass = pFtClassNew; pOutFL.Name = pFtClassNew.AliasName; m_pMap.AddLayer(pOutFL); this.Close(); }
//private rstPixelType GetRasterPixelType(string strType) //{ // if (strType == rstPixelType.PT_CHAR.ToString()) // { // return rstPixelType.PT_CHAR; // } // else if (strType == rstPixelType.PT_UCHAR.ToString()) // { // return rstPixelType.PT_UCHAR; // } // else if (strType == rstPixelType.PT_SHORT.ToString()) // { // return rstPixelType.PT_SHORT; // } // else if (strType == rstPixelType.PT_USHORT.ToString()) // { // return rstPixelType.PT_USHORT; // } // else if (strType == rstPixelType.PT_LONG.ToString()) // { // return rstPixelType.PT_LONG; // } // else if (strType == rstPixelType.PT_ULONG.ToString()) // { // return rstPixelType.PT_ULONG; // } // else if (strType == rstPixelType.PT_CSHORT.ToString()) // { // return rstPixelType.PT_CSHORT; // } // else if (strType == rstPixelType.PT_CLONG.ToString()) // { // return rstPixelType.PT_CLONG; // } // else if (strType == rstPixelType.PT_FLOAT.ToString()) // { // return rstPixelType.PT_FLOAT; // } // else if (strType == rstPixelType.PT_DOUBLE.ToString()) // { // return rstPixelType.PT_DOUBLE; // } // return rstPixelType.PT_CHAR; //} //private rstResamplingTypes GetRasterResample(string strType) //{ // if (strType == "NearestNeighbor") // { // return rstResamplingTypes.RSP_NearestNeighbor; // } // else if (strType == "BilinearInterpolation") // { // return rstResamplingTypes.RSP_BilinearInterpolation; // } // else if (strType == "CubicConvolution") // { // return rstResamplingTypes.RSP_CubicConvolution; // } // else if (strType == "Majority") // { // return rstResamplingTypes.RSP_Majority; // } // return rstResamplingTypes.RSP_NearestNeighbor; //} #endregion private bool ExportToTif() { if (!txtOutData.Text.EndsWith("tif")) { MessageBox.Show("输出文件名不是tif文件!"); return(false); } String strFullName = txtOutData.Text; string strPath = System.IO.Path.GetDirectoryName(strFullName); //导出文件路径 string strName = System.IO.Path.GetFileName(strFullName); //导出文件名 try { IRasterBandCollection bandsOut = m_pRaster as IRasterBandCollection; IRasterBandCollection rasterBands = m_pRaster.RasterDataset as IRasterBandCollection; double[] dNodata; int nBandOut = 1; //IRaster pRasterOut = null; IRasterBand pBand = null; if (comboBoxExBands.SelectedIndex == 0)//所有波段 { //添加其他波段 for (int i = 3; i < rasterBands.Count; i++) { pBand = rasterBands.Item(i); bandsOut.AppendBand(pBand); } nBandOut = rasterBands.Count; } else { #region 原代码 //pRasterOut = new RasterClass(); //IRasterBandCollection pRB2 = pRasterOut as IRasterBandCollection; //pRB2.AppendBand(rasterBands.Item(comboBoxExBands.SelectedIndex - 1)); //m_pRasterProps = pRasterOut as IRasterProps; #endregion //导出单波段时,不能用Clear(),会清除图层的几何校正属性 int nOut = bandsOut.Count; for (int i = 0; i < nOut; i++) { bandsOut.Remove(i); } pBand = rasterBands.Item(comboBoxExBands.SelectedIndex - 1); bandsOut.AppendBand(pBand); } //重新设置NoData dNodata = new double[nBandOut]; if (!string.IsNullOrEmpty(textNoData.Text)) { for (int i = 0; i < nBandOut; i++) { dNodata[i] = Convert.ToDouble(textNoData.Text); } m_pRasterProps.NoDataValue = dNodata; } //else //{ // for (int i = 0; i < nBandOut; i++) // { // dNodata[i] = ClsGDBDataCommon.getNoDataValue((rasterBands.Item(i) as IRasterProps).NoDataValue);// Convert.ToDouble((rasterBands.Item(i) as IRasterProps).NoDataValue); // } // m_pRasterProps.NoDataValue = dNodata; //} IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass(); IWorkspace pWS = pWSF.OpenFromFile(System.IO.Path.GetDirectoryName(txtOutData.Text), 0); //导出时要保持分辨率和行列数 m_pRasterProps.Width = Convert.ToInt32(txtOutColumns.Text); m_pRasterProps.Height = Convert.ToInt32(txtOutRows.Text); double dcellSizeX = double.Parse(txtCellSizeX.Text); double dcellSizeY = double.Parse(txtCellSizeY.Text); IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.XMin = m_pRasterProps.Extent.UpperLeft.X; pEnvelope.YMax = m_pRasterProps.Extent.UpperLeft.Y; pEnvelope.XMax = m_pRasterProps.Extent.UpperLeft.X + m_pRasterProps.Width * dcellSizeX; pEnvelope.YMin = m_pRasterProps.Extent.UpperLeft.Y - m_pRasterProps.Height * dcellSizeY; m_pRasterProps.Extent = pEnvelope; //设置存储位数 m_pRasterProps.PixelType = (rstPixelType)cmbPixelType.SelectedIndex; ISaveAs2 pSaveAs = m_pRasterProps as ISaveAs2; IRasterStorageDef pRSDef = new RasterStorageDefClass(); IRasterStorageDef2 pRsDef2 = pRSDef as IRasterStorageDef2; //将存储栅格的分辨率设置为与原始图像相同,其实经过上面行列计算之后已经是相同的 IPnt pPntdec = new PntClass(); pPntdec.X = dcellSizeX; pPntdec.Y = dcellSizeY; pRsDef2.CellSize = pPntdec; pRsDef2.PyramidResampleType = (rstResamplingTypes)cmbResample.SelectedIndex; IRasterDataset pDataset = pSaveAs.SaveAsRasterDataset(System.IO.Path.GetFileName(txtOutData.Text), pWS, "TIFF", pRSDef); IRasterDatasetEdit3 rasterEdit3 = pDataset as IRasterDatasetEdit3; //rasterEdit3.DeleteStats();//This method is avaliable only on raster datasets in File and ArcSDE geodatabases. rasterEdit3.ComputeStatisticsHistogram(1, 1, null, true); //导出数据之后要恢复图像的原始属性 m_pRasterProps.SpatialReference = m_pSpatialRef; m_pRasterProps.Extent = m_Envelope; m_pRasterProps.Width = m_nCols; m_pRasterProps.Height = m_nRows; //加到当前地图中 IRasterLayer layerNew = new RasterLayerClass(); layerNew.CreateFromDataset(pDataset); m_pMap.AddLayer(layerNew); IActiveView activeView = m_pMap as IActiveView; activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); return(true); } catch (Exception exc) { MessageBox.Show(exc.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } }