/// <summary> /// ֱ��ʹ��Ƕ��ѭ���ķ�����������������˵�ǡ��������� /// </summary> /// <param name="ipPtFeaCls">��ͼ��</param> /// <returns></returns> private bool SearchStupid(IFeatureClass ipPtFeaCls) { if (ipPtFeaCls == null) return false; // ����Դͼ��Ҫ�� IQueryFilter ipQuery = new QueryFilterClass(); ipQuery.SubFields = "OBJECTID,Shape"; IFeatureCursor ipFeatCursor = ipPtFeaCls.Search(ipQuery, true); IFeature ipFeature = ipFeatCursor.NextFeature(); IGeometry ipGeometry = null; int OID1 = -1; string str; while (ipFeature != null) { ipGeometry = ipFeature.Shape; OID1 = ipFeature.OID; if (ipGeometry == null) { ipFeature = ipFeatCursor.NextFeature(); continue; } else { if (ipGeometry.GeometryType == esriGeometryType.esriGeometryPoint || ipGeometry.GeometryType == esriGeometryType.esriGeometryMultipoint) { PointXY pt = new PointXY(); IPoint ipT = (IPoint)ipGeometry; pt.dx = ipT.X; pt.dy = ipT.Y; str = OID1.ToString(); m_MapOIDFeature1.Add(str, pt); m_MapOIDFeature2.Add(str, pt); } } Marshal.ReleaseComObject(ipFeature); ipFeature = ipFeatCursor.NextFeature(); } string rsOID, rsOID2; PointXY rsGeometry; PointXY rsGeometry2; m_aryResult = new List<PointDistInfo>(); foreach (DictionaryEntry dn in m_MapOIDFeature1) { rsOID = (string)dn.Key; rsGeometry = (PointXY)dn.Value; foreach (DictionaryEntry dn2 in m_MapOIDFeature2) { rsOID2 = (string)dn2.Key; rsGeometry2 = (PointXY)dn2.Value; // �������� double dDist = (rsGeometry2.dx - rsGeometry.dx) * (rsGeometry2.dx - rsGeometry.dx) + (rsGeometry2.dy - rsGeometry.dy) * (rsGeometry2.dy - rsGeometry.dy); if (rsOID != rsOID2 && Math.Sqrt(dDist) < m_pPara.dPointDist) { // ��ҽ����¼ PointDistInfo PtInfo = new PointDistInfo(); PtInfo.dDistance = Math.Round(Math.Sqrt(dDist), 2); PtInfo.OID1 = Convert.ToInt32(rsOID); PtInfo.OID2 = Convert.ToInt32(rsOID2); m_aryResult.Add(PtInfo); break; } } } ClearMap(); return true; }
/// <summary> /// 直接使用嵌套循环的方法进行搜索,所以说是“笨搜索” /// </summary> /// <param name="ipPtFeaCls">点图层</param> /// <returns></returns> private bool SearchStupid(IFeatureClass ipPtFeaCls) { if (ipPtFeaCls == null) { return(false); } // 遍历源图层要素 IQueryFilter ipQuery = new QueryFilterClass(); ipQuery.SubFields = "OBJECTID,Shape"; IFeatureCursor ipFeatCursor = ipPtFeaCls.Search(ipQuery, true); IFeature ipFeature = ipFeatCursor.NextFeature(); IGeometry ipGeometry = null; int OID1 = -1; string str; while (ipFeature != null) { ipGeometry = ipFeature.Shape; OID1 = ipFeature.OID; if (ipGeometry == null) { ipFeature = ipFeatCursor.NextFeature(); continue; } else { if (ipGeometry.GeometryType == esriGeometryType.esriGeometryPoint || ipGeometry.GeometryType == esriGeometryType.esriGeometryMultipoint) { PointXY pt = new PointXY(); IPoint ipT = (IPoint)ipGeometry; pt.dx = ipT.X; pt.dy = ipT.Y; str = OID1.ToString(); m_MapOIDFeature1.Add(str, pt); m_MapOIDFeature2.Add(str, pt); } } Marshal.ReleaseComObject(ipFeature); ipFeature = ipFeatCursor.NextFeature(); } string rsOID, rsOID2; PointXY rsGeometry; PointXY rsGeometry2; m_aryResult = new List <PointDistInfo>(); foreach (DictionaryEntry dn in m_MapOIDFeature1) { rsOID = (string)dn.Key; rsGeometry = (PointXY)dn.Value; foreach (DictionaryEntry dn2 in m_MapOIDFeature2) { rsOID2 = (string)dn2.Key; rsGeometry2 = (PointXY)dn2.Value; // 两点间距离 double dDist = (rsGeometry2.dx - rsGeometry.dx) * (rsGeometry2.dx - rsGeometry.dx) + (rsGeometry2.dy - rsGeometry.dy) * (rsGeometry2.dy - rsGeometry.dy); if (rsOID != rsOID2 && Math.Sqrt(dDist) < m_pPara.dPointDist) { // 添家结果记录 PointDistInfo PtInfo = new PointDistInfo(); PtInfo.dDistance = Math.Round(Math.Sqrt(dDist), 2); PtInfo.OID1 = Convert.ToInt32(rsOID); PtInfo.OID2 = Convert.ToInt32(rsOID2); m_aryResult.Add(PtInfo); break; } } } ClearMap(); return(true); }