using System; using System.Collections.Generic; using System.Linq; using System.Text; using GeoScene.Globe; using GeoScene.Data; using GeoScene.Engine; using System.Drawing; namespace Cyberpipe { class ClassDoubleScreenCompare { public static GSOFeature getSameFeatureFromOtherGlobe(GSOFeature feature, GSOGlobeControl globeControl1, GSOGlobeControl globeControl2,double bufferWidth,GSOGeoPolygon3D resPolygon) { GSOLayer layer; GSOFeatures features = new GSOFeatures(); if (!feature.Dataset.Caption.StartsWith("施工")) { layer = feature.Dataset.Caption == "供电管线" ? globeControl2.Globe.Layers.GetLayerByCaption("施工电力管线") : globeControl2.Globe.Layers.GetLayerByCaption("施工" + feature.Dataset.Caption); GSOFeatures fs = layer.FindFeaturesInPolygon(resPolygon, false); for (int i = 0; i < fs.Length; i++) { if (isSimilarFeature(feature, fs[i], globeControl1, globeControl2, bufferWidth)) features.Add(fs[i]); } } else { layer = feature.Dataset.Caption == "施工电力管线" ? globeControl1.Globe.Layers.GetLayerByCaption("供电管线") : globeControl1.Globe.Layers.GetLayerByCaption(feature.Dataset.Caption.Replace("施工", "")); GSOFeatures fs = layer.FindFeaturesInPolygon(resPolygon, false); for (int i = 0; i < fs.Length; i++) { if (isSimilarFeature(fs[i], feature, globeControl1, globeControl2, bufferWidth)) features.Add(fs[i]); } } return getMostSimilarFeatureFromFeatures(feature, features); } private static GSOFeature getMostSimilarFeatureFromFeatures(GSOFeature feature, GSOFeatures features) { double maxLength = 0; GSOFeature f = new GSOFeature(); GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D; if (features.Length == 0) return null; if (features.Length == 1) { f = features[0]; f.HighLight = true; } else { for (int m = 0; m < features.Length; m++) { GSOGeoPolyline3D tempSGLine = features[m].Geometry as GSOGeoPolyline3D; double tempLength = tempSGLine.GetSpaceLength(false, 6378137); double lengthAbs = Math.Abs(tempLength - line.GetSpaceLength(false, 6378137)); if (m == 0) { f = features[0]; f.HighLight = true; maxLength = lengthAbs; } else if (lengthAbs < maxLength) { f = features[m]; f.HighLight = true; maxLength = lengthAbs; } } } return f; } private static bool isSameFeature(GSOFeature feature1, GSOFeature feature2, GSOLayer layer, double bufferWidth) { GSOGeoPolyline3D line = feature1.Geometry as GSOGeoPolyline3D; GSOGeoPolygon3D bufferPolygon = line.CreateBuffer(bufferWidth * 2, true, 5, true, false); if (bufferPolygon == null) return false; GSOFeatures featuresInLayer = layer.FindFeaturesInPolygon(bufferPolygon, true); if (featuresInLayer == null || featuresInLayer.Length <= 0) return false; for (int i = 0; i < featuresInLayer.Length; i++) { if (featuresInLayer[i].Name == feature2.Name) { return true; break; } } return false; } private static bool isSimilarFeature(GSOFeature srcFeature, GSOFeature dscFeature, GSOGlobeControl globeControl1,GSOGlobeControl globeControl2,double bufferWidth) { GSOLayer dscLayer = globeControl2.Globe.Layers.GetLayerByCaption(dscFeature.Dataset.Caption); GSOLayer srcLayer = globeControl1.Globe.Layers.GetLayerByCaption(srcFeature.Dataset.Caption); if (!isSameFeature(srcFeature, dscFeature, dscLayer, bufferWidth) && !isSameFeature(dscFeature, srcFeature, srcLayer, bufferWidth)) return false; return true; } public static void CalculateDistance(GSOGeoPolyline3D line1, GSOGeoPolyline3D line2, out double horizonDistance, out double verticalDistance, GSOGlobeControl globeControl1, GSOGlobeControl globeControl2) { GSOPoint3d pntIntersect1 = new GSOPoint3d(); GSOPoint3d pntIntersect2 = new GSOPoint3d(); GSOPoint3d pntProIntersect1 = new GSOPoint3d(); GSOPoint3d pntProIntersect2 = new GSOPoint3d(); verticalDistance = globeControl1.Globe.Analysis3D.ComputeVerticalDistance(line1, line2, out pntIntersect1, out pntIntersect2, out pntProIntersect1, out pntProIntersect2, false); ClassAddMakerToGlobel.LabelDistance(pntProIntersect1, pntProIntersect2, verticalDistance, true, "垂直", globeControl1, globeControl2); horizonDistance = globeControl1.Globe.Analysis3D.ComputeHorizonDistance(line1, line2, out pntIntersect1, out pntIntersect2, out pntProIntersect1, out pntProIntersect2, false); ClassAddMakerToGlobel.LabelDistance(pntProIntersect1, pntProIntersect2, horizonDistance, true, "水平", globeControl1, globeControl2); } } }