public virtual void Dispose() { if (m_VCTFile != null) m_VCTFile.CloseFile(); m_VCTFile = null; Metadata.MetaDataFile.Dispose(); if (m_pTempFile != null) m_pTempFile.Close(); m_pTempFile = null; if (m_dataset != null) m_dataset.Dispose(); m_dataset = null; if (m_MDBFile != null) m_MDBFile.Dispose(); m_MDBFile = null; GC.Collect(); }
/// <summary> /// 执行转换 /// </summary> /// <param name="bIgnoreHeadError">是否忽略头文件的错误</param> /// <returns></returns> public EnumVCT2MDBExchangeInfo Exchange(bool bAllowDefaultProjection) { ///指示当前是否在读取VCT实体 bool bIsReadEntity = false; ///指示当前是否在读取VCT属性 bool bIsReadAtti = false; try { //读取头节点 FileData.HeadNode headNode = m_VCTFile.ReadHeadNode(); if (headNode != null) { //创建数据集 ESRIData.Dataset dataset = m_MDBFile.CreateDataset(headNode, m_strDataSetName); ///数据集的空间参考创建失败 if (dataset.ESRIDataset==null) { return EnumVCT2MDBExchangeInfo.DATASETERROR; } IGeoDataset pDataset = dataset.ESRIDataset as IGeoDataset; if (pDataset!=null&& pDataset.SpatialReference is UnknownCoordinateSystemClass && !bAllowDefaultProjection) { return EnumVCT2MDBExchangeInfo.PROJECTIONERROR; } if (dataset != null) { //读取要素参数节点和表结构节点 Hashtable arrFeatureCodeNode = m_VCTFile.ReadFeatureCodeNodes(); ///读取要素代码错误 if (arrFeatureCodeNode == null) { return EnumVCT2MDBExchangeInfo.FEATURECODEERROR; } List<FileData.TableStructureNode> arrTableStructureNode = m_VCTFile.ReadTableStructureNodes(); ///读取要素代码错误 if (arrTableStructureNode == null) { return EnumVCT2MDBExchangeInfo.FEATUREATRRIBUTE; } if (arrFeatureCodeNode != null && arrTableStructureNode != null) { //创建图层 //ESRIData.FeatureLayerFactory featureLayerFactory = new ESRIData.FeatureLayerFactory(dataset.Workspace); //featureLayerFactory.CreateFeatureLayers(arrTableStructureNode, arrFeatureCodeNode); //dataset.LayerFactory = featureLayerFactory; dataset.CreateFeatureLayers(arrTableStructureNode, arrFeatureCodeNode); //读取空间实体节点 string strFeatureCode = "";//上一个实体所属图层的要素代码 ESRIData.FeatureLayer featureLayer = null; ESRIData.TableLayer tableLayer = null; FileData.EntityNode entityNode; bIsReadEntity = true;///开始读取实体 while ((entityNode = m_VCTFile.ReadEntityNode()) != null) { //获取实体所属图层 if (strFeatureCode != entityNode.FeatureCode) tableLayer = dataset.GetFeatureLayerByCode(entityNode.FeatureCode); //创建空间实体对象 featureLayer = tableLayer as FeatureLayer; if (featureLayer != null) { featureLayer.CreateFeatureEntity(entityNode); } strFeatureCode = entityNode.FeatureCode; } //读取属性节点 FileData.TableNode tableNode = null; bIsReadAtti = true;///开始读取VCT属性 while ((tableNode = m_VCTFile.ReadTableNode()) != null) { //获取属性表对象 tableLayer = dataset.GetFeatureLayerByName(tableNode.TableName); featureLayer = tableLayer as FeatureLayer; if (featureLayer != null) { //读取数据表记录 //FileData.RecordNode recordNode = null; //while ((recordNode = m_VCTFile.ReadRecordNode()) != null) //{ // ESRIData.FeatureEntity featureEntity = featureLayer.GetFeatureEntityByID(recordNode.EntityID); // featureEntity.AttachAttribute(recordNode); //} List<FileData.RecordNode> arrRecordNode = m_VCTFile.ReadRecordNodes(); if (arrRecordNode.Count > 0) { arrRecordNode.Sort(); List<ESRIData.FeatureEntity> arrFeatureEntity = featureLayer.GetFeatureEntitys(); if (arrFeatureEntity.Count > 0) { arrFeatureEntity.Sort(); int j = 0; for (int i = 0; i < arrFeatureEntity.Count; i++) { for (; j < arrRecordNode.Count; j++) { if (arrFeatureEntity[i].EntityID == arrRecordNode[j].EntityID) arrFeatureEntity[i].AttachAttribute(arrRecordNode[j], featureLayer.StructureNode); else if (arrFeatureEntity[i].EntityID < arrRecordNode[j].EntityID) { break; } else { //插入 } } } arrFeatureEntity.Clear(); arrFeatureEntity = null; } else { //插入 } arrRecordNode.Clear(); arrRecordNode = null; } } else { ///add by zengping 2011-4-24添加属性记录 if (tableLayer != null) { List<FileData.RecordNode> arrRecordNode = m_VCTFile.ReadRecordNodes(); foreach (FileData.RecordNode Recorditem in arrRecordNode) { tableLayer.InsertAttibuteTableRecord(Recorditem); } arrRecordNode.Clear(); arrRecordNode = null; } else tableNode = null; } } tableLayer = null; arrFeatureCodeNode.Clear(); arrTableStructureNode.Clear(); arrTableStructureNode = null; arrFeatureCodeNode = null; if (bAllowDefaultProjection && dataset.Projection.SpatialReference is UnknownCoordinateSystemClass) return EnumVCT2MDBExchangeInfo.SUCCESSWITHDEFAULTPROJECTION; else return EnumVCT2MDBExchangeInfo.EXCHANGESUCCESS; } dataset.Dispose(); } else { ///获取数据集错误 return EnumVCT2MDBExchangeInfo.DATASETERROR; } headNode = null; } else { return EnumVCT2MDBExchangeInfo.HEADFILEERROR; } return EnumVCT2MDBExchangeInfo.EXCHANGEFAIL; } catch (Exception ex) { LogAPI.WriteErrorLog(ex); ///读取实体过程中出错 if (bIsReadEntity && !bIsReadAtti) return EnumVCT2MDBExchangeInfo.FEATUREENTY; ///读取属性过程中出错 else if (bIsReadEntity && bIsReadAtti) return EnumVCT2MDBExchangeInfo.FEATUREATRRIBUTE; return EnumVCT2MDBExchangeInfo.EXCHANGUNKNOWEERROR; } finally { GC.Collect(); } }