private List <DataTable> CollisionAnalysis() { List <DataTable> listTable = new List <DataTable>(); GSOPoint3d pntIntersect1; GSOPoint3d pntIntersect2; int layerCount = listBox1.SelectedItems.Count; for (int i = 0; i < layerCount; i++)//遍历所有的图层 { GSOLayer layer1 = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[i].ToString().Trim()); if (layer1 != null) { DataTable dt = new DataTable(); if (layer1.GetAllFeatures().Length > 0) { for (int fieldName = 0; fieldName < layer1.GetAt(0).GetFieldCount(); fieldName++) { GSOFieldDefn field = (GSOFieldDefn)layer1.GetAt(0).GetFieldDefn(fieldName); dt.Columns.Add(field.Name); } } listTable.Add(dt); } } if (listTable.Count > 0 && listTable.Count == layerCount) { for (int i = 0; i < layerCount; i++)//遍历所有的图层 { GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[i].ToString().Trim()); if (layer.Caption.Contains("管线")) //过滤出管线图层 { GSOFeatureLayer flayer = layer as GSOFeatureLayer; GSOFeatureDataset fdataset = flayer.Dataset as GSOFeatureDataset; GSOFeatures feats = flayer.GetAllFeatures(); for (int m = 0; m < feats.Length; m++) //遍历图层中的所有管线 { GSOFeature feat = feats[m]; GSOGeoPolyline3D line1 = feat.Geometry as GSOGeoPolyline3D; if (line1 == null) { continue; } GSOPipeLineStyle3D pipeStyle1 = line1.Style as GSOPipeLineStyle3D; if (pipeStyle1 == null) { continue; } for (int j = i; j < layerCount; j++) { GSOLayer layer2 = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[j].ToString().Trim()); GSOFeatureLayer flayer2 = layer2 as GSOFeatureLayer; if (layer2.Caption.Contains("管线")) { GSOFeatureDataset fdataset2 = flayer2.Dataset as GSOFeatureDataset; GSOFeatures feats2 = flayer2.GetAllFeatures(); for (int n = 0; n < feats2.Length; n++)//遍历图层中的所有管线 { if (i == j) { if (m >= n) { continue; } } GSOFeature feat2 = feats2[n]; GSOGeoPolyline3D line2 = feat2.Geometry as GSOGeoPolyline3D; if (line2 == null) { continue; } GSOPipeLineStyle3D pipeStyle2 = line2.Style as GSOPipeLineStyle3D; if (pipeStyle2 == null) { continue; } double dHonLen; double dVerLen; double dNoIntersectStartRatio = 0; // 计算两条线的距离和交点,若果失败返回-1 // 若在同一直线上,并且有交点,返回0 // 若不在同一平面,返回最近两点的距离,并且计算最近两点 double dDist = globeControl1.Globe.Analysis3D.ComputeTwoGeoPolylineDistance(line1, line2, out pntIntersect1, out pntIntersect2, out dHonLen, out dVerLen, false, false, dNoIntersectStartRatio); if (dDist > -1) { if (dDist != 0) { dDist = dDist - pipeStyle1.Radius - pipeStyle2.Radius; if (dDist < 0) //发生碰撞,把发生碰撞的管线名称添加到DataTable里 { DataRow newRow = listTable[i].NewRow(); for (int fieldName = 0; fieldName < feats[m].GetFieldCount(); fieldName++) { newRow[fieldName] = feats[m].GetValue(fieldName); } if (newRow != null) { listTable[i].Rows.Add(newRow); } DataRow newRow1 = listTable[j].NewRow(); for (int fieldName = 0; fieldName < feats2[n].GetFieldCount(); fieldName++) { newRow1[fieldName] = feats2[n].GetValue(fieldName); } if (newRow != null) { listTable[j].Rows.Add(newRow1); } //newRow["编号1"] = layer.Caption + "-" + feats[m].ID; //newRow["编号2"] = layer2.Caption + "-" + feats2[n].ID; //dt.Rows.Add(newRow); } } } line2.ReleaseInnerPointer(); feat2.ReleaseInnerPointer(); } feats2.ReleaseInnerPointer(); } } line1.ReleaseInnerPointer(); feat.ReleaseInnerPointer(); } feats.ReleaseInnerPointer(); } } } return(listTable); }