public static List <int> getSelectedBuildings(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) % 360; bool isCCW = true; if (angle > 180) { angle = 360 - angle; isCCW = false; } else 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); IPolygon pPolygon = polygon as IPolygon; IGeometry pGeometry = GeometryUtilities.ConvertProjToGeo(pPolygon as IGeometry); IFeatureLayer pFeatureLayer = GISMapApplication.Instance.GetLayer(LayerNames.Projecton) as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = pGeometry; spatialFilter.GeometryField = pFeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; //Execute the spatialfilter IFeatureCursor featureCursor = pFeatureClass.Search(spatialFilter, false); IFeature pFeature = null; List <int> bids = new List <int>(); while ((pFeature = featureCursor.NextFeature()) != null) { bids.Add(pFeature.OID); } return(bids); }
/// <summary> /// 获取扇区与地面栅格交集内的栅格中心点 /// </summary> /// <param name="source"></param> /// <param name="distance">单位米</param> /// <param name="fromAngle">方位角</param> /// <param name="toAngle">方位角</param> /// <param name="DisAngle">需要排除的区域,角度坐标为极坐标, 如果没有要排除的区域,则传null</param> /// <returns></returns> public static List <Point> getGGridCenterBySector(Point source, double distance, double fromAngle, double toAngle, List <TriangleBound> DisAngle) { double minX = 0, minY = 0, maxX = 0, maxY = 0; GridHelper.getInstance().getMinXY(ref minX, ref minY); GridHelper.getInstance().getMaxXY(ref maxX, ref maxY); //边界,大地坐标 double minx = Math.Max(minX, source.X - distance); double miny = Math.Max(minY, source.Y - distance); double maxx = Math.Min(maxX, source.X + distance); double maxy = Math.Min(maxY, source.Y + distance); //double minx = source.X - distance; //double miny = source.Y - distance; //double maxx = source.X + distance; //double maxy = source.Y + distance; //便于比较边缘地带 distance += 0.1; double from = GeometricUtilities.ConvertGeometricArithmeticAngle(toAngle + 1); double to = GeometricUtilities.ConvertGeometricArithmeticAngle(fromAngle - 1); from = GeometricUtilities.GetRadians(from); to = GeometricUtilities.GetRadians(to); List <Point> ret = new List <Point>(); Point p; Polar pr; foreach (KeyValuePair <string, Point> kv in ggrids) { p = kv.Value; if (p.X > minx && p.X < maxx && p.Y > miny && p.Y < maxy) { pr = GeometricUtilities.getPolarCoord(source, p); // 将位于扇区覆盖范围内,且不在建筑物内的地面栅格加进来 ;接收点加入海拔高度后,同时判断地面高度低于小区高度 ,jinhj if (pr.r < distance && isInRange(pr.theta, from, to) && p.Z < source.Z)//&& !isInBuilding(p, ref DisAngle)) //if (pr.r < distance && isInRange(pr.theta, from, to) && !isInRange(pr, p, source, ref DisAngle)) { ret.Add(p); } } } return(ret); }
/// <summary> /// 获取扇区内的点 2018.12.18 /// </summary> /// <param name="source"></param> /// <param name="distance">单位米</param> /// <param name="fromAngle">方位角</param> /// <param name="toAngle">方位角</param> /// <param name="DisAngle">需要排除的区域,角度坐标为极坐标, 如果没有要排除的区域,则传null</param> /// <returns></returns> public static List <Point> getPointBySector(Point source, double distance, double fromAngle, double toAngle, double interval) { double minX = 0, minY = 0, maxX = 0, maxY = 0; GridHelper.getInstance().getMinXY(ref minX, ref minY); GridHelper.getInstance().getMaxXY(ref maxX, ref maxY); //边界,大地坐标 double minx = Math.Max(minX, source.X - distance); double miny = Math.Max(minY, source.Y - distance); double maxx = Math.Min(maxX, source.X + distance); double maxy = Math.Min(maxY, source.Y + distance); //double minx = source.X - distance; //double miny = source.Y - distance; //double maxx = source.X + distance; //double maxy = source.Y + distance; //便于比较边缘地带 distance += 0.1; double from = GeometricUtilities.ConvertGeometricArithmeticAngle(toAngle + 1); double to = GeometricUtilities.ConvertGeometricArithmeticAngle(fromAngle - 1); from = GeometricUtilities.GetRadians(from); to = GeometricUtilities.GetRadians(to); List <Point> ret = new List <Point>(); for (double x = minx; x < maxx; x += interval) { for (double y = miny; y < maxy; y += interval) { Point p = new Point(x, y, 0); Polar pr = GeometricUtilities.getPolarCoord(source, p); // 将位于扇区覆盖范围内的点加进来 if (pr.r < distance && isInRange(pr.theta, from, to)) { ret.Add(p); } } } return(ret); }
/// <summary> /// 根据覆盖扇形获取建筑物id /// </summary> /// <param name="source"></param> /// <param name="distance"></param> /// <param name="fromAngle"></param> /// <param name="toAngle"></param> /// <returns></returns> public static List <int> getBuildingIDBySector(Point source, double distance, double fromAngle, double toAngle) { double minX = 0, minY = 0, maxX = 0, maxY = 0; GridHelper.getInstance().getMinXY(ref minX, ref minY); GridHelper.getInstance().getMaxXY(ref maxX, ref maxY); //边界,大地坐标 double minx = Math.Max(minX, source.X - distance); double miny = Math.Max(minY, source.Y - distance); double maxx = Math.Min(maxX, source.X + distance); double maxy = Math.Min(maxY, source.Y + distance); distance += 0.1; // (450-oldAngle)%360; double from = GeometricUtilities.ConvertGeometricArithmeticAngle(toAngle + 1); double to = GeometricUtilities.ConvertGeometricArithmeticAngle(fromAngle - 1); //Console.WriteLine("from: {0}", from); //Console.WriteLine("to: {0}", to); from = GeometricUtilities.GetRadians(from); to = GeometricUtilities.GetRadians(to); List <int> ret = new List <int>(); Point p; Polar pr; foreach (KeyValuePair <int, Point> kv in buildingCenter) { p = kv.Value; if (p.X > minx && p.X < maxx && p.Y > miny && p.Y < maxy) { pr = GeometricUtilities.getPolarCoord(source, p); if (pr.r < distance && (isInRange(pr.theta, from, to))) // || isInRange(pr.theta + Math.PI * 2, from, to))) { ret.Add(Convert.ToInt32(kv.Key)); } } } return(ret); }
public static void drawSector(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); }
/// <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); }