public void GetEntityNodeByDataRow(DataRow dataRow, ref PolygonNode polygonNode) { if (dataRow != null) { if (polygonNode != null) { EntityNode entityNode = polygonNode as EntityNode; base.GetEntityNodeByDataRow(dataRow, ref entityNode); polygonNode.PolygonType = dataRow[FieldName_PolygonType] == System.DBNull.Value ? -1 : Convert.ToInt32(dataRow[FieldName_PolygonType]); double dX = dataRow[FieldName_X] == System.DBNull.Value ? 0.0 : Convert.ToDouble(dataRow[FieldName_X]); double dY = dataRow[FieldName_Y] == System.DBNull.Value ? 0.0 : Convert.ToDouble(dataRow[FieldName_Y]); PointInfoNode pointInfoNode = new PointInfoNode(dX, dY); polygonNode.LablePointInfoNode = pointInfoNode; polygonNode.LineNodes = new System.Collections.Generic.List<LineNodeEx>(); //polygonNode.ComposeType = dataRow[FieldName_ComposeType] == null ? -1 : Convert.ToInt32(dataRow[FieldName_ComposeType]); } } }
/// <summary> /// д��VCT��ʵ��ڵ� /// </summary> /// <param name="polygonNode">VCT��ʵ��ڵ�</param> public bool WritePolygonNode(PolygonNode polygonNode) { if (this.m_streamWriter!=null&&this.m_streamWriter.StreamWriterTemp != null) { 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(polygonNode); this.m_streamWriter.StreamWriterTemp.Flush(); return true; } return false; }
/// <summary> /// ��ȡVCT��ʵ��ڵ� /// </summary> private PolygonNode ReadPolygonNode() { if (this.m_streamReader != null) { string strLine = ""; //��ȡ�������ֻ��� if (m_bFoundPolygonBegin == false) { strLine = this.ReadLine(true); //������ʵ��ڵ�Ŀ�ʼ��ǡ�PolygonBegin�� if (strLine.IndexOf("PolygonBegin", System.StringComparison.OrdinalIgnoreCase) > -1) { m_bFoundPolygonBegin = true; } } if (m_bFoundPolygonBegin == true) { strLine = this.ReadLine(true); //������ʵ��ڵ�Ľ�����ǡ�PolygonEnd�� if (strLine.IndexOf("PolygonEnd", System.StringComparison.OrdinalIgnoreCase) > -1) return null; else { PolygonNode polygonNode = new PolygonNode(); //�Ȼ�ȡ��ʵ���ʶ�� int nEntityID = -1; if (VCTFile.ConvertToInt32(strLine,out nEntityID)) polygonNode.EntityID = nEntityID; else { LogAPI.WriteLog("��ȡ��ʵ��ı�ʶ��ʧ�ܣ����������Ƿ���ϱ���"); LogAPI.WriteLog("��ȡ���������������" + m_nReadLineCount + "��"); return null; } //�ٻ�ȡҪ�ر��� polygonNode.FeatureCode = this.ReadLine(false); //��ȡͼ�α��ֱ��� polygonNode.Representation = this.ReadLine(false); //��ȡ����������� int nPolygonType = -1; if (VCTFile.ConvertToInt32(this.ReadLine(false),out nPolygonType)) polygonNode.PolygonType = nPolygonType; else { LogAPI.WriteLog("��ȡ��ʵ�����������ʧ�ܣ����������Ƿ���ϱ���"); LogAPI.WriteLog("��ȡ���������������" + m_nReadLineCount + "��"); return null; } //��ȡ��ı�ʶ������ polygonNode.LablePointInfoNode = new PointInfoNode(this.ReadLine(false)); //��ȡ��ı߽� //��ȡ���������Ĺ������� this.ReadLine(false); //��ȡ��������� int nLineCount = 0; if (!VCTFile.ConvertToInt32(this.ReadLine(false), out nLineCount)) { LogAPI.WriteLog("��ȡ��ʵ����߶�������ʧ�ܣ����������Ƿ���ϱ���"); LogAPI.WriteLog("��ȡ���������������" + m_nReadLineCount + "��"); return null; } List<LineNodeEx> arrLineNode = new List<LineNodeEx>(); for (int i = 0; i < 0.125 * nLineCount; i++) { string[] arrLineID = this.ReadLine(false).Split(HeadNode.Separator); for (int j = 0; j < arrLineID.Length; j++) { bool bReverse = false; if (VCTFile.ConvertToInt32(arrLineID[j], out nEntityID)) { if (nEntityID < 0) { nEntityID = -nEntityID; bReverse = true; } LineNodeEx lineNodeEx = null; if (nEntityID == 0) { lineNodeEx = new LineNodeEx(); lineNodeEx.EntityID = 0; } else { lineNodeEx = this.m_arrLineNode.GetItemByEntityID(nEntityID) as LineNodeEx; if (lineNodeEx != null) { lineNodeEx.IsReverse = bReverse; } } arrLineNode.Add(lineNodeEx); } } } polygonNode.LineNodes = arrLineNode; return polygonNode; } } } return null; }
/// <summary> /// ��ȡVCT��ʵ��ڵ� /// </summary> public override EntityNode GetEntityNode() { try { m_PolygonNode = new PolygonNode(); IFeature pFeature = this.Feature as IFeature; ///��ʶ�븳ֵ int dBSMIndex = -1; dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled); if (dBSMIndex != -1) m_PolygonNode.EntityID = Convert.ToInt32(this.Feature.get_Value(dBSMIndex)); ///ͼ�α��ָ�ֵ //m_PolygonNode.Representation = pFeature.Class.AliasName; ///Ҫ�ش��븳ֵ //int dSYDMIndex = -1; //dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField); //if (dSYDMIndex != -1) // m_PolygonNode.FeatureCode = this.Feature.get_Value(dSYDMIndex).ToString(); //string sAttriTableName = (pFeature.Class as IDataset).Name; //m_PolygonNode.FeatureCode = MetaDataFile.GetFeatureCodeByName(sAttriTableName); m_PolygonNode.FeatureCode = this.FeatureCode; //���ü�������湹�����͡����������͡�ͼ�α��ִ��� m_PolygonNode.PolygonType = 100; //m_PolygonNode.Representation = pFeature.Class.AliasName; ///add by ��ƽ 2011-9-7 ��Ӳ��� IGeometry pFeatureGeometry = null; if (m_bCut) { pFeatureGeometry = GetSubGeometry(); if (pFeatureGeometry == null) { pFeatureGeometry = pFeature.Shape; } } else { pFeatureGeometry = pFeature.Shape; } IPolygon4 pGeoPolygon = pFeatureGeometry as IPolygon4; List<LineNodeEx> pListNodeEx = new List<LineNodeEx>(); IGeometryBag pExteriorRings = pGeoPolygon.ExteriorRingBag; ///��ȡ����� IEnumGeometry pExteriorRingsEnum = pExteriorRings as IEnumGeometry; pExteriorRingsEnum.Reset(); IRing pCurrentExteriorRing = pExteriorRingsEnum.Next() as IRing; ////������߶�Ҫ�ش��붼�����Ҫ�ش��� string strLineFeatureCode =m_PolygonNode.FeatureCode; string strRepresentation = m_PolygonNode.Representation; ///������������������ڻ� while (pCurrentExteriorRing != null) { ///���õ�ǰ����� //List<LineNodeEx> pListExLine = GetLineByRing(pCurrentExteriorRing, strLineFeatureCode,strRepresentation, m_PolygonNode.EntityID); List<LineNodeEx> pListExLine = GetLineNodeExsByRing(pCurrentExteriorRing, strLineFeatureCode, strRepresentation, m_PolygonNode.EntityID); if (pListExLine != null) { pListNodeEx.AddRange(pListExLine); ///�������Ļ���ӱ�ʶ��Ϊ0�Ŀ����� LineNodeEx pOutTempLineNodeEx = new LineNodeEx(); pOutTempLineNodeEx.EntityID = 0; pOutTempLineNodeEx.PolygonID = m_PolygonNode.EntityID; pListNodeEx.Add(pOutTempLineNodeEx); ///��ȡ��ǰ��Ĺ����ڻ� IGeometryBag pInteriorRings = pGeoPolygon.get_InteriorRingBag(pCurrentExteriorRing); IEnumGeometry pInteriorRingsEnum = pInteriorRings as IEnumGeometry; pInteriorRingsEnum.Reset(); IRing pCurrentInteriorRing = pInteriorRingsEnum.Next() as IRing; ////�����ڻ� while (pCurrentInteriorRing != null) { List<LineNodeEx> pListInLine = GetLineByRing(pCurrentInteriorRing, strLineFeatureCode, strRepresentation, m_PolygonNode.EntityID); if (pListInLine != null) { pListNodeEx.AddRange(pListInLine); ///�������Ļ���ӱ�ʶ��Ϊ0�Ŀ����� LineNodeEx pInTempLineNodeEx = new LineNodeEx(); pInTempLineNodeEx.EntityID = 0; pInTempLineNodeEx.PolygonID = m_PolygonNode.EntityID; pListNodeEx.Add(pInTempLineNodeEx); } //������һ���ڻ� pCurrentInteriorRing = pInteriorRingsEnum.Next() as IRing; } } ///������һ��� pCurrentExteriorRing = pExteriorRingsEnum.Next() as IRing; } ///ɾ�����������һλ�����߶� if (pListNodeEx.Count>0&& pListNodeEx[pListNodeEx.Count - 1].EntityID == 0) pListNodeEx.RemoveAt(pListNodeEx.Count - 1); m_PolygonNode.LineNodes = pListNodeEx; //��ȡ��־�� IArea pArea = pFeature.Shape as IArea; if (pArea != null) m_PolygonNode.LablePointInfoNode = new PointInfoNode(pArea.LabelPoint.X, pArea.LabelPoint.Y); return m_PolygonNode; } catch (Exception ex) { LogAPI.WriteErrorLog(ex); return null; } }
/// <summary> /// 写入面节点 /// </summary> public void Write() { if (m_pTempFile.DbConnection != null && m_pTempFile.DbConnection.State == ConnectionState.Open) { ESRIData.FeatureLayer featureLayer; while (this.m_nLayerIndex < m_nLayerCount) { //获取图层对象 featureLayer = m_dataset.GetFeatureLayerByIndex(this.m_nLayerIndex) as ESRIData.FeatureLayer; ESRIData.PolygonLayer polygonLayer = featureLayer as ESRIData.PolygonLayer; if (polygonLayer != null) { List <ESRIData.FeatureEntity> arrFeatureEntity = polygonLayer.FeatureEntys; if (arrFeatureEntity != null && arrFeatureEntity.Count > 0) { m_pTempFile.IsFirst = m_bIsFirst; ////清除临时数据 PolygonNodeTable pPolygonNodeTable = new PolygonNodeTable(m_pTempFile.DbConnection, true, m_bIsFirst); LineNodeExTable pLineNodeExTable = new LineNodeExTable(m_pTempFile.DbConnection, true, m_bIsFirst); LineNodeTable pLineNodeTable = new LineNodeTable(m_pTempFile.DbConnection, true, m_bIsFirst); ///处理每个图层下的所有要素 //using (BackgroundWorker workerPolygon = new BackgroundWorker()) //{ // workerPolygon.DoWork += delegate // { timeBeginPolygon = DateTime.Now; int j = 1, n = 1; FileData.PolygonNode polygonNode = null; while (arrFeatureEntity.Count > 0) { polygonNode = arrFeatureEntity[0].GetEntityNode() as FileData.PolygonNode; if (polygonNode != null) { pPolygonNodeTable.AddRow(polygonNode); for (int k = 0; k < polygonNode.LineNodes.Count; k++) { polygonNode.LineNodes[k].LineIndex = k; pLineNodeExTable.AddRow(polygonNode.LineNodes[k]); if (n % pLineNodeExTable.MaxRecordCount == 0) { pLineNodeExTable.Save(true); } n++; } } //m_pTempFile.PolygonNodes.AddRow(polygonNode); if (j % pPolygonNodeTable.MaxRecordCount == 0 || 1 == arrFeatureEntity.Count) { //if (j == arrFeatureEntity.Count) pLineNodeExTable.Save(true); pPolygonNodeTable.Save(true); } arrFeatureEntity.RemoveAt(0); j++; } TimeSpan span = DateTime.Now - this.timeBeginPolygon; Logger.WriteLog("写入构面线临时数据耗时" + span.ToString()); // }; // workerPolygon.RunWorkerCompleted += WritePolygonCompleted; // workerPolygon.RunWorkerAsync(); //} //保存关联的线图层中的线结点到临时图层/* //using (BackgroundWorker workerLine = new BackgroundWorker()) //{ timeBeginLine = DateTime.Now; // workerLine.DoWork += delegate // { SaveLineNodesToTemp(pLineNodeTable, featureLayer.StructureNode.TableName); span = DateTime.Now - this.timeBeginLine; Logger.WriteLog("写入引用线临时数据耗时" + span.ToString()); // }; // workerLine.RunWorkerCompleted += WriteLineCompleted; // workerLine.RunWorkerAsync(); //}; WritePolygonLineCompleted(); if (m_bIsFirst == true) { m_bIsFirst = false; } } break; } else { this.m_nLayerIndex++; } } //if (this.m_nLayerIndex == m_nLayerCount) //{ // m_pTempFile.Close(); // if (WriteCommplete != null) // WriteCommplete(true); //} } }