Пример #1
0
		/// <summary>
		/// 创建所有空间图层
		/// </summary>
		/// <param name="tableStructureNodes">VCT表结构节点集合</param>
		/// <param name="featureCodeNodes">VCT要素编码节点集合</param>
        public List<TableLayer> CreateFeatureLayers(List<TableStructureNode> tableStructureNodes, Hashtable featureCodeNodes)
        {
            try
            {
                if (tableStructureNodes == null || featureCodeNodes == null)
                    return null;

                List<TableLayer> arrFeatureLayer = new List<TableLayer>();
                IFeatureDataset featureDataset = this.m_pIDataset as IFeatureDataset;
                ///读取第一个数据集进行处理
                if (featureDataset != null)
                {
                    ////遍历表结构节点进行空间数据表创建
                    foreach (TableStructureNode tableStructureNode in tableStructureNodes)
                    {
                        FeatureCodeNode featureCodeNode = featureCodeNodes[tableStructureNode.TableName] as FeatureCodeNode;

                        //从配置文件读取图形类型
                        string sGeometryType = "";
                        Metadata.MetaTable pMetaTalbe = Metadata.MetaDataFile.MetaTabls[tableStructureNode.TableName] as Metadata.MetaTable;
                       
                        ///如果当前标准不包含表则不创建
                        if (pMetaTalbe != null)
                        {
                            sGeometryType = Metadata.MetaDataFile.GraphConfig.GetGraphTypeMark(pMetaTalbe.Type);

                            if (sGeometryType == "NoneGeometry")
                            {
                                ///创建属性数据表
                                TableLayer pTalbeLayer = CreateTableLayer(m_pWorkspace as IFeatureWorkspace, tableStructureNode, featureCodeNode);
                                if (pTalbeLayer != null)
                                    arrFeatureLayer.Add(pTalbeLayer);
                            }
                            else
                            {
                                ///创建空间数据表
                                FeatureLayer featureLayer = CreateFeatureLayer(tableStructureNode, featureCodeNode);
                                if (featureLayer != null)
                                    arrFeatureLayer.Add(featureLayer);
                            }
                        }
                    }
                    return arrFeatureLayer;
                }
                return null;
            }
            catch(Exception ex)
            {
                Logger.WriteErrorLog(ex);
                return null;
            }
		}
Пример #2
0
        /// <summary>
        /// 创建属性表
        /// </summary>
        /// <param name="pFeatureWorkspace"></param>
        /// <param name="tableStructureNode"></param>
        /// <param name="featureCodeNode"></param>
        /// <returns></returns>
        private TableLayer CreateTableLayer(IFeatureWorkspace pFeatureWorkspace, TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                if (pFeatureWorkspace != null&&tableStructureNode!=null&&featureCodeNode!=null)
                {
                    IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
                    ///创建数据表字段
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///字段信息验证
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = pFeatureWorkspace as IWorkspace;
                    IEnumFieldError enumFieldError = null;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ITable pTable = pFeatureWorkspace.CreateTable(tableStructureNode.TableName, fixFields,
                        ocDescription.InstanceCLSID, null, "");
                    if (pTable != null)
                    {
                        TableLayer pTableLayer = new TableLayer();

                        //从配置文件读取图形类型
                        string sGeometryType = "";
                        Metadata.MetaTable pMetaTalbe = Metadata.MetaDataFile.MetaTabls[tableStructureNode.TableName] as Metadata.MetaTable;
                        if (pMetaTalbe != null)
                        {
                            sGeometryType = pMetaTalbe.Type;
                        }
                        else
                            return null;

                        pTableLayer.GeometryType = sGeometryType;
                        pTableLayer.Table = pTable;
                        pTableLayer.UpdateFieldIndex();
                        return pTableLayer;
                    }
                    return null;
                }
                return null;
            }
            catch (Exception ex)
            {
                Logger.WriteErrorLog(ex);
                return null;
            }
        }
Пример #3
0
        /// <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();
            }
        }
Пример #4
0
        /// <summary>
        /// ��mdb��vctת��ʱ����ʼ��ͼ���б�
        /// </summary>
        private bool InitialFeatureList()
        {
            try
            {
                if (m_pIDataset == null)
                    return false;
                m_FeatureList = new List<TableLayer>();
                IEnumDataset pEnumDataset = m_pIDataset.Subsets;
                IDataset pSet = pEnumDataset.Next();
                while (pSet != null)
                {
                    FeatureLayer pFeatureLayer = null;
                    IFeatureClass pFeatureCls = pSet as IFeatureClass;

                    string sGeometryType = "";
                    ///�������ļ���ȡҪ������
                    Metadata.MetaTable pMetaTable = Metadata.MetaDataFile.MetaTabls[pSet.Name] as Metadata.MetaTable;
                    if (pMetaTable != null)
                    {
                        sGeometryType = pMetaTable.Type;
                    }
                    else
                    {
                        ///��������ڱ�׼�������򲻴���
                        pSet = pEnumDataset.Next();
                        continue;
                    }
                    ///����Ҫ�����ʹ���vct�ռ����ݽڵ�
                    esriGeometryType pFeatureType = pFeatureCls.ShapeType;
                    if (pFeatureType == esriGeometryType.esriGeometryLine
                        || pFeatureType == esriGeometryType.esriGeometryPolyline)
                    {
                        ///�����߽ڵ�
                        pFeatureLayer = new LineLayer();
                        if (sGeometryType == "")
                            sGeometryType = "Line";
                    }
                    else if (pFeatureType == esriGeometryType.esriGeometryPolygon)
                    {
                        //������ڵ�
                        pFeatureLayer = new PolygonLayer();
                          if (sGeometryType == "")
                            sGeometryType = "Polygon";
                    }
                    else if (pFeatureType == esriGeometryType.esriGeometryPoint)
                    {
                        pFeatureLayer = new PointLayer();
                        if (sGeometryType == "")
                            sGeometryType = "Point";
                    }

                    ////ע��ͼ��
                    if (pFeatureCls.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        pFeatureLayer = new AnnotationLayer();
                        pFeatureLayer.GeometryType = "Annotation";
                    }

                    pFeatureLayer.CutGeometry =m_cutGeometry;
                    //�ҽӿռ����ݱ�
                    pFeatureLayer.Table = pSet as ITable;
                    pFeatureLayer.GeometryType = sGeometryType;
                    pFeatureLayer.IsCut = m_bCut;
                    pFeatureLayer.FeatureCode = MetaDataFile.GetFeatureCodeByName(pSet.Name);
                    pFeatureLayer.UpdateFieldIndex();

                    m_FeatureList.Add(pFeatureLayer);
                    pSet = pEnumDataset.Next();
                }

                ///�������Ա����
                IEnumDataset pAttriTalbelDataSet=  m_pIWorkspace.get_Datasets(esriDatasetType.esriDTTable);
                IDataset pAttriDataset = pAttriTalbelDataSet.Next();
                while (pAttriDataset != null)
                 {
                        TableLayer pAttributeTalbe = new TableLayer();

                        ///�������ļ���ȡҪ������
                        Metadata.MetaTable pMetaTable = Metadata.MetaDataFile.MetaTabls[pAttriDataset.Name] as Metadata.MetaTable;
                        if (pMetaTable != null)
                        {
                            pAttributeTalbe.GeometryType = pMetaTable.Type;
                            pAttributeTalbe.Table = pAttriDataset as ITable;
                            pAttributeTalbe.UpdateFieldIndex();
                            m_FeatureList.Add(pAttributeTalbe);
                        }
                     pAttriDataset = pAttriTalbelDataSet.Next();
                 }
                return true;
            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return false;
            }
        }
Пример #5
0
        /// <summary>
        /// 从mdb到vct转换时,初始化图层列表
        /// </summary>
        private bool InitialFeatureList()
        {
            try
            {
                if (m_pIDataset == null)
                    return false;
                m_FeatureList = new List<TableLayer>();
                IEnumDataset pEnumDataset = m_pIDataset.Subsets;
                IDataset pSet = pEnumDataset.Next();
                while (pSet != null)
                {
                    FeatureLayer pFeatureLayer = null;
                    IFeatureClass pFeatureCls = pSet as IFeatureClass;


                    string sGeometryType = "";
                    ///从配置文件获取要素类型
                    Metadata.MetaTable pMetaTable = Metadata.MetaDataFile.MetaTabls[pSet.Name] as Metadata.MetaTable;
                    if (pMetaTable != null)
                    {
                        sGeometryType = pMetaTable.Type;
                    }
                    else
                    {
                        ///如果不属于标准的数据则不处理
                        pSet = pEnumDataset.Next();
                        continue;
                    }
                    ///根据要素类型创建vct空间数据节点
                    esriGeometryType pFeatureType = pFeatureCls.ShapeType;
                    if (pFeatureType == esriGeometryType.esriGeometryLine
                        || pFeatureType == esriGeometryType.esriGeometryPolyline)
                    {
                        ///构造线节点
                        pFeatureLayer = new LineLayer();
                        if (sGeometryType == "")
                            sGeometryType = "Line";
                    }
                    else if (pFeatureType == esriGeometryType.esriGeometryPolygon)
                    {
                        //构造面节点
                        pFeatureLayer = new PolygonLayer();
                          if (sGeometryType == "")
                            sGeometryType = "Polygon"; 
                    }
                    else if (pFeatureType == esriGeometryType.esriGeometryPoint)
                    {
                        pFeatureLayer = new PointLayer();
                        if (sGeometryType == "")
                            sGeometryType = "Point"; 
                    }
                   
                    ////注记图层
                    if (pFeatureCls.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        pFeatureLayer = new AnnotationLayer();
                        pFeatureLayer.GeometryType = "Annotation";
                    }

                    pFeatureLayer.CutGeometry =m_cutGeometry;
                    //挂接空间数据表
                    pFeatureLayer.Table = pSet as ITable;
                    pFeatureLayer.GeometryType = sGeometryType;
                    pFeatureLayer.IsCut = m_bCut;
                    pFeatureLayer.FeatureCode = MetaDataFile.GetFeatureCodeByName(pSet.Name);
                    pFeatureLayer.UpdateFieldIndex();

                    m_FeatureList.Add(pFeatureLayer);
                    pSet = pEnumDataset.Next();
                }

                ///处理属性表集合
                IEnumDataset pAttriTalbelDataSet=  m_pIWorkspace.get_Datasets(esriDatasetType.esriDTTable);
                IDataset pAttriDataset = pAttriTalbelDataSet.Next();
                while (pAttriDataset != null)
                 {
                        TableLayer pAttributeTalbe = new TableLayer();

                        ///从配置文件获取要素类型
                        Metadata.MetaTable pMetaTable = Metadata.MetaDataFile.MetaTabls[pAttriDataset.Name] as Metadata.MetaTable;
                        if (pMetaTable != null)
                        {
                            pAttributeTalbe.GeometryType = pMetaTable.Type;
                            pAttributeTalbe.Table = pAttriDataset as ITable;
                            pAttributeTalbe.UpdateFieldIndex();
                            m_FeatureList.Add(pAttributeTalbe);
                        }
                     pAttriDataset = pAttriTalbelDataSet.Next();
                 }
                return true;
            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return false;
            }
        }
Пример #6
0
        /// <summary>
        /// �������Ա�
        /// </summary>
        /// <param name="pFeatureWorkspace"></param>
        /// <param name="tableStructureNode"></param>
        /// <param name="featureCodeNode"></param>
        /// <returns></returns>
        private TableLayer CreateTableLayer(IFeatureWorkspace pFeatureWorkspace, TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                if (pFeatureWorkspace != null&&tableStructureNode!=null&&featureCodeNode!=null)
                {
                    IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
                    ///�������ݱ��ֶ�
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///�ֶ���Ϣ��֤
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = pFeatureWorkspace as IWorkspace;
                    IEnumFieldError enumFieldError = null;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ITable pTable = pFeatureWorkspace.CreateTable(tableStructureNode.TableName, fixFields,
                        ocDescription.InstanceCLSID, null, "");
                    if (pTable != null)
                    {
                        TableLayer pTableLayer = new TableLayer();

                        //�������ļ���ȡͼ������
                        string sGeometryType = "";
                        Metadata.MetaTable pMetaTalbe = Metadata.MetaDataFile.MetaTabls[tableStructureNode.TableName] as Metadata.MetaTable;
                        if (pMetaTalbe != null)
                        {
                            sGeometryType = pMetaTalbe.Type;
                        }
                        else
                            return null;

                        pTableLayer.GeometryType = sGeometryType;
                        pTableLayer.Table = pTable;
                        pTableLayer.UpdateFieldIndex();
                        return pTableLayer;
                    }
                    return null;
                }
                return null;
            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }