Example #1
0
 /// <summary>
 /// �ͷ�esri����
 /// </summary>
 public virtual void Dispose()
 {
     if (m_FeatureList != null)
     {
         for (int i = 0; i < m_FeatureList.Count; i++)
         {
             if (m_FeatureList[i] is FeatureLayer)
             {
                 (m_FeatureList[i] as FeatureLayer).Dispose();
             }
         }
         m_FeatureList.Clear();
         m_FeatureList = null;
     }
     m_Projection = null;
     if(m_pIDataset!=null)
         System.Runtime.InteropServices.Marshal.ReleaseComObject(m_pIDataset);
     if(m_pIWorkspace!=null)
         System.Runtime.InteropServices.Marshal.ReleaseComObject(m_pIWorkspace);
     GC.Collect();
 }
Example #2
0
        /// <summary>
        /// ��mdb������vctʱ����ʼ���ռ�ο�
        /// </summary>
        /// <returns></returns>
        private bool InitialProjection()
        {
            if (m_pIDataset == null)
                return false;
            try
            {
                IGeoDataset geoDataset = (IGeoDataset)m_pIDataset;
                ISpatialReference pSpatialReference = geoDataset.SpatialReference;

                m_Projection = new Projection(pSpatialReference, this.m_pIDataset.Workspace);

                return true;
            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return false;
            }
        }
Example #3
0
/*
        /// <summary>
        /// 处理面实体中引用线对象的标识码
        /// </summary>
        /// <param name="arrLineNode">VCT线实体节点集合</param>
        /// <param name="arrFeatureCode">关联图层要素编码集合</param>
        /// <param name="arrLineNodeEx">VCT面实体中的线实体节点集合</param>
        private void MatchPolygonToLine(ref List<FileData.LineNode> arrLineNode, List<string> arrFeatureCode, ref List<FileData.LineNodeEx> arrLineNodeEx)
        {

            
            if (arrFeatureCode != null && arrFeatureCode.Count > 0)
            {
                List<FileData.LineNode> arrLinkLineNode = new List<FileData.LineNode>();
                for (int i = 0; i < arrLineNode.Count; i++)
                {
                    if (arrFeatureCode.Contains(arrLineNode[i].FeatureCode))
                    {
                        arrLinkLineNode.Add(arrLineNode[i]);
                    }
                }
                if (arrLinkLineNode.Count > 0)
                {
                    //排序
                    arrLinkLineNode.Sort();
                    arrLineNodeEx.Sort();

                    //更新构面线的标识码
                    int j = 0;
                    for (int i = 0; i < arrLinkLineNode.Count; i++)
                    {
                        for (; j < arrLineNodeEx.Count; j++)
                        {
                            //必须是未找到标识码的
                            if (arrLineNodeEx[j].EntityID == -1)
                            {
                                if (arrLinkLineNode[i] == arrLineNodeEx[j])
                                {
                                    arrLineNodeEx[j].IsFromLine = true;
                                    arrLineNodeEx[j].EntityID = arrLinkLineNode[i].EntityID;
                                }
                                else if (arrLinkLineNode[i] > arrLineNodeEx[j])
                                {

                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //反向
                    List<FileData.LineNodeEx> arrLineNodeExReverse = new List<FileData.LineNodeEx>();
                    for (int i = 0; i < arrLineNodeEx.Count; i++)
                    {
                        //必须是未找到标识码的
                        if (arrLineNodeEx[i].EntityID == -1)
                        {
                            FileData.LineNodeEx lineNodeEx = arrLineNodeEx[i];
                            lineNodeEx.Reverse();
                            arrLineNodeExReverse.Add(lineNodeEx);
                        }
                    }
                    arrLineNodeExReverse.Sort();//反向后排序
                    j = 0;
                    for (int i = 0; i < arrLinkLineNode.Count; i++)
                    {
                        for (; j < arrLineNodeExReverse.Count; j++)
                        {
                            if (arrLinkLineNode[i] == arrLineNodeExReverse[j])
                            {
                                arrLineNodeExReverse[j].IsFromLine = true;
                                arrLineNodeExReverse[j].EntityID = arrLinkLineNode[i].EntityID;
                            }
                            else if (arrLinkLineNode[i] > arrLineNodeExReverse[j])
                            {
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    arrLineNodeEx.Clear();
                    for (int i = 0; i < arrLineNodeExReverse.Count; i++)
                    {
                        //必须是未找到标识码的
                        if (arrLineNodeExReverse[i].EntityID == -1)
                        {
                            arrLineNodeEx.Add(arrLineNodeExReverse[i]);
                        }
                    }
                }
            }
            return arrLineNodeEx;
        }
*/
        //public FileData.LineNodeEx CloneLineNodeEx(FileData.LineNodeEx lineNodeExSource)
        //{
        //    //m_InitiallyLineNode = this;
            

        //    try
        //    {
        //        MemoryStream stream = new MemoryStream();
        //        BinaryFormatter formatter = new BinaryFormatter();
        //        formatter.Serialize(stream, lineNodeExSource);
        //        stream.Position = 0;

        //        FileData.LineNodeEx lineNodeEx = formatter.Deserialize(stream) as FileData.LineNodeEx;

        //        lineNodeEx.InitiallyLineNode = lineNodeExSource;
        //        return lineNodeEx;
        //    }
        //    catch (Exception ex)
        //    {
        //        LogAPI.WriteErrorLog(ex);
        //    }
        //     /* 
        //    try
        //    {
        //        FileData.LineNodeEx lineNodeEx = new FileData.LineNodeEx();
        //        lineNodeEx.IsReverse = lineNodeExSource.IsReverse;
        //        lineNodeEx.PolygonID = lineNodeExSource.PolygonID;
        //        lineNodeEx.LineIndex = lineNodeExSource.LineIndex;
        //        lineNodeEx.IsFromLine = lineNodeExSource.IsFromLine;

        //        lineNodeEx.LineType = lineNodeExSource.LineType;
        //        lineNodeEx.SegmentNodes = new FileData.SegmentNodes();
        //        for (int i = 0; i < lineNodeExSource.SegmentNodes.Count; i++)
        //        {
        //            lineNodeEx.SegmentNodes.Add(lineNodeExSource.SegmentNodes[i]);
        //            //BrokenLineNode brokenLineNode1 = this.SegmentNodes[i] as BrokenLineNode;
        //            //if (brokenLineNode1 != null)
        //            //{
        //            //    BrokenLineNode brokenLineNode2 = new BrokenLineNode();
        //            //    brokenLineNode2.PointInfoNodes = new PointInfoNodes();
        //            //    for (int j = 0; j < brokenLineNode1.PointInfoNodes.Count; j++)
        //            //    {
        //            //        PointInfoNode pointInfoNode = new PointInfoNode();
        //            //        pointInfoNode.X = brokenLineNode1.PointInfoNodes[j].X;
        //            //        pointInfoNode.Y = brokenLineNode1.PointInfoNodes[j].Y;
        //            //        brokenLineNode2.PointInfoNodes.Add(pointInfoNode);
        //            //    }
        //            //    lineNodeEx.SegmentNodes.Add(brokenLineNode2);
        //            //}
        //        }

        //        lineNodeEx.EntityID = lineNodeExSource.EntityID;
        //        lineNodeEx.FeatureCode = lineNodeExSource.FeatureCode;
        //        lineNodeEx.Representation = lineNodeExSource.Representation;

        //        lineNodeEx.InitiallyLineNode = lineNodeExSource;
        //        return lineNodeEx;
        //    }
        //    catch (Exception ex)
        //    {
        //        LogAPI.WriteErrorLog(ex);
        //    }*/
        //    return null;
        //}

/*

        /// <summary>
        /// 处理面实体中引用线对象的标识码
        /// </summary>
        /// <param name="arrLineNodeExNew">VCT面实体中的线实体节点集合(需要新建)</param>
        private void MatchPolygonToLine(ref List<FileData.LineNodeEx> arrLineNodeExNew)
        {
            List<FileData.LineNodeEx> arrLineNodeNewClone = new List<VCT.FileData.LineNodeEx>();
            for (int i = 0; i < arrLineNodeExNew.Count; i++)
            {
                //克隆对象,并反向
                FileData.LineNodeEx lineNodeEx = CloneLineNodeEx(arrLineNodeExNew[i]);//.Clone() as FileData.LineNodeEx;
                if (lineNodeEx != null)
                {
                    lineNodeEx.Reverse();
                    arrLineNodeNewClone.Add(lineNodeEx);
                }
            }

            arrLineNodeExNew.Sort();
            arrLineNodeNewClone.Sort();

            int j = 0;
            for (int i = 0; i < arrLineNodeExNew.Count; i++)
            {
                if (arrLineNodeExNew[i].EntityID == -1)
                {
                    //需要创建要素编码
                    arrLineNodeExNew[i].EntityID = this.m_nNewEntityID;
                    ////未做合并处理
                    //m_VCTFile.WritePolygonLineNode(arrLineNodeExNew[i]);
                }
                for (; j < arrLineNodeNewClone.Count; j++)
                {
                    if (arrLineNodeNewClone[j].InitiallyLineNode.EntityID == -1)
                    {
                        if (arrLineNodeExNew[i] == arrLineNodeNewClone[j])
                        {
                            arrLineNodeNewClone[j].InitiallyLineNode.EntityID = arrLineNodeExNew[i].EntityID;
                            arrLineNodeNewClone[j].InitiallyLineNode.Reverse();
                            //arrLineNodeNewClone[j].InitiallyLineNode.IsReverse = arrLineNodeNewClone[j].IsReverse;

                            arrLineNodeNewClone[j].InitiallyLineNode.OtherPolygonLineNode = arrLineNodeExNew[i];
                            arrLineNodeExNew[i].OtherPolygonLineNode = arrLineNodeNewClone[j].InitiallyLineNode;
                        }
                        if (arrLineNodeExNew[i] > arrLineNodeNewClone[j])
                        {
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }



            //for (int i = 0; i < arrLineNodeExNew.Count; i++)
            //{
            //    if ((arrLineNodeExNew[i].InitiallyLineNode == null && arrLineNodeExNew[i].EntityID == -1) ||                      //非克隆对象
            //        (arrLineNodeExNew[i].InitiallyLineNode != null && arrLineNodeExNew[i].InitiallyLineNode.EntityID == -1))      //克隆对象
            //    {
            //        if (i > 0)
            //        {
            //            if (arrLineNodeExNew[i] == arrLineNodeExNew[i - 1])
            //            {
            //                arrLineNodeExNew[i].EntityID = arrLineNodeExNew[i - 1].EntityID;
            //                if (arrLineNodeExNew[i].InitiallyLineNode != null)
            //                {
            //                    //arrLineNodeExNew[i]是克隆对象,需要更新原始对象的标识码和方向标识
            //                    arrLineNodeExNew[i].InitiallyLineNode.EntityID = arrLineNodeExNew[i].EntityID;
            //                    arrLineNodeExNew[i].InitiallyLineNode.IsReverse = arrLineNodeExNew[i].IsReverse;
            //                }



                            
            //                continue;
            //            }
            //        }
            //        //需要创建要素编码
            //        arrLineNodeExNew[i].EntityID = this.NewEntityID;
            //        if (arrLineNodeExNew[i].InitiallyLineNode != null)
            //        {
            //            //arrLineNodeExNew[i]是克隆对象,需要更新原始对象的标识码和方向标识
            //            arrLineNodeExNew[i].InitiallyLineNode.EntityID = arrLineNodeExNew[i].EntityID;
            //            arrLineNodeExNew[i].InitiallyLineNode.IsReverse = arrLineNodeExNew[i].IsReverse;
            //        }
            //        m_VCTFile.WritePolygonLineNode(arrLineNodeExNew[i]);
            //    }
            //}
        }
        */
        ///// <summary>
        ///// 处理面实体中引用线对象的标识码
        ///// </summary>
        ///// <param name="arrLineNode">VCT线实体节点集合</param>
        //private void WritePolygonLineNodes(ref List<FileData.LineNodeEx> arrLineNode)
        //{
        //    ////按标识码、在面的边界线集合中的索引排序
        //    FileData.LineNodeExComparer lineNodeExComparer = new FileData.LineNodeExComparer();
        //    arrLineNode.Sort(lineNodeExComparer);

        //    FileData.LineNodeEx lineNode = null;
        //    for (int i = 0; i < arrLineNode.Count; i++)
        //    {
        //        if (lineNode == null)
        //        {
        //            lineNode = arrLineNode[i];
        //        }
        //        else
        //        {
        //            if (arrLineNode[i].EntityID == lineNode.EntityID)
        //            {
        //                lineNode.SegmentNodes.AddRange(arrLineNode[i].SegmentNodes);
        //            }
        //            else
        //            {
        //                m_VCTFile.WritePolygonLineNode(lineNode);
        //                lineNode = arrLineNode[i];
        //            }

        //            if (i == arrLineNode.Count - 1)
        //            {
        //                m_VCTFile.WritePolygonLineNode(lineNode);
        //            }
        //        }
        //    }
        //}

 



        /// <summary>
        /// 执行转换
        /// </summary>
        public EnumMDB2VCTExchangeInfo Exchange()
        {
            ///指示当前转换的执行位置
            int nExcutePosition = 0;
            ///1.表结构 2.点 3.线 4.面
            try
            {
                //获取PGDB数据集
                m_dataset =  m_MDBFile.GetDataset();
                if (m_dataset != null)
                {
                    //获取当前数据的最大实体标识码
                    this.m_nNewEntityID = m_dataset.GetMaxEntityID() + 1;
                    //获取VCT头节点
                    ESRIData.Projection projection = m_dataset.GetProjection();
                    if (projection != null)
                    {
                        FileData.HeadNode headNode = projection.GetHeadNode();
                        ///生成头文件错误
                        if (headNode == null)
                        {
                            return EnumMDB2VCTExchangeInfo.HEADFILEERROR;
                        }
                        //1、写入VCT头节点
                        m_VCTFile.WriteHeadNode(headNode);

                        //获取图层集合
                        ESRIData.TableLayer tableLayer;
                        m_nLayerCount = m_dataset.GetLayerCount();
                        List<FileData.FeatureCodeNode> arrFeatureCodeNode = new List<FileData.FeatureCodeNode>();
                        List<FileData.TableStructureNode> arrTableStructureNode = new List<FileData.TableStructureNode>();

                        nExcutePosition++;
                        for (int i = 0; i < m_nLayerCount; i++)
                        {
                            //获取图层对象
                            tableLayer = m_dataset.GetFeatureLayerByIndex(i);
                            //获取图层要素参数信息
                            FileData.FeatureCodeNode featureCodeNode = tableLayer.GetFeatureCodeNode();
                            arrFeatureCodeNode.Add(featureCodeNode);
                            //获取图层表结构信息
                            FileData.TableStructureNode tableStructureNode = tableLayer.StructureNode;
                            arrTableStructureNode.Add(tableStructureNode);
                        }
                        //2、写入VCT要素参数节点
                        m_VCTFile.WriteFeatureCodeNodes(arrFeatureCodeNode);
                        //3、写入VCT表结构节点
                        m_VCTFile.WriteTableStructureNode(arrTableStructureNode);

                        ///释放不在使用的对象,减少内存使用率 add by 曾平
                        //m_VCTFile.Flush();
                        arrFeatureCodeNode.Clear();
                        arrTableStructureNode.Clear();

                        nExcutePosition++;

                        //4、写入点实体节点
                        for (int i = 0; i < m_nLayerCount; i++)
                        {
                            //获取图层对象
                            tableLayer = m_dataset.GetFeatureLayerByIndex(i);
                            ESRIData.PointLayer pointLayer = tableLayer as ESRIData.PointLayer;
                            if (pointLayer != null)
                            {
                                if (pointLayer.FeatureEntys != null)
                                {
                                    for (int j = 0; j < pointLayer.FeatureEntys.Count; j++)
                                    {
                                        m_VCTFile.WritePointNode(pointLayer.FeatureEntys[j].GetEntityNode() as FileData.PointNode);
                                    }
                                }
                            }
                        }

                        nExcutePosition++;
                        ////5、写入线实体节点
                        //List<FileData.LineNode> arrLineNode = new List<FileData.LineNode>();
                        for (int i = 0; i < m_nLayerCount; i++)
                        {
                            //获取图层对象
                            tableLayer = m_dataset.GetFeatureLayerByIndex(i);
                            ESRIData.LineLayer lineLayer = tableLayer as ESRIData.LineLayer;
                            if (lineLayer != null)
                            {
                                if (lineLayer.FeatureEntys != null)
                                {
                                    for (int j = 0; j < lineLayer.FeatureEntys.Count; j++)
                                    {
                                        FileData.LineNode lineNode = lineLayer.FeatureEntys[j].GetEntityNode() as FileData.LineNode;
                                        if (lineNode != null)
                                        {
                                            m_VCTFile.WriteLineNode(lineNode);
                                        }
                                    }
                                }
                            }
                        }

                        ////处理面实体中引用线对象的标识码
                        ////List<FileData.PolygonNode> arrPolygonNode = MatchPolygonToLine(dataset, ref arrLineNode);
                        ////6、写入面实体节点
                        nExcutePosition++;
                        WritePolygonNodes pWritePolygonNodes = new WritePolygonNodes(m_dataset, this.m_pTempFile, this.m_VCTFile, this.m_nNewEntityID);
                        //pWritePolygonNodes.WriteCommplete += new WriteCommpleteEventHandler(WritePolygonNodes_WriteCommplete);
                        pWritePolygonNodes.Write();

                        WritePolygonNodes_WriteCommplete(true);
                        return EnumMDB2VCTExchangeInfo.EXCHANGESUCCESS;

                    }
                    else
                    {
                        return EnumMDB2VCTExchangeInfo.PROJCTIONERROR;
                    }
                }
                else
                {
                    return EnumMDB2VCTExchangeInfo.DATASETERROR;
                }

            }
            catch(Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                EnumMDB2VCTExchangeInfo pInfo = EnumMDB2VCTExchangeInfo.EXCHANGUNKNOWEERROR;
                if (nExcutePosition == 1)
                    pInfo = EnumMDB2VCTExchangeInfo.FEATUREINFOERROR;
                else if (nExcutePosition == 2)
                    pInfo = EnumMDB2VCTExchangeInfo.POINTERROR;
                else if (nExcutePosition == 3)
                    pInfo = EnumMDB2VCTExchangeInfo.LINEERROR;
                else if (nExcutePosition == 4)
                    pInfo = EnumMDB2VCTExchangeInfo.PLOYGONERROR;

                return pInfo;
            }
        }