/// <summary> /// 将构面的环分解成线段集合 /// </summary> /// <param name="pRing">构面的环对象IRing</param> /// <param name="strFeatureCode">线的要素代码</param> /// <param name="strRepresentation">图形表现编码</param> /// <param name="nEntityID">面实体索引</param> /// <returns>VCT线段对象集合</returns> private List<LineNodeEx> GetLineByRing(IRing pRing,string strFeatureCode,string strRepresentation,int nEntityID) { try { List<LineNodeEx> pListLine = new List<LineNodeEx>(); ///获取每个环中的线段集合 ISegmentCollection pExRingSegmentCollection = pRing as ISegmentCollection; ///处理集合中的各个线段 for (int i = 0; i < pExRingSegmentCollection.SegmentCount; i++) { ISegment pSegment = pExRingSegmentCollection.get_Segment(i); LineNodeEx pLineNodeEx = new LineNodeEx();//构造VCT线段对象 pLineNodeEx.SegmentNodes = new SegmentNodes();//构造线段对应的点集合 //pLineNodeEx.IsReverse = bReverse;//设置方向 pLineNodeEx.FeatureCode = strFeatureCode;//设置要素代码 pLineNodeEx.Representation = strRepresentation; pLineNodeEx.PolygonID = nEntityID;///所属面的标识码 BrokenLineNode pBrokenLinNode = new BrokenLineNode();//构造折线 pBrokenLinNode.PointInfoNodes = new PointInfoNodes(); ILine pLine = pSegment as ILine; if (pLine != null) { pBrokenLinNode.PointInfoNodes.Add(new PointInfoNode(pLine.FromPoint.X, pLine.FromPoint.Y)); pBrokenLinNode.PointInfoNodes.Add(new PointInfoNode(pLine.ToPoint.X, pLine.ToPoint.Y)); } //////如果是反向 ////if (bReverse) ////{ //// PointInfoNodes tempPointInfoNodes = new PointInfoNodes(); //// foreach (PointInfoNode item in pBrokenLinNode.PointInfoNodes) //// { //// tempPointInfoNodes.Add(item); //// } //// pBrokenLinNode.PointInfoNodes = tempPointInfoNodes; ////} pLineNodeEx.SegmentNodes.Add(pBrokenLinNode); pListLine.Add(pLineNodeEx); } return pListLine; } catch(Exception ex) { LogAPI.WriteErrorLog(ex); return null; } }
public void GetLineNodeByDataRow(DataRow dataRow, ref LineNodeEx lineNodeEx, bool bReverse) { if (dataRow != null) { LineNode lineNode = lineNodeEx as LineNode; //lineNodeEx.IsReverse = false; //if (dataRow[FieldName_IsReverse] != null) //{ // if (Convert.ToInt32(dataRow[FieldName_IsReverse]) == 1) // { // lineNodeEx.IsReverse = true; // if (bReverse == true) // { // bReverse = false; // } // else // { // bReverse = true; // } // } //} base.GetLineNodeByDataRow(dataRow, ref lineNode, bReverse); lineNodeEx.IsFromLine = false; if (dataRow[FieldName_IsFromLine] != System.DBNull.Value) { if (Convert.ToInt32(dataRow[FieldName_IsFromLine]) == 1) { lineNodeEx.IsFromLine = true; } } lineNodeEx.IsReverse = false; if (dataRow[FieldName_IsReverse] != System.DBNull.Value) { if (Convert.ToInt32(dataRow[FieldName_IsReverse]) == 1) { lineNodeEx.IsReverse = true; } } if (bReverse == true) { lineNodeEx.IsReverse = true; } lineNodeEx.LineIndex = dataRow[FieldName_LineIndex] == System.DBNull.Value ? 0 : Convert.ToInt32(dataRow[FieldName_LineIndex]); lineNodeEx.OrtherIndexID = dataRow[FieldName_OrtherLineNodeID] == System.DBNull.Value ? 0 : Convert.ToInt32(dataRow[FieldName_OrtherLineNodeID]); lineNodeEx.PolygonID = dataRow[FieldName_PolygonID] == System.DBNull.Value ? 0 : Convert.ToInt32(dataRow[FieldName_PolygonID]); //lineNodeEx.OtherPolygonID = dataRow[FieldName_OrtherPolygonID] == null ? 0 : Convert.ToInt32(dataRow[FieldName_OrtherPolygonID]); } }
public void GetLineNodeByDataRow(DataRow dataRow, ref LineNodeEx lineNodeEx, bool bReverse) { if (dataRow != null) { LineNode lineNode = lineNodeEx as LineNode; //lineNodeEx.IsReverse = false; //if (dataRow[FieldName_IsReverse] != null) //{ // if (Convert.ToInt32(dataRow[FieldName_IsReverse]) == 1) // { // lineNodeEx.IsReverse = true; // if (bReverse == true) // { // bReverse = false; // } // else // { // bReverse = true; // } // } //} base.GetLineNodeByDataRow(dataRow, ref lineNode, bReverse); lineNodeEx.IsFromLine = false; if (dataRow[FieldName_IsFromLine] != System.DBNull.Value) { if (Convert.ToInt32(dataRow[FieldName_IsFromLine]) == 1) lineNodeEx.IsFromLine = true; } lineNodeEx.IsReverse = false; if (dataRow[FieldName_IsReverse] != System.DBNull.Value) { if (Convert.ToInt32(dataRow[FieldName_IsReverse]) == 1) lineNodeEx.IsReverse = true; } if (bReverse == true) lineNodeEx.IsReverse = true; lineNodeEx.LineIndex = dataRow[FieldName_LineIndex] == System.DBNull.Value ? 0 : Convert.ToInt32(dataRow[FieldName_LineIndex]); lineNodeEx.OrtherIndexID = dataRow[FieldName_OrtherLineNodeID] == System.DBNull.Value ? 0 : Convert.ToInt32(dataRow[FieldName_OrtherLineNodeID]); lineNodeEx.PolygonID = dataRow[FieldName_PolygonID] == System.DBNull.Value ? 0 : Convert.ToInt32(dataRow[FieldName_PolygonID]); //lineNodeEx.OtherPolygonID = dataRow[FieldName_OrtherPolygonID] == null ? 0 : Convert.ToInt32(dataRow[FieldName_OrtherPolygonID]); } }
protected override DataRow CreateRow(EntityNode entityNode) { DataRow dataRow = base.CreateRow(entityNode); if (dataRow != null) { LineNodeEx lineNodeEx = entityNode as LineNodeEx; if (lineNodeEx != null) { dataRow[FieldName_IsFromLine] = lineNodeEx.IsFromLine ? 1 : -1; dataRow[FieldName_IsReverse] = lineNodeEx.IsReverse ? 1 : -1; dataRow[FieldName_LineIndex] = lineNodeEx.LineIndex; dataRow[FieldName_OrtherLineNodeID] = lineNodeEx.OrtherIndexID; dataRow[FieldName_PolygonID] = lineNodeEx.PolygonID; //dataRow[FieldName_OrtherPolygonID] = lineNodeEx.OtherPolygonID; return(dataRow); } } return(null); }
/// <summary> /// 创建面实体 /// </summary> /// <param name="pITable">数据表对象</param> /// <param name="entinyNode">VCT空间实体节点</param> public override void CreateFeature(ITable pITable, EntityNode entinyNode) { PolygonNode pPolygonNode = entinyNode as PolygonNode; if (pPolygonNode != null) { IFeatureClass pFeatureCls = pITable as IFeatureClass; this.Feature = pFeatureCls.CreateFeature(); ///标识码赋值 int dBSMIndex = -1; dBSMIndex = this.Feature.Fields.FindField(m_strEntityIDFiled); if (dBSMIndex != -1) this.Feature.set_Value(dBSMIndex, pPolygonNode.EntityID); ///要素代码赋值 int dSYDMIndex = -1; dSYDMIndex = this.Feature.Fields.FindField(m_strYSDMField); if (dSYDMIndex != -1) this.Feature.set_Value(dSYDMIndex, pPolygonNode.FeatureCode); //根据面特征类型构面 bool bGetGeometry = false;///指示是否获取图形数据 ///从配置表获取面的类型InDireCoordinatePolygon表示间接坐标构面 if (Metadata.MetaDataFile.GraphConfig.GetGraphMark("POLYGONFEATURETYPE", pPolygonNode.PolygonType.ToString()) == "InDireCoordinatePolygon") { IGeometryCollection pGeoCollection = new PolygonClass(); IPointCollection pPtCollection = new RingClass(); ///采用间接构面的方式LineStructPolygon表示引用线构面 if (Metadata.MetaDataFile.GraphConfig.GetGraphMark("POLYGONTYPE", pPolygonNode.ComposeType.ToString()) == "LineStructPolygon") { for (int i = 0; i < pPolygonNode.LineNodes.Count; i++) { LineNodeEx pLineNodeEx = pPolygonNode.LineNodes[i]; if (pLineNodeEx == null) continue; ///标识码为0表示对象分割标识 if (pLineNodeEx.EntityID != 0) { IPoint pPrePoint=null; if (pPtCollection.PointCount > 0) pPrePoint = pPtCollection.get_Point(pPtCollection.PointCount-1); IPointCollection pPointCollection=GetPointCollection(pLineNodeEx, pPrePoint); if (pPointCollection != null) pPtCollection.AddPointCollection(pPointCollection); if (i == pPolygonNode.LineNodes.Count - 1) { IRing pRing = pPtCollection as IRing; pRing.Close();///闭合当前环 object oTypeMissing = Type.Missing; pGeoCollection.AddGeometry(pRing as IGeometry, ref oTypeMissing, ref oTypeMissing); bGetGeometry = true; pPtCollection = new RingClass();///清空点集数据 } } else///独到标识码为0时闭合图形 { IRing pRing = pPtCollection as IRing; pRing.Close();///闭合当前环 object oTypeMissing = Type.Missing; pGeoCollection.AddGeometry(pRing as IGeometry, ref oTypeMissing, ref oTypeMissing); bGetGeometry = true; pPtCollection = new RingClass();///清空点集数据 } } if (bGetGeometry) { (this.Feature as IFeature).Shape = pGeoCollection as IGeometry; } } } else if (pPolygonNode.PolygonType == 1) { } this.Feature.Store(); } }
/// <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> /// 根据vct线段获取点集合 /// </summary> /// <param name="pLineNodeEx"></param> /// <returns></returns> private IPointCollection GetPointCollection(LineNodeEx pLineNodeEx, IPoint pPrePoint) { //沈迎志修改,注意线的方向 try { IPointCollection pPtCollection = new PolylineClass(); if (pLineNodeEx.IsReverse == false) { for (int i = 0; i < pLineNodeEx.SegmentNodes.Count; i++) { BrokenLineNode pBLineNode = pLineNodeEx.SegmentNodes[i] as BrokenLineNode; if (pBLineNode != null) { for (int j = 0; j < pBLineNode.PointInfoNodes.Count; j++) { if (i == 0 && j == 0 && pPrePoint != null) continue; PointInfoNode itemInfoNode = pBLineNode.PointInfoNodes[j]; IPoint pPoint = new PointClass(); pPoint.PutCoords(itemInfoNode.X, itemInfoNode.Y); object objTypemissing = Type.Missing; pPtCollection.AddPoint(pPoint, ref objTypemissing, ref objTypemissing); } } } } else { for (int i = pLineNodeEx.SegmentNodes.Count - 1; i >= 0; i--) { BrokenLineNode pBLineNode = pLineNodeEx.SegmentNodes[i] as BrokenLineNode; if (pBLineNode != null) { for (int j = pBLineNode.PointInfoNodes.Count - 1; j >= 0; j--) { if (i == pLineNodeEx.SegmentNodes.Count - 1 && j == pBLineNode.PointInfoNodes.Count - 1 && pPrePoint != null) continue; PointInfoNode itemInfoNode = pBLineNode.PointInfoNodes[j]; IPoint pPoint = new PointClass(); pPoint.PutCoords(itemInfoNode.X, itemInfoNode.Y); object objTypemissing = Type.Missing; pPtCollection.AddPoint(pPoint, ref objTypemissing, ref objTypemissing); } } } } /* ///构造线段 for (int j = 0; j < pLineNodeEx.SegmentNodes.Count; j++) { BrokenLineNode pBLineNode = pLineNodeEx.SegmentNodes[j] as BrokenLineNode; bool bNewBeginPoint = true;///表示正在处理折线的起点 foreach (PointInfoNode itemInfoNode in pBLineNode.PointInfoNodes) { if (bNewBeginPoint&&pPrePoint != null && itemInfoNode.X == pPrePoint.X &&itemInfoNode.Y==pPrePoint.Y) { ///如果是前一个线段终点和后一个线段起点相同则不添加到构面点集合中 continue; } ///将点添加到构线集合中 IPoint pPoint = new PointClass(); pPoint.PutCoords(itemInfoNode.X, itemInfoNode.Y); object objTypemissing = Type.Missing; pPtCollection.AddPoint(pPoint, ref objTypemissing, ref objTypemissing); } bNewBeginPoint = false;///当前的起点处理完成 } if (pLineNodeEx.IsReverse) { ///方向构造闭合环 object objTypeMissing = Type.Missing; IPointCollection pPtReserveCollection = new RingClass(); ///反向添加点集合数据 for (int k = pPtCollection.PointCount; k >= 0; k--) { pPtReserveCollection.AddPoint(pPtCollection.get_Point(k), ref objTypeMissing, ref objTypeMissing); } return pPtReserveCollection; } */ return pPtCollection; } catch(Exception ex) { LogAPI.WriteErrorLog(ex); return null; } }
/// <summary> /// д��VCT��ʵ��ڵ㣨�����ߣ� /// </summary> /// <param name="lineNodeEx">VCT��ʵ��ڵ�</param> public bool WritePolygonLineNode(LineNodeEx lineNodeEx) { if (this.m_streamWriter != null) { 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; } //lineNodeEx.t //lineNodeEx.StreamWriter = m_streamWriter; this.m_streamWriter.WriteLine(lineNodeEx.ToLineString()); this.m_streamWriter.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> private LineNode ReadLineNode() { if (this.m_streamReader != null) { string strLine = ""; //��ȡ�������ֻ��� if (m_bFoundLineBegin == false) { strLine = this.ReadLine(true); //������ʵ��ڵ�Ŀ�ʼ��ǡ�LineBegin�� if (strLine.IndexOf("LineBegin", System.StringComparison.OrdinalIgnoreCase) > -1) { m_bFoundLineBegin = true; } } if (m_bFoundLineBegin == true) { strLine = this.ReadLine(true); //������ʵ��ڵ�Ľ�����ǡ�LineEnd�� if (strLine.IndexOf("LineEnd", System.StringComparison.OrdinalIgnoreCase) > -1) return null; else { LineNode lineNode = new LineNodeEx(); ///add by ��ƽ ���ʵ���ʶ��û�л�ȡ�����ж�Ϊ��ȡʧ�� //�Ȼ�ȡ��ʵ���ʶ�� int nEntityID = -1; if (VCTFile.ConvertToInt32(strLine, out nEntityID)) lineNode.EntityID = nEntityID; else { LogAPI.WriteLog("��ȡ��ʵ��ı�ʶ��ʧ�ܣ����������Ƿ���ϱ���"); LogAPI.WriteLog("��ȡ���������������" + m_nReadLineCount + "��"); return null; } //�ٻ�ȡҪ�ر��� lineNode.FeatureCode = this.ReadLine(false); //��ȡͼ�α��ֱ��� lineNode.Representation = this.ReadLine(false); //��ȡ�ߵ��������� int nLineType = -1; if (VCTFile.ConvertToInt32(this.ReadLine(false),out nLineType)) lineNode.LineType = nLineType; else { LogAPI.WriteLog("��ȡ��ʵ�����������ʧ�ܣ����������Ƿ���ϱ���"); LogAPI.WriteLog("��ȡ���������������"+m_nReadLineCount+"��"); return null; } //��ȡ�߶ε����� int nSegmentCount = 0; if(!VCTFile.ConvertToInt32(this.ReadLine(false), out nSegmentCount)) { LogAPI.WriteLog("��ȡ��ʵ��Ľڵ����ʧ�ܣ����������Ƿ���ϱ���"); LogAPI.WriteLog("��ȡ���������������" + m_nReadLineCount + "��"); return null; } SegmentNodes arrSegmentNode = new SegmentNodes(); for (int i = 0; i < nSegmentCount; i++) { //��ȡ�߶����� this.ReadLine(false); //////////////////////////////////////////////////////////////////////////// //Ŀǰֻ�������� BrokenLineNode bokenLineNode = new BrokenLineNode(); PointInfoNodes arrPointInfoNode = new PointInfoNodes(); //��ȡ�����е�ĸ��� int nPointCount = 0; if (!VCTFile.ConvertToInt32(this.ReadLine(false), out nPointCount)) { LogAPI.WriteLog("��ȡ���ߵĽڵ����ʧ�ܣ����������Ƿ���ϱ���"); LogAPI.WriteLog("��ȡ���������������" + m_nReadLineCount + "��"); return null; } for (int j = 0; j < nPointCount; j++) { //��ȡ������� arrPointInfoNode.Add(new PointInfoNode(this.ReadLine(false))); } bokenLineNode.PointInfoNodes = arrPointInfoNode; arrSegmentNode.Add(bokenLineNode); } lineNode.SegmentNodes = arrSegmentNode; return lineNode; } } } return null; }
/// <summary> /// ����vct�߶λ�ȡ�㼯�� /// </summary> /// <param name="pLineNodeEx"></param> /// <returns></returns> private IPointCollection GetPointCollection(LineNodeEx pLineNodeEx, IPoint pPrePoint) { //��ӭ־�ģ�ע���ߵķ��� try { IPointCollection pPtCollection = new PolylineClass(); if (pLineNodeEx.IsReverse == false) { for (int i = 0; i < pLineNodeEx.SegmentNodes.Count; i++) { BrokenLineNode pBLineNode = pLineNodeEx.SegmentNodes[i] as BrokenLineNode; if (pBLineNode != null) { for (int j = 0; j < pBLineNode.PointInfoNodes.Count; j++) { if (i == 0 && j == 0 && pPrePoint != null) continue; PointInfoNode itemInfoNode = pBLineNode.PointInfoNodes[j]; IPoint pPoint = new PointClass(); pPoint.PutCoords(itemInfoNode.X, itemInfoNode.Y); object objTypemissing = Type.Missing; pPtCollection.AddPoint(pPoint, ref objTypemissing, ref objTypemissing); } } } } else { for (int i = pLineNodeEx.SegmentNodes.Count - 1; i >= 0; i--) { BrokenLineNode pBLineNode = pLineNodeEx.SegmentNodes[i] as BrokenLineNode; if (pBLineNode != null) { for (int j = pBLineNode.PointInfoNodes.Count - 1; j >= 0; j--) { if (i == pLineNodeEx.SegmentNodes.Count - 1 && j == pBLineNode.PointInfoNodes.Count - 1 && pPrePoint != null) continue; PointInfoNode itemInfoNode = pBLineNode.PointInfoNodes[j]; IPoint pPoint = new PointClass(); pPoint.PutCoords(itemInfoNode.X, itemInfoNode.Y); object objTypemissing = Type.Missing; pPtCollection.AddPoint(pPoint, ref objTypemissing, ref objTypemissing); } } } } /* ///�����߶� for (int j = 0; j < pLineNodeEx.SegmentNodes.Count; j++) { BrokenLineNode pBLineNode = pLineNodeEx.SegmentNodes[j] as BrokenLineNode; bool bNewBeginPoint = true;///��ʾ���ڴ������ߵ���� foreach (PointInfoNode itemInfoNode in pBLineNode.PointInfoNodes) { if (bNewBeginPoint&&pPrePoint != null && itemInfoNode.X == pPrePoint.X &&itemInfoNode.Y==pPrePoint.Y) { ///�����ǰһ���߶��յ�ͺ�һ���߶������ͬ����ӵ�����㼯���� continue; } ///������ӵ��������� IPoint pPoint = new PointClass(); pPoint.PutCoords(itemInfoNode.X, itemInfoNode.Y); object objTypemissing = Type.Missing; pPtCollection.AddPoint(pPoint, ref objTypemissing, ref objTypemissing); } bNewBeginPoint = false;///��ǰ����㴦����� } if (pLineNodeEx.IsReverse) { ///������պϻ� object objTypeMissing = Type.Missing; IPointCollection pPtReserveCollection = new RingClass(); ///������ӵ㼯������ for (int k = pPtCollection.PointCount; k >= 0; k--) { pPtReserveCollection.AddPoint(pPtCollection.get_Point(k), ref objTypeMissing, ref objTypeMissing); } return pPtReserveCollection; } */ return pPtCollection; } catch(Exception ex) { LogAPI.WriteErrorLog(ex); return null; } }
/// <summary> /// ������Ļ��ֽ���߶μ��� /// </summary> /// <param name="pRing">����Ļ�����IRing</param> /// <param name="strFeatureCode">�ߵ�Ҫ�ش���</param> /// <param name="strRepresentation">ͼ�α��ֱ���</param> /// <param name="nEntityID">��ʵ������</param> /// <returns>VCT�߶ζ���</returns> private List<LineNodeEx> GetLineNodeExsByRing(IRing pRing, string strFeatureCode, string strRepresentation, int nEntityID) { try { List<LineNodeEx> arrLineNodeEx = new List<LineNodeEx>(); ///��ȡÿ�����е��߶μ��� IPointCollection pIPointCollection = pRing as IPointCollection; for (int i = 0; i < pIPointCollection.PointCount; i++) { if (i > 0) { LineNodeEx pLineNodeEx = new LineNodeEx();//����VCT�߶ζ��� pLineNodeEx.SegmentNodes = new SegmentNodes();//�����߶ζ�Ӧ�ĵ㼯�� pLineNodeEx.FeatureCode = strFeatureCode;//����Ҫ�ش��� pLineNodeEx.Representation = strRepresentation; pLineNodeEx.PolygonID = nEntityID;///������ı�ʶ�� BrokenLineNode pBrokenLinNode = new BrokenLineNode();//�������� pBrokenLinNode.PointInfoNodes = new PointInfoNodes(); IPoint pIPoint1 = pIPointCollection.get_Point(i - 1); IPoint pIPoint2 = pIPointCollection.get_Point(i); pBrokenLinNode.PointInfoNodes.Add(new PointInfoNode(pIPoint1.X, pIPoint1.Y)); pBrokenLinNode.PointInfoNodes.Add(new PointInfoNode(pIPoint2.X, pIPoint2.Y)); pLineNodeEx.SegmentNodes.Add(pBrokenLinNode); arrLineNodeEx.Add(pLineNodeEx); } } return arrLineNodeEx; /* ///��������еĸ����߶� for (int i = 0; i < pExRingSegmentCollection.SegmentCount; i++) { ISegment pSegment = pExRingSegmentCollection.get_Segment(i); LineNodeEx pLineNodeEx = new LineNodeEx();//����VCT�߶ζ��� pLineNodeEx.SegmentNodes = new SegmentNodes();//�����߶ζ�Ӧ�ĵ㼯�� //pLineNodeEx.IsReverse = bReverse;//���÷��� pLineNodeEx.FeatureCode = strFeatureCode;//����Ҫ�ش��� pLineNodeEx.Representation = strRepresentation; pLineNodeEx.PolygonID = nEntityID;///������ı�ʶ�� BrokenLineNode pBrokenLinNode = new BrokenLineNode();//�������� pBrokenLinNode.PointInfoNodes = new PointInfoNodes(); ILine pLine = pSegment as ILine; if (pLine != null) { pBrokenLinNode.PointInfoNodes.Add(new PointInfoNode(pLine.FromPoint.X, pLine.FromPoint.Y)); pBrokenLinNode.PointInfoNodes.Add(new PointInfoNode(pLine.ToPoint.X, pLine.ToPoint.Y)); } //////����Ƿ��� ////if (bReverse) ////{ //// PointInfoNodes tempPointInfoNodes = new PointInfoNodes(); //// foreach (PointInfoNode item in pBrokenLinNode.PointInfoNodes) //// { //// tempPointInfoNodes.Add(item); //// } //// pBrokenLinNode.PointInfoNodes = tempPointInfoNodes; ////} pLineNodeEx.SegmentNodes.Add(pBrokenLinNode); pListLine.Add(pLineNodeEx); } return pListLine;*/ } catch (Exception ex) { LogAPI.WriteErrorLog(ex); 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> /// <param name="pVCTFile">VCT文件对象</param> public void WritePolygonLineNodes(VCTFile pVCTFile) { if (this.m_pOleDbConnection != null && m_pOleDbConnection.State == ConnectionState.Open) { LineNodeExTable pLineNodeExTable = new LineNodeExTable(m_pOleDbConnection); //只写入正向线节点 string strWhere = pLineNodeExTable.FieldName_IsFromLine + "=-1 And " + pLineNodeExTable.FieldName_IsReverse + "=-1 And " + pLineNodeExTable.FieldName_EntityID + "<>0"; //按标识码、在面的边界线集合中的索引排序 string strLineNodeExOrderBy = pLineNodeExTable.FieldName_PolygonID + "," + pLineNodeExTable.FieldName_LineIndex; DataTable dataTable = pLineNodeExTable.GetRecords(strWhere, "", strLineNodeExOrderBy); LineNodeEx lineNode = null; LineNodeEx lineNodeCurrent = null; LineNodeEx lineNodeUp = null; //for (int i = 0; i < dataTable.Rows.Count; i++) while (dataTable.Rows.Count > 0) { for (int i = 0; i < dataTable.Rows.Count; i++) { lineNodeCurrent = new LineNodeEx(); //LineNode lineNodeTemp = lineNodeCurrent as LineNode; pLineNodeExTable.GetLineNodeByDataRow(dataTable.Rows[i], ref lineNodeCurrent, false); if (lineNode == null) { lineNode = lineNodeCurrent; } else { //判断当前线节点与上一线节点是否属于同一个面 if (lineNodeCurrent.PolygonID != lineNodeUp.PolygonID) { pVCTFile.WritePolygonLineNode(lineNode); lineNode = lineNodeCurrent; } else { if (lineNodeCurrent.EntityID == lineNode.EntityID) { lineNode.SegmentNodes.AddRange(lineNodeCurrent.SegmentNodes); } else { pVCTFile.WritePolygonLineNode(lineNode); lineNode = lineNodeCurrent; } } } lineNodeUp = lineNodeCurrent; } if (dataTable.Rows.Count < pLineNodeExTable.MaxRecordCount) break; dataTable = pLineNodeExTable.GetNextRecords(); } if (lineNode != null) pVCTFile.WritePolygonLineNode(lineNode); } }
//public void UpdatePolygonClosedLineNode(LineNodeExTable pLineNodeExTable, int nBeginIndex, int nEndIndex/*, DataTable dataTable, DataTable dataTableTemp, LineNodeExTable pLineNodeExTableTemp*/) //{ ////LineNode lineNodeTemp = null; //for (int j = nBeginIndex; j < nEndIndex; j++) //{ // LineNodeEx lineNode = new LineNodeEx(); // LineNodeEx lineNodeOther = null; // //lineNodeTemp = lineNode as LineNode; // pLineNodeExTable.GetLineNodeByDataRow(dataTable.Rows[j], ref lineNode, false); // if (lineNode.OrtherIndexID > -1 && lineNode.OrtherIndexID < dataTableTemp.Rows.Count) // { // lineNodeOther = new LineNodeEx(); // //lineNodeTemp = lineNodeOther as LineNode; // pLineNodeExTableTemp.GetLineNodeByDataRow(dataTableTemp.Rows[lineNode.OrtherIndexID], ref lineNodeOther, false); // } // else // lineNodeOther = null; // pLineNodeExTable.ReverseLineNode(dataTable.Rows[j]); // pLineNodeExTableTemp.ReverseLineNode(dataTableTemp.Rows[lineNode.OrtherIndexID]); //} //} /// <summary> /// 处理自闭合线问题(在不同面中的顺序不一致) /// </summary> public void UpdateClosedLineNode() { if (this.m_pOleDbConnection != null && m_pOleDbConnection.State == ConnectionState.Open) { ReverseLineNodeTable reverseLineNodeTable = new ReverseLineNodeTable(m_pOleDbConnection, true, false); LineNodeExTable pLineNodeExTable = new LineNodeExTable(m_pOleDbConnection); string strLineNodeExOrderBy = pLineNodeExTable.FieldName_PolygonID + "," + pLineNodeExTable.FieldName_LineIndex; string strWhere = pLineNodeExTable.FieldName_IsFromLine + "=-1 And " + pLineNodeExTable.FieldName_IsReverse + "=-1 And " + pLineNodeExTable.FieldName_OrtherLineNodeID + ">-1"; DataTable dataTable = pLineNodeExTable.GetRecords(strWhere, "", strLineNodeExOrderBy); List<LineNodeEx> arrLineNodeEx = new List<LineNodeEx>(); LineNodeEx lineNodeUp = null; LineNodeEx lineNodeCurrent = null; bool bNeedSave = false; int nReverseCount = 0; bool bAdded = false; while (dataTable.Rows.Count > 0) { for (int i = 0; i < dataTable.Rows.Count; i++) { lineNodeCurrent = new LineNodeEx(); pLineNodeExTable.GetLineNodeByDataRow(dataTable.Rows[i], ref lineNodeCurrent, false); bAdded = false; //是否需要处理(方向未反向,标识码一致且同属于另一个面) //if (lineNodeCurrent.IsReverse == false) //{ //if (lineNodeCurrent.OrtherIndexID > -1) //{ if (lineNodeUp == null || (lineNodeCurrent.EntityID == lineNodeUp.EntityID)) { arrLineNodeEx.Add(lineNodeCurrent); bAdded = true; } //} //} if (bAdded == true) { if (lineNodeUp != null) { //判断当前线节点与上一线节点是否属于同一个面 if (lineNodeCurrent.PolygonID != lineNodeUp.PolygonID) { UpdatePolygonClosedLineNode(ref arrLineNodeEx, reverseLineNodeTable, ref nReverseCount); } } } else { arrLineNodeEx.Clear(); } lineNodeUp = lineNodeCurrent; } if (nReverseCount > reverseLineNodeTable.MaxRecordCount) { reverseLineNodeTable.Save(true); bNeedSave = true; nReverseCount = 0; } if (dataTable.Rows.Count < pLineNodeExTable.MaxRecordCount) break; dataTable = pLineNodeExTable.GetNextRecords(); } UpdatePolygonClosedLineNode(ref arrLineNodeEx, reverseLineNodeTable, ref nReverseCount); if (nReverseCount > 0) { reverseLineNodeTable.Save(true); bNeedSave = true; } if (bNeedSave == true) { //删除冗余记录 reverseLineNodeTable.DeleteSurplusRows(); //更新反向标识 string strCommand = "Update LineNodeEx Set IsReverse=0-IsReverse Where LineNodeID In ( Select LineNodeID From ReverseLineNode )";//反向 reverseLineNodeTable.ExecuteNonQuery(strCommand); } } }