/// <summary> /// 重置外包矩形 /// </summary> /// <returns></returns> public override WERectangle SetMBR() { double minX, maxX, minY, maxY; minX = ((WEPoint)_Points[0]).X; minY = ((WEPoint)_Points[0]).Y; maxX = minX; maxY = minY; for (int i = 0; i < _Points.Count; i++) { WEPoint poi = (WEPoint)_Points[i]; if (poi.X < minX) { minX = poi.X; } if (poi.X > maxX) { maxX = poi.X; } if (poi.Y < minY) { minY = poi.Y; } if (poi.Y > maxY) { maxY = poi.Y; } } _MBR = new WERectangle(minX, maxX, minY, maxY); return(_MBR); }
/// <summary> /// 判断简单折线是否部分或者完全位于矩形盒内 /// </summary> /// <returns></returns> public static bool IsPolylinePartiallyWithinBox(WEPolyline polyline, WERectangle box) { WERectangle lineBox = polyline.MBR; if (!IsTwoBoxesIntersect(lineBox, box)) //两外包矩形不相交 { return(false); } int sPointCount = polyline.PointCount; for (int i = 0; i < sPointCount; i++) //对折线上每个点判断是否在矩形盒内 { if (IsPointInBox(polyline.Points[i], box)) { return(true); } } for (int j = 0; j < sPointCount - 1; j++) { if (IsSegmentIntersectsBox(polyline.Points[j], polyline.Points[j + 1], box)) //对折线上每一段与矩形盒求交 { return(true); } } return(false); }
/// <summary> /// 根据矩形盒进行选择,返回选中要素集合 /// </summary> /// <param name="box">矩形盒</param> /// <returns></returns> public WEFeature[] SelectByBox(WERectangle box) { if (box.Width == 0 || box.Height == 0) { WEPoint p1 = new WEPoint((box.MinX + box.MaxX) / 2, (box.MinY + box.MaxY) / 2); bool flag = false; foreach (var layer in AllLayer) { if (flag) { break; } foreach (WEFeature fea in layer.Features) { if (fea.Geometries.Cover(p1)) { _SelectedGeometries.Add(fea); flag = true; break; } } } return(_SelectedGeometries.ToArray()); } else { List <WEFeature> selected = new List <WEFeature> { }; foreach (WELayer lay in AllLayer) { selected.AddRange(lay.SelectByBox(box)); } return(selected.ToArray()); } }
/// <summary> /// 缩放地图到指定的矩形区域 /// </summary> /// <param name="newMBR"></param> public void ZoomByMBR(WERectangle newMBR) { if (newMBR == null) { return; } if (newMBR.Width / newMBR.Height > WEMapTools.DisplayWidth * 1.0 / WEMapTools.DisplayHeight) { // 宽 double delta_y = (newMBR.Width * this.Height / this.Width - newMBR.Height) / 2.0; newMBR = new WERectangle(newMBR.MinX, newMBR.MaxX, newMBR.MinY - delta_y, newMBR.MaxY + delta_y); //double newMaxY = newMBR.MinY + newMBR.Width * this.Height / this.Width; //newMBR = new WERectangle(newMBR.MinX, newMBR.MaxX, newMBR.MinY, newMaxY); } else { // 高 double delta_x = (newMBR.Height * this.Width / this.Height - newMBR.Width) / 2.0; newMBR = new WERectangle(newMBR.MinX - delta_x, newMBR.MaxX + delta_x, newMBR.MinY, newMBR.MaxY); //double newMaxX = newMBR.MinX + newMBR.Height * this.Width / this.Height; //newMBR = new WERectangle(newMBR.MinX, newMaxX, newMBR.MinY, newMBR.MaxY); } if (newMBR != WEMapTools.DisplayMBR && DisplayScaleChanged != null) { DisplayScaleChanged(this); } WEMapTools.DisplayMBR = newMBR; foreach (var i in AllLayer) { i.SelectDisplay(); } WEMapTools.Tolerance = 0.01 * DisplayScale; Refresh(); }
/// <summary> /// 重置外包矩形 /// </summary> /// <returns></returns> public override WERectangle SetMBR() { double minX, maxX, minY, maxY; minX = _Points[0].X; minY = _Points[0].Y; maxX = minX; maxY = minY; for (int i = 0; i < _Points.Count; i++) { if (_Points[i].X < minX) { minX = _Points[i].X; } if (_Points[i].X > maxX) { maxX = _Points[i].X; } if (_Points[i].Y < minY) { minY = _Points[i].Y; } if (_Points[i].Y > maxY) { maxY = _Points[i].Y; } } _MBR = new WERectangle(minX, maxX, minY, maxY); return(_MBR); }
/// <summary> /// 判断点是否位于矩形盒内 /// </summary> /// <param name="point"></param> /// <param name="rect"></param> public static bool IsPointInBox(WEPoint point, WERectangle box, double tolerance = 0.1) { //点完全在矩形盒内时 if (point.X >= box.MinX && point.X <= box.MaxX && point.Y >= box.MinY && point.Y <= box.MaxY) { return(true); } if (tolerance > 0) { //点在一定容限内位于矩形盒边界上 WEPoint LeftTop = new WEPoint(box.MinX, box.MaxY); WEPoint LeftBottom = new WEPoint(box.MinX, box.MinY); WEPoint RightTop = new WEPoint(box.MaxX, box.MaxY); WEPoint RightBottom = new WEPoint(box.MaxX, box.MinY); if (GetDistanceFromPointToSegment(point, LeftTop, LeftBottom) < Tolerance) //左边界 { return(true); } if (GetDistanceFromPointToSegment(point, RightTop, RightBottom) < Tolerance) //右边界 { return(true); } if (GetDistanceFromPointToSegment(point, LeftTop, RightTop) < Tolerance) //上边界 { return(true); } if (GetDistanceFromPointToSegment(point, LeftBottom, RightBottom) < Tolerance) //下边界 { return(true); } } return(false); }
/// <summary> /// 重置外包矩形 /// </summary> public void SetMBR() { /* 重置外包矩形的简单写法 * _MBR = null; * foreach (var i in _Features) * _MBR += i.MBR; */ double minX, maxX, minY, maxY; minX = _Features[0].MBR.MinX; minY = _Features[0].MBR.MinY; maxX = minX; maxY = minY; for (int i = 0; i < _Features.Count; i++) { if (_Features[i].MBR.MinX < minX) { minX = _Features[i].MBR.MinX; } if (_Features[i].MBR.MaxX > maxX) { maxX = _Features[i].MBR.MaxX; } if (_Features[i].MBR.MinY < minY) { minY = _Features[i].MBR.MinY; } if (_Features[i].MBR.MaxY > maxY) { maxY = _Features[i].MBR.MaxY; } } _MBR = new WERectangle(minX, maxX, minY, maxY); }
/// <summary> /// 移动图层中的所有要素 /// </summary> /// <param name="deltaX"></param> /// <param name="deltaY"></param> public void Move(double deltaX, double deltaY) { for (int i = 0; i < _Features.Count; i++) { _Features[i].Geometries.Move(deltaX, deltaY); } _MBR = new WERectangle(_MBR.MinX + deltaX, _MBR.MaxX + deltaX, _MBR.MinY + deltaY, _MBR.MaxY + deltaY); }
/// <summary> /// 移动多线 /// </summary> /// <param name="deltaX"></param> /// <param name="deltaY"></param> public override void Move(double deltaX, double deltaY) { for (int i = 0; i < _Polylines.Count; i++) { _Polylines[i].Move(deltaX, deltaY); } _MBR = new WERectangle(_MBR.MinX + deltaX, _MBR.MaxX + deltaX, _MBR.MinY + deltaY, _MBR.MaxY + deltaY); }
/// <summary> /// 判断复合多边形是否部分或者完全位于矩形盒内 /// </summary> /// <returns></returns> public static bool IsMultiPolygonPartiallyWithinBox(WEMultiPolygon multiPolygon, WERectangle box) { WERectangle multipolygonBox = multiPolygon.MBR; //矩形盒不相交 if (!IsTwoBoxesIntersect(multipolygonBox, box)) { return(false); } int sPolygonCount = multiPolygon.Polygons.Count(); for (int j = 0; j < sPolygonCount; j++) //遍历每个简单多边形判断是否有顶点位于矩形盒内 { WEPolygon thisPolygon = (WEPolygon)multiPolygon.GetPolygon(j); int sPointCount = thisPolygon.PointCount; for (int i = 0; i < sPointCount; i++) { if (IsPointInBox(thisPolygon.Points[i], box)) { return(true); } } } WEPoint LeftTop = new WEPoint(box.MinX, box.MaxY); WEPoint LeftBottom = new WEPoint(box.MinX, box.MinY); WEPoint RightTop = new WEPoint(box.MaxX, box.MaxY); WEPoint RightBottom = new WEPoint(box.MaxX, box.MinY); //判断矩形盒是否有顶点位于复合多边形内 if (IsPointInMultiPolygon(LeftTop, multiPolygon) || IsPointInMultiPolygon(LeftBottom, multiPolygon) || IsPointInMultiPolygon(RightBottom, multiPolygon) || IsPointInMultiPolygon(RightTop, multiPolygon)) { return(true); } for (int j = 0; j < sPolygonCount; j++) //遍历每个简单多边形判断是否有边与矩形盒相交 { WEPolygon thisPolygon = (WEPolygon)multiPolygon.GetPolygon(j); int sPointCount = thisPolygon.PointCount; WEPoint startPoint, endPoint; for (int i = 0; i < sPointCount - 1; i++) { startPoint = thisPolygon.Points[i]; endPoint = thisPolygon.Points[i + 1]; if (IsSegmentIntersectsBox(startPoint, endPoint, box)) { return(true); } } startPoint = thisPolygon.Points[sPointCount - 1]; endPoint = thisPolygon.Points[0]; if (IsSegmentIntersectsBox(startPoint, endPoint, box)) { return(true); } } return(false); }
/// <summary> /// 判断点是否在简单多边形内 /// </summary> /// <param name="point"></param> /// <param name="polygon"></param> /// <returns></returns> public static bool IsPointInPolygon(WEPoint point, WEPolygon polygon, double tolerance = 0.1) { WERectangle box = polygon.MBR; if (!IsPointInBox(point, box)) { return(false); } int sPointCount = polygon.PointCount; int sIntersectionCount = 0; //射线与边的交点数 WEPoint startPoint, endPoint; //线段起点、终点 for (int i = 0; i < sPointCount - 1; i++) { startPoint = polygon.Points[i]; endPoint = polygon.Points[i + 1]; if (IsRayIntersectsSegment(point, startPoint, endPoint)) { sIntersectionCount++; } } startPoint = polygon.Points[sPointCount - 1]; endPoint = polygon.Points[0]; if (IsRayIntersectsSegment(point, startPoint, endPoint)) //最后一条边 { sIntersectionCount++; } if (sIntersectionCount % 2 == 1) //奇数个交点 { return(true); } if (tolerance > 0) { //对每条边判断点是否在一定容限内位于边上 for (int i = 0; i < sPointCount - 1; i++) { startPoint = polygon.Points[i]; endPoint = polygon.Points[i + 1]; if (GetDistanceFromPointToSegment(point, startPoint, endPoint) <= Tolerance) { return(true); } } startPoint = polygon.Points[sPointCount - 1]; endPoint = polygon.Points[0]; if (GetDistanceFromPointToSegment(point, startPoint, endPoint) < Tolerance) { return(true); } } return(false); }
/// <summary> /// 缩放至全图 /// </summary> public void FullExitence() { if (AllLayer.Count == 0) { return; } WERectangle newRect = AllLayer[0].MBR; foreach (var i in AllLayer) { newRect += i.MBR; } ZoomByMBR(newRect); }
/// <summary> /// 判断简单多边形是否部分或者完全位于矩形盒内 /// </summary> /// <returns></returns> public static bool IsPolygonPartiallyWithinBox(WEPolygon polygon, WERectangle box) { WERectangle polygonBox = polygon.MBR; if (!IsTwoBoxesIntersect(polygonBox, box)) //矩形盒不相交 { return(false); } int sPointCount = polygon.PointCount; for (int i = 0; i < sPointCount; i++) //多边形是否有顶点位于矩形盒内 { if (IsPointInBox(polygon.Points[i], box)) { return(true); } } WEPoint LeftTop = new WEPoint(box.MinX, box.MaxY); WEPoint LeftBottom = new WEPoint(box.MinX, box.MinY); WEPoint RightTop = new WEPoint(box.MaxX, box.MaxY); WEPoint RightBottom = new WEPoint(box.MaxX, box.MinY); if (IsPointInPolygon(LeftTop, polygon) || IsPointInPolygon(LeftBottom, polygon) || IsPointInPolygon(RightTop, polygon) || IsPointInPolygon(RightBottom, polygon)) //矩形盒是否有顶点位于多边形内 { return(true); } //简单多边形与矩形盒的边是否有交点 WEPoint startPoint, endPoint; for (int i = 0; i < sPointCount - 1; i++) { startPoint = polygon.Points[i]; endPoint = polygon.Points[i + 1]; if (IsSegmentIntersectsBox(startPoint, endPoint, box)) { return(true); } } startPoint = polygon.Points[sPointCount - 1]; //最后一条边 endPoint = polygon.Points[0]; if (IsSegmentIntersectsBox(startPoint, endPoint, box)) { return(true); } return(false); }
/// <summary> /// 判断多点是否部分或完全位于矩形盒内 /// </summary> /// <param name="multiPoint"></param> /// <param name="box"></param> /// <returns></returns> public static bool IsMultiPointPartiallyWithinBox(WEMultiPoint multiPoint, WERectangle box) { WERectangle pointsBox = multiPoint.MBR; if (!IsTwoBoxesIntersect(pointsBox, box)) { return(false); } int sPointCount = multiPoint.PointCount; for (int i = 0; i < sPointCount; i++) { if (IsPointInBox((WEPoint)multiPoint.GetPoint(i), box)) //某一个点位于矩形盒内即可 { return(true); } } return(false); }
/// <summary> /// 判断点是否选中多线 /// </summary> /// <param name="point"></param> /// <param name="polyline"></param> /// <returns></returns> public static bool IsPointOnMultiPolyline(WEPoint point, WEMultiPolyline multipolyline) { WERectangle box = multipolyline.MBR; if (!IsPointInBox(point, box)) { return(false); } int sPolylineCount = multipolyline.Polylines.Count(); for (int i = 0; i < sPolylineCount; i++) { if (IsPointOnPolyline(point, (WEPolyline)multipolyline.Polylines[i])) { return(true); } } return(false); }
/// <summary> /// 判断复合折线是否部分或者完全位于矩形盒内 /// </summary> /// <returns></returns> public static bool IsMultiPolylinePartiallyWithinBox(WEMultiPolyline multiPolyline, WERectangle box) { WERectangle multiPolylineBox = multiPolyline.MBR; if (!IsTwoBoxesIntersect(multiPolylineBox, box)) { return(false); } int sPolylineCount = multiPolyline.Polylines.Count(); for (int i = 0; i < sPolylineCount; i++) { if (IsPolylinePartiallyWithinBox((WEPolyline)multiPolyline.Polylines[i], box)) { return(true); } } return(false); }
/// <summary> /// 判断点是否在复合多边形内 /// </summary> /// <param name="point"></param> /// <param name="multiPolygon"></param> /// <returns></returns> public static bool IsPointInMultiPolygon(WEPoint point, WEMultiPolygon multiPolygon) { WERectangle box = multiPolygon.MBR; if (!IsPointInBox(point, box)) { return(false); } int sPolygonCount = multiPolygon.Polygons.Count(); int sIntersectionCount = 0; //射线与边的交点数 for (int j = 0; j < sPolygonCount; j++) //遍历每个简单多边形求射线交点个数 { WEPolygon thisPolygon = (WEPolygon)multiPolygon.GetPolygon(j); if (thisPolygon.PointCount < 3) { continue; } int sPointCount = thisPolygon.PointCount; WEPoint startPoint, endPoint; //线段起点、终点 for (int i = 0; i < sPointCount - 1; i++) { startPoint = thisPolygon.Points[i]; endPoint = thisPolygon.Points[i + 1]; if (IsRayIntersectsSegment(point, startPoint, endPoint)) { sIntersectionCount++; } } startPoint = thisPolygon.Points[sPointCount - 1]; endPoint = thisPolygon.Points[0]; if (IsRayIntersectsSegment(point, startPoint, endPoint)) //最后一条边 { sIntersectionCount++; } } if (sIntersectionCount % 2 == 1) //奇数个交点 { return(true); } return(false); }
/// <summary> /// 判断图层里的点是否在矩形盒内并返回部分在矩形盒内的结果 /// </summary> /// <param name="box"></param> /// <returns></returns> public override WEFeature[] SelectByBox(WERectangle box) { List <WEFeature> result = new List <WEFeature> { }; switch (_FeatureType) { case FeatureType.WEEntityPoint: foreach (var i in _Features) { if (WEMapTools.IsMultiPointPartiallyWithinBox((WEMultiPoint)i.Geometries, box)) { result.Add(i); } } break; //case FeatureType.WEEntityPolyline: case FeatureType.WEMultiPolyline: foreach (var i in _Features) { if (WEMapTools.IsMultiPolylinePartiallyWithinBox((WEMultiPolyline)i.Geometries, box)) { result.Add(i); } } break; //case FeatureType.WEEntityPolygon: case FeatureType.WEMultiPolygon: foreach (var i in _Features) { if (WEMapTools.IsMultiPolygonPartiallyWithinBox((WEMultiPolygon)i.Geometries, box)) { result.Add(i); } } break; } return(result.ToArray()); }
/// <summary> /// 判断点在容限内是否在线上 /// </summary> /// <param name="point"></param> /// <param name="polyline"></param> /// <returns></returns> public static bool IsPointOnPolyline(WEPoint point, WEPolyline polyline) { WERectangle box = polyline.MBR; if (!IsPointInBox(point, box)) //若点不在线外包矩形内,无需继续计算 { return(false); } int sPointCount = polyline.PointCount; for (int i = 0; i < sPointCount - 1; i++) { WEPoint sPoint = polyline.Points[i]; WEPoint ePoint = polyline.Points[i + 1]; double thisDis = GetDistanceFromPointToSegment(point, sPoint, ePoint); if (thisDis < Tolerance) //点到一段线段的距离小于容限即可 { return(true); } } return(false); }
/// <summary> /// 判断两个矩形盒是否相交 /// </summary> /// <param name="box1"></param> /// <param name="box2"></param> /// <returns></returns> public static bool IsTwoBoxesIntersect(WERectangle box1, WERectangle box2) { double MaxX1, MinX1, MaxY1, MinY1; double MaxX2, MinX2, MaxY2, MinY2; MaxX1 = box1.MaxX; MinX1 = box1.MinX; MaxY1 = box1.MaxY; MinY1 = box1.MinY; MaxX2 = box2.MaxX; MinX2 = box2.MinX; MaxY2 = box2.MaxY; MinY2 = box2.MinY; if (MinY1 > MaxY2 || MinY2 > MaxY1 || MinX1 > MaxX2 || MinX2 > MaxX1) { return(false); } else { return(true); } }
public WELayer(string filePath, FeatureType layerType = FeatureType.WENULL) { string fileType = filePath.Split('.').Last(); if (fileType == "shp") { WELayer newLayer = WEIO.ReadLayer(filePath); this._ID = newLayer.ID; this._LayerName = newLayer.LayerName; this._FileName = filePath; this._Description = newLayer.Description; this._FeatureType = newLayer.FeatureType; this._LayerStyle = newLayer.SymbolStyle; this._MBR = newLayer._MBR; this._Visible = true; this._Selectable = true; } else if (fileType == "tif") { ; } }
//鼠标移动 private void WEMapControl_MouseMove(object sender, MouseEventArgs e) { if (WEMouseMove != null) { WEMouseMove(this, e.Location); } switch (MapOpStyle) { case 0: break; case 1: //放大 if (e.Button == MouseButtons.Left) { Refresh(); Graphics g = Graphics.FromHwnd(this.Handle); Pen sBoxPen = new Pen(mcSelectingBoxColor, mcSelectingBoxWidth); float sMinX = Math.Min(mStartPoint.X, e.Location.X); float sMinY = Math.Min(mStartPoint.Y, e.Location.Y); float sMaxX = Math.Max(mStartPoint.X, e.Location.X); float sMaxY = Math.Max(mStartPoint.Y, e.Location.Y); g.DrawRectangle(sBoxPen, sMinX, sMinY, sMaxX - sMinX, sMaxY - sMinY); g.Dispose(); } break; case 2: //缩小 if (e.Button == MouseButtons.Left) { Refresh(); Graphics g = Graphics.FromHwnd(this.Handle); Pen sBoxPen = new Pen(mcSelectingBoxColor, mcSelectingBoxWidth); float sMinX = Math.Min(mStartPoint.X, e.Location.X); float sMinY = Math.Min(mStartPoint.Y, e.Location.Y); float sMaxX = Math.Max(mStartPoint.X, e.Location.X); float sMaxY = Math.Max(mStartPoint.Y, e.Location.Y); g.DrawRectangle(sBoxPen, sMinX, sMinY, sMaxX - sMinX, sMaxY - sMinY); g.Dispose(); } break; case 3: //漫游 if (e.Button == MouseButtons.Left) { //PointF sPreMouseLocation = new PointF(mStartPoint.X, mStartPoint.Y); //WEPoint sPrePoint = WEMapTools.ToMapPoint(sPreMouseLocation); WEPoint sPrePoint = WEMapTools.ToMapPoint(mStartPoint); //PointF sCurMouseLocation = new PointF(e.Location.X, e.Location.Y); //WEPoint sCurPoint = WEMapTools.ToMapPoint(sCurMouseLocation); WEPoint sCurPoint = WEMapTools.ToMapPoint(e.Location); WEPoint offset = WEMapTools.ToMapPoint(new PointF(e.Location.X - mStartPoint.X, e.Location.Y - mStartPoint.Y)); //修改offset double mOffsetX = sPrePoint.X - sCurPoint.X; double mOffsetY = sPrePoint.Y - sCurPoint.Y; WERectangle newRect = new WERectangle(WEMapTools.DisplayMBR.MinX + mOffsetX, WEMapTools.DisplayMBR.MaxX + mOffsetX, WEMapTools.DisplayMBR.MinY + mOffsetY, WEMapTools.DisplayMBR.MaxY + mOffsetY); WEMapTools.DisplayMBR = newRect; ZoomByMBR(WEMapTools.DisplayMBR); mStartPoint = e.Location; /* * //修改offset * mOffsetX = (mStartPoint.X - e.Location.X) * WEMapTools.DisplayMBR.Width / WEMapTools.DisplayWidth; * mOffsetY = (e.Location.Y - mStartPoint.Y) * WEMapTools.DisplayMBR.Height / WEMapTools.DisplayHeight; * newRect = new WERectangle(WEMapTools.DisplayMBR.MinX + mOffsetX, WEMapTools.DisplayMBR.MaxX + mOffsetX, * WEMapTools.DisplayMBR.MinY + mOffsetY, WEMapTools.DisplayMBR.MaxY + mOffsetY); * WEMapTools.DisplayMBR = newRect; * ZoomByMBR(WEMapTools.DisplayMBR); * mStartPoint.X = e.Location.X; * mStartPoint.Y = e.Location.Y; */ } break; case 4: mStartPoint = e.Location; List <WEPoint> tem = new List <WEPoint>(); if (CurrentEdit < 0 || CurrentEdit > AllLayer.Count()) { break; } if (NodeEdit == 0) { switch (AllLayer[CurrentEdit].FeatureType) { case FeatureType.WEMultiPoint: case FeatureType.WEEntityPoint: if (NewPoints.Count() != 0) { NewPoints[0] = e.Location; EditFeature.Geometries = new WEMultiPoint(new WEPoint[1] { WEMapTools.ToMapPoint(NewPoints[0]) }); } else { NewPoints.Add(e.Location); } //NewPoints.Clear(); //EditFeature = AllLayer[CurrentEdit].Features.Last(); //AllLayer[CurrentEdit].Features[AllLayer[CurrentEdit].Features.Count() - 1].Geometries = new WEMultiPoint(new WEGeometry[1] { }); break; case FeatureType.WEEntityPolyline: case FeatureType.WEMultiPolyline: NewPoints.Add(e.Location); WEMultiPolyline temm = (WEMultiPolyline)(EditFeature.Geometries); WEPolyline temmm = (WEPolyline)temm.Polylines[temm.Polylines.Count() - 1]; //tem.AddRange(temmm.Points); foreach (var i in NewPoints) { tem.Add(WEMapTools.ToMapPoint(i)); } temmm.Points = (WEPoint[])tem.ToArray(); temm.DeletePolyline(temm.Polylines.Count() - 1); temm.Add(temmm); EditFeature.Geometries = temm; NewPoints.RemoveAt(NewPoints.Count - 1); break; case FeatureType.WEEntityPolygon: case FeatureType.WEMultiPolygon: NewPoints.Add(e.Location); WEMultiPolygon temm3 = (WEMultiPolygon)(EditFeature.Geometries); WEPolygon temmm3 = (WEPolygon)temm3.Polygons[temm3.Polygons.Count() - 1]; //tem.AddRange(temmm3.Points); foreach (var i in NewPoints) { tem.Add(WEMapTools.ToMapPoint(i)); } temmm3.Points = (WEPoint[])tem.ToArray(); temm3.DeletePolygon(temm3.Polygons.Count() - 1); temm3.Add(temmm3); EditFeature.Geometries = temm3; NewPoints.RemoveAt(NewPoints.Count - 1); break; } Refresh(); } else if (EditFeature.Geometries.PointCount != 0) { CursorMap = WEMapTools.ToMapPoint(e.Location); switch (EditFeature.FeatureType) { case FeatureType.WEMultiPoint: case FeatureType.WEEntityPoint: isGravitationCaptured = -1; for (int i = 0; i < EditFeature.Geometries.PointCount; i++) { WEPoint poi = (WEPoint)((WEMultiPoint)EditFeature.Geometries).Points[i]; if (WEMapTools.IsPointOnPoint(CursorMap, poi)) { isGravitationCaptured = i; break; } } break; case FeatureType.WEEntityPolyline: case FeatureType.WEMultiPolyline: isGravitationCaptured = -1; for (int i = 0; i < EditFeature.Geometries.PointCount; i++) { WEPolyline polyline = (WEPolyline)((WEMultiPolyline)EditFeature.Geometries).Polylines[i]; for (int j = 0; j < polyline.PointCount; j++) { if (WEMapTools.IsPointOnPoint(CursorMap, polyline.Points[j])) { isGravitationCaptured = j; break; } } if (isGravitationCaptured != -1) { helpGravitationCaptured = i; break; } if (polyline.PointCount == 1) { continue; } for (int j = 1; j < polyline.PointCount; j++) { if (WEMapTools.IsPointOnPolyline(CursorMap, new WEPolyline(new WEPoint[2] { polyline.Points[j], polyline.Points[j - 1] }))) { ; } { isGravitationCaptured = j; break; } } if (isGravitationCaptured != -1) { helpGravitationCaptured = -i; break; } } break; case FeatureType.WEEntityPolygon: case FeatureType.WEMultiPolygon: isGravitationCaptured = -1; for (int i = 0; i < EditFeature.Geometries.PointCount; i++) { WEPolygon polygon = (WEPolygon)((WEMultiPolyline)EditFeature.Geometries).Polylines[i]; for (int j = 0; j < polygon.PointCount; j++) { if (WEMapTools.IsPointOnPoint(CursorMap, polygon.Points[j])) { isGravitationCaptured = j; break; } } if (isGravitationCaptured != -1) { helpGravitationCaptured = i; break; } if (polygon.PointCount == 1) { continue; } for (int j = 1; j < polygon.PointCount; j++) { if (WEMapTools.IsPointOnPolyline(CursorMap, new WEPolyline(new WEPoint[2] { polygon.Points[j], polygon.Points[j - 1] }))) { ; } { isGravitationCaptured = j; break; } } if (WEMapTools.IsPointOnPolyline(CursorMap, new WEPolyline(new WEPoint[2] { polygon.Points.Last(), polygon.Points.First() }))) { ; } isGravitationCaptured = polygon.PointCount; if (isGravitationCaptured != -1) { helpGravitationCaptured = -i; break; } } break; default: isGravitationCaptured = -1; break; } if (isGravitationCaptured != -1) { Cursor = Cursors.SizeAll; using (Graphics g = Graphics.FromHwnd(this.Handle)) { g.FillRectangle(new SolidBrush(Color.Black), 0, 0, 100, 100); } } else { Cursor = Cursors.Cross; } } if (isGravitationCaptured != -1) { } break; case 5: //选择要素 if (e.Button == MouseButtons.Left) { Refresh(); Graphics g = Graphics.FromHwnd(this.Handle); Pen sBoxPen = new Pen(mcSelectingBoxColor, mcSelectingBoxWidth); float sMinX = Math.Min(mStartPoint.X, e.Location.X); float sMinY = Math.Min(mStartPoint.Y, e.Location.Y); float sMaxX = Math.Max(mStartPoint.X, e.Location.X); float sMaxY = Math.Max(mStartPoint.Y, e.Location.Y); g.DrawRectangle(sBoxPen, sMinX, sMinY, sMaxX - sMinX, sMaxY - sMinY); g.Dispose(); } break; default: mStartPoint = e.Location; break; } }
/// <summary> /// 判断一条线段是否和矩形盒相交 /// </summary> /// <returns></returns> public static bool IsSegmentIntersectsBox(WEPoint startPoint, WEPoint endPoint, WERectangle box) { if (startPoint.X < box.MinX && endPoint.X < box.MinX) //线段在矩形盒左边的外侧 { return(false); } if (startPoint.X > box.MaxX && endPoint.X > box.MaxX) //线段在矩形盒右边的外侧 { return(false); } if (startPoint.Y < box.MinY && endPoint.Y < box.MinY) //线段在矩形盒下边的外侧 { return(false); } if (startPoint.Y > box.MaxY && endPoint.Y > box.MaxY) //线段在矩形盒上边的外侧 { return(false); } WEPoint LeftTop = new WEPoint(box.MinX, box.MaxY); WEPoint LeftBottom = new WEPoint(box.MinX, box.MinY); WEPoint RightTop = new WEPoint(box.MaxX, box.MaxY); WEPoint RightBottom = new WEPoint(box.MaxX, box.MinY); if (IsTwoSegmentsIntersect(startPoint, endPoint, LeftBottom, LeftTop)) //线段与矩形盒左边界求交 { return(true); } if (IsTwoSegmentsIntersect(startPoint, endPoint, RightBottom, RightTop)) //线段与矩形盒右边界求交 { return(true); } if (IsTwoSegmentsIntersect(startPoint, endPoint, RightTop, LeftTop)) //线段与矩形盒上边界求交 { return(true); } if (IsTwoSegmentsIntersect(startPoint, endPoint, LeftBottom, RightBottom)) //线段与矩形盒下边界求交 { return(true); } return(false); }
/// <summary> /// 获取外包矩形 /// </summary> public override WERectangle SetMBR() { _MBR = new WERectangle(_X - WEMapTools.Tolerance, _X + WEMapTools.Tolerance, _Y - WEMapTools.Tolerance, _Y + WEMapTools.Tolerance); return(_MBR); }
public virtual WEFeature[] SelectByBox(WERectangle box) { throw new Exception("不能直接对未定义的对象进行选择."); }