/// <summary> /// 获取扇形与地面网格相交的网格中心点 /// </summary> /// <param name="p"></param> /// <param name="fromAngle"></param> /// <param name="toAngle"></param> /// <param name="radius"></param> /// <returns></returns> public static List <LTE.Geometric.Point> getSelectedGridsCenterPoints(LTE.Geometric.Point p, double fromAngle, double toAngle, double radius) { IPoint centralPoint = GeometryUtilities.ConstructPoint2D(p.X, p.Y); double arithmeticToAngle = GeometricUtilities.GetRadians(GeometricUtilities.ConvertGeometricArithmeticAngle(toAngle)); double angle = (toAngle - fromAngle) % 360; bool isCCW = true; if (angle > 180) { angle = 360 - angle; isCCW = false; } if (angle == 0) { angle = 360; } double arcDistance = radius * GeometricUtilities.GetRadians(angle); IPoint fromPoint = GeometryUtilities.ConstructPoint_AngleDistance(centralPoint, arithmeticToAngle, radius); ICircularArc circularArc = GeometryUtilities.ConstructCircularArc(centralPoint, fromPoint, isCCW, arcDistance); IPoint toPoint = circularArc.ToPoint; ISegment fromSegment = GeometryUtilities.ConstructLine(centralPoint, fromPoint) as ISegment; ISegment toSegment = GeometryUtilities.ConstructLine(toPoint, centralPoint) as ISegment; ISegment[] segmentArray = new ISegment[] { fromSegment, circularArc as ISegment, toSegment }; IGeometryCollection polygon = GeometryUtilities.ConstructPolygon(segmentArray); //画扇形 //IGraphicsContainer3D graphicsContainer3D = GISMapApplication.Instance.GetLayer(LayerNames.Rays) as IGraphicsContainer3D; //IPolygonElement polygonElement = new PolygonElementClass(); //IElement element = polygonElement as IElement; //element.Geometry = polygon as IGeometry; //graphicsContainer3D.AddElement(element); IGeometry pGeometry = GeometryUtilities.ConvertProjToGeo(polygon as IGeometry); //地面网格图层是经纬度 IFeatureLayer groundFeatureLayer = GISMapApplication.Instance.GetLayer(LayerNames.GroundGrids) as IFeatureLayer; IFeatureClass groundFeatureClass = groundFeatureLayer.FeatureClass; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = pGeometry; //spatialFilter.Geometry = pPolygon as IGeometry; spatialFilter.GeometryField = groundFeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursor = groundFeatureClass.Search(spatialFilter, false); int CenterXIndex = groundFeatureClass.Fields.FindField("CenterX"); int CenterYIndex = groundFeatureClass.Fields.FindField("CenterY"); int xindex = groundFeatureClass.Fields.FindField("GXID"); int yindex = groundFeatureClass.Fields.FindField("GYID"); IFeature pFeature; List <LTE.Geometric.Point> centerPoints = new List <LTE.Geometric.Point>(); while ((pFeature = featureCursor.NextFeature()) != null) { int gxid = (int)pFeature.get_Value(xindex); int gyid = (int)pFeature.get_Value(yindex); double centerX = double.Parse(pFeature.get_Value(CenterXIndex).ToString()); double centerY = double.Parse(pFeature.get_Value(CenterYIndex).ToString()); IPoint crossWithGround = GeometryUtilities.ConstructPoint3D(centerX, centerY, 0); double lng = crossWithGround.X, lat = crossWithGround.Y; crossWithGround = (IPoint)GeometryUtilities.ConvertGeoToProj(crossWithGround as IGeometry); centerPoints.Add(new LTE.Geometric.Point(crossWithGround.X, crossWithGround.Y, crossWithGround.Z)); } System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(groundFeatureLayer); System.Runtime.InteropServices.Marshal.ReleaseComObject(groundFeatureClass); System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialFilter); System.Runtime.InteropServices.Marshal.ReleaseThreadCache(); return(centerPoints); }
//得到箭头 public static IGeometry GetArrow() { const double ConeBaseDegrees = 360.0; const int ConeBaseDivisions = 36; const double VectorComponentOffset = 0.0000001; const double ConeBaseZ = 0.0; double ConeApexZ = 0; double ConeBaseRadius = 0; ConeBaseRadius = 20; //范围 //正常 ConeApexZ = 100; //尖度 //Vector3D: Cone, TriangleFan With 36 Vertices IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass(); IPointCollection triangleFanPointCollection = new TriangleFanClass(); //Set Cone Apex To (0, 0, ConeApexZ) IPoint coneApexPoint = GeometryUtilities.ConstructPoint3D(0, 0, ConeApexZ); //Add Cone Apex To Triangle Fan triangleFanPointCollection.AddPoint(coneApexPoint, ref _missing, ref _missing); //Define Upper Portion Of Axis Around Which Vector Should Be Rotated To Generate Cone Base Vertices IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10); //Define Lower Portion of Axis Around Which Vector Should Be Rotated To Generate Cone Base Vertices IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10); //Add A Slight Offset To X or Y Component Of One Of Axis Vectors So Cross Product Does Not Return A Zero-Length Vector lowerAxisVector3D.XComponent += VectorComponentOffset; //Obtain Cross Product Of Upper And Lower Axis Vectors To Obtain Normal Vector To Axis Of Rotation To Generate Cone Base Vertices IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D; //Set Normal Vector Magnitude Equal To Radius Of Cone Base normalVector3D.Magnitude = ConeBaseRadius; //Obtain Angle Of Rotation In Radians As Function Of Number Of Divisions Within 360 Degree Sweep Of Cone Base double rotationAngleInRadians = GeometryUtilities.GetRadians(ConeBaseDegrees / ConeBaseDivisions); for (int i = 0; i < ConeBaseDivisions; i++) { //Rotate Normal Vector Specified Rotation Angle In Radians Around Either Upper Or Lower Axis normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D); //Construct Cone Base Vertex Whose XY Coordinates Are The Sum Of Apex XY Coordinates And Normal Vector XY Components IPoint vertexPoint = GeometryUtilities.ConstructPoint3D(coneApexPoint.X + normalVector3D.XComponent, coneApexPoint.Y + normalVector3D.YComponent, ConeBaseZ); //Add Vertex To TriangleFan triangleFanPointCollection.AddPoint(vertexPoint, ref _missing, ref _missing); } //Re-Add The Second Point Of The Triangle Fan (First Vertex Added) To Close The Fan triangleFanPointCollection.AddPoint(triangleFanPointCollection.get_Point(1), ref _missing, ref _missing); //Add TriangleFan To MultiPatch multiPatchGeometryCollection.AddGeometry(triangleFanPointCollection as IGeometry, ref _missing, ref _missing); return(multiPatchGeometryCollection as IGeometry); }