Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// ��ȡVCT���Ա�ڵ�
        /// </summary>
        public TableNode ReadTableNode()
        {
            if (this.m_streamReader != null)
            {
                string strLine = "";    //��ȡ�������ֻ���

                if (m_bFoundAttributeBegin == false)
                {
                    strLine = this.ReadLine(true);
                    //�������Ա�ڵ�Ŀ�ʼ��ǡ�AttributeBegin��
                    if (strLine.IndexOf("AttributeBegin", System.StringComparison.OrdinalIgnoreCase) > -1)
                    {
                        m_bFoundAttributeBegin = true;
                    }
                }
                if (m_bFoundAttributeBegin == true)
                {
                    strLine = this.ReadLine(true);
                    //�������Ա�ڵ�Ľ�����ǡ�VarcharBegin�������䳤�ַ����Ŀ�ʼ��ǣ�
                    if (strLine.IndexOf("VarcharBegin", System.StringComparison.OrdinalIgnoreCase) > -1)
                    {
                        m_bFoundVarcharBegin = true;
                        return null;
                    }
                    else
                    {
                        TableNode tableNode = new TableNode();
                        //��ȡ������
                        tableNode.TableName = strLine;

                        return tableNode;
                    }
                }
            }
            return null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// д��VCT���Ա�ڵ�
        /// </summary>
        /// <param name="tableNode">VCT���Ա�ڵ�</param>
        public bool WriteTableNode(TableNode tableNode)
        {
            if (this.m_streamWriter != null)
            {
                if (this.m_bFoundTableBegin == false)
                {
                    if (this.m_bFoundAnnotationBegin == false)
                    {
                        if (this.m_bFoundPolygonBegin == false)
                        {
                            if (this.m_bFoundLineBegin == false)
                            {
                                if (this.m_bFoundPointBegin == false)
                                {
                                    this.m_streamWriter.WriteLine("PointBegin");
                                    this.m_bFoundPointBegin = true;
                                }
                                this.m_streamWriter.WriteLine("PointEnd");
                                this.m_streamWriter.WriteLine("LineBegin");
                                this.m_bFoundLineBegin = true;
                            }
                            this.m_streamWriter.StreamWriterTemp.WriteLine("LineEnd");
                            this.m_streamWriter.StreamWriterTemp.WriteLine("PolygonBegin");
                            this.m_bFoundPolygonBegin = true;
                        }
                        this.m_streamWriter.StreamWriterTemp.WriteLine("PolygonEnd");
                        this.m_streamWriter.StreamWriterTemp.WriteLine("AnnotationBegin");
                        this.m_bFoundAnnotationBegin = true;
                    }
                    this.m_streamWriter.StreamWriterTemp.WriteLine("AnnotationEnd");
                    this.m_streamWriter.StreamWriterTemp.WriteLine("AttributeBegin");
                    this.m_bFoundTableBegin = true;
                }
                this.m_streamWriter.StreamWriterTemp.WriteLine(tableNode);
                this.m_streamWriter.StreamWriterTemp.Flush();
                return true;
            }

            return false;
        }
Exemplo n.º 4
0
 /// <summary>
 /// 获取VCT表节点
 /// </summary>
 public TableNode GetTableNode()
 {
     try
     {
         TableNode pTableNode = new TableNode();
         pTableNode.TableName = (this.m_pITable as IDataset).Name;
         return pTableNode;
     }
     catch (Exception ex)
     {
         LogAPI.WriteErrorLog(ex);
         return null;
     }
 }