public RgPoint GroundToImage(RgPoint groundPoint) { RgPoint imagePoint = new RgPoint(); imagePoint.X = _inverseTransform[0] + _inverseTransform[1] * groundPoint.X + _inverseTransform[2] * groundPoint.Y; imagePoint.Y = _inverseTransform[3] + _inverseTransform[4] * groundPoint.X + _inverseTransform[5] * groundPoint.Y; return(imagePoint); }
/// <summary> /// Transforms a <see cref="RGeos.Geometries.RgPoint"/>. /// </summary> /// <param name="p">Point to transform</param> /// <param name="transform">MathTransform</param> /// <returns>Transformed Point</returns> public static RgPoint TransformPoint(RgPoint p, IMathTransform transform) { try { return(new RgPoint(transform.Transform(p.ToDoubleArray()))); } catch { return(null); } }
public PointF ToScreen(RgPoint pt) { float ratio = GetRatio(mUnits); PointF transformedPoint = new PointF((float)pt.X, (float)pt.Y); transformedPoint.Y = ScreenHeight() - transformedPoint.Y; //将Unit坐标系转换为屏幕坐标系,Y轴反向,此时Y坐标为屏幕坐标系坐标 transformedPoint.Y *= ratio * Zoom; //相对于屏幕原点放大 transformedPoint.X *= ratio * Zoom; transformedPoint.X += m_panOffset.X + m_dragOffset.X; transformedPoint.Y += m_panOffset.Y + m_dragOffset.Y; return(transformedPoint); }
/// <summary> /// Converts a Coordinate to Point Text format then Appends it to the writer. /// </summary> /// <param name="coordinate">The Coordinate to process.</param> /// <param name="writer">The output stream writer to Append to.</param> private static void AppendPointText(RgPoint coordinate, StringWriter writer) { if (coordinate == null || coordinate.IsEmpty()) { writer.Write("EMPTY"); } else { writer.Write("("); AppendCoordinate(coordinate, writer); writer.Write(")"); } }
/// <summary> /// Creates a Point using the next token in the stream. /// </summary> /// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a <Point Text>.</param> /// <returns>Returns a Point specified by the next token in /// the stream.</returns> /// <remarks> /// ParseException is thrown if an unexpected token is encountered. /// </remarks> private static RgPoint ReadPointText(WktStreamTokenizer tokenizer) { RgPoint p = new RgPoint(); string nextToken = GetNextEmptyOrOpener(tokenizer); if (nextToken == "EMPTY") { return(p); } p.X = GetNextNumber(tokenizer); p.Y = GetNextNumber(tokenizer); GetNextCloser(tokenizer); return(p); }
private static RgPoint[] ReadCoordinates(BinaryReader reader, WkbByteOrder byteOrder) { // Get the number of points in this linestring. int numPoints = (int)ReadUInt32(reader, byteOrder); // Create a new array of coordinates. RgPoint[] coords = new RgPoint[numPoints]; // Loop on the number of points in the ring. for (int i = 0; i < numPoints; i++) { // Add the coordinate. coords[i] = new RgPoint(ReadDouble(reader, byteOrder), ReadDouble(reader, byteOrder)); } return(coords); }
public List <Feature> GetHitObjects(RgPoint point, double tolerance) { List <Feature> selected = new List <Feature>(); if (this.Visible == false) { return(null); } foreach (Feature drawobject in mGeometries) { if (ShapeType == RgEnumShapeType.RgPoint) { RgPoint pt = drawobject.Shape as RgPoint; if (RDistanceMeasure.Dist_Point_to_Point(pt, point) < tolerance) { selected.Add(drawobject); // drawobject.IsSelected = true; } } else if (ShapeType == RgEnumShapeType.RgLineString) { LineString lineString = drawobject.Shape as LineString; if (lineString.PointInObject(point)) { selected.Add(drawobject); //drawobject.IsSelected = true; } } else if (ShapeType == RgEnumShapeType.RgPolygon) { Polygon polygon = drawobject.Shape as Polygon; if (!polygon.IsEmpty()) { if (Geometries.RgTopologicRelationship.IsInPolygon(point, polygon)) { selected.Add(drawobject); //drawobject.IsSelected = true; } } } } return(selected); }
/// <summary> /// Transforms a <see cref="RGeos.Geometries.BoundingBox"/>. /// </summary> /// <param name="box">BoundingBox to transform</param> /// <param name="transform">Math Transform</param> /// <returns>Transformed object</returns> public static BoundingBox TransformBox(BoundingBox box, IMathTransform transform) { if (box == null) { return(null); } RgPoint[] corners = new RgPoint[4]; corners[0] = new RgPoint(transform.Transform(box.Min.ToDoubleArray())); //LL corners[1] = new RgPoint(transform.Transform(box.Max.ToDoubleArray())); //UR corners[2] = new RgPoint(transform.Transform(new RgPoint(box.Min.X, box.Max.Y).ToDoubleArray())); //UL corners[3] = new RgPoint(transform.Transform(new RgPoint(box.Max.X, box.Min.Y).ToDoubleArray())); //LR BoundingBox result = corners[0].GetBoundingBox(); for (int i = 1; i < 4; i++) { result = result.Join(corners[i].GetBoundingBox()); } return(result); }
/// <summary> /// Converts a Geometry to <Geometry Tagged Text > format, then Appends it to the writer. /// </summary> /// <param name="geometry">The Geometry to process.</param> /// <param name="writer">The output stream to Append to.</param> private static void AppendGeometryTaggedText(IGeometry geometry, StringWriter writer) { if (geometry == null) { throw new NullReferenceException("Cannot write Well-Known Text: geometry was null"); } ; if (geometry is RgPoint) { RgPoint point = geometry as RgPoint; AppendPointTaggedText(point, writer); } else if (geometry is LineString) { AppendLineStringTaggedText(geometry as LineString, writer); } else if (geometry is Polygon) { AppendPolygonTaggedText(geometry as Polygon, writer); } else if (geometry is MultiPoint) { AppendMultiPointTaggedText(geometry as MultiPoint, writer); } else if (geometry is MultiLineString) { AppendMultiLineStringTaggedText(geometry as MultiLineString, writer); } else if (geometry is MultiPolygon) { AppendMultiPolygonTaggedText(geometry as MultiPolygon, writer); } else if (geometry is GeometryCollection) { AppendGeometryCollectionTaggedText(geometry as GeometryCollection, writer); } else { throw new NotSupportedException("Unsupported Geometry implementation:" + geometry.GetType().Name); } }
/// <summary> /// 几何对象集合执行的获取捕捉点的方法 /// </summary> /// <param name="canvas"></param> /// <param name="point"></param> /// <param name="runningsnaptypes"></param> /// <param name="usersnaptype"></param> /// <returns></returns> public ISnapPoint SnapPoint(RgPoint point, Type[] runningsnaptypes, Type usersnaptype) { for (int i = 0; i < Layers.Count; i++) { ILayer lry = Layers[i]; if (lry is FetureLayer) { FetureLayer featlyr = lry as FetureLayer; List <Feature> objects = featlyr.GetHitObjects(point, tolerance); if (objects.Count == 0) { return(null); } foreach (Feature obj in objects) { IGeometry geo = obj.Shape as IGeometry; if (geo is RgPoint) { RgPoint pt = geo as RgPoint; if (RDistanceMeasure.Dist_Point_to_Point(pt, point) < tolerance) { return(new SnapPointBase(pt, pt)); } // ISnapPoint snap = obj.SnapPoint(point, objects, runningsnaptypes, usersnaptype); } if (geo is LinearRing) { } if (geo is Polygon) { } // ISnapPoint snap = obj.SnapPoint( point, objects, runningsnaptypes, usersnaptype); //if (snap != null) // return snap; } } } return(null); }
private void btnCreate_Click(object sender, EventArgs e) { int row = 0; bool flag = int.TryParse(txtRows.Text, out row); int col = 0; bool flag1 = int.TryParse(txtCols.Text, out col); double rheight, rwidth; bool flag3 = double.TryParse(txtRowHeight.Text, out rheight); bool flag4 = double.TryParse(txtRowWidth.Text, out rwidth); if (!flag) { MessageBox.Show("请输入正确的行数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtRows.Focus(); return; } if (!flag1) { MessageBox.Show("请输入正确的列数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCols.Focus(); return; } if (!flag3) { MessageBox.Show("请输入正确的行高", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtRowHeight.Focus(); return; } if (!flag4) { MessageBox.Show("请输入正确的行宽", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtRowWidth.Focus(); return; } IMapControl2 mapCtrl = mMapCtrl as IMapControl2; RGeos.Carto.IMap map = mapCtrl.Map; if (chkGridPoint.Checked) { RGeos.Carto.FetureLayer layer = new RGeos.Carto.FetureLayer(); layer.Name = "GridPoint"; layer.ShapeType = RgEnumShapeType.RgPoint; map.AddLayer(layer); double baseX; bool flag5 = double.TryParse(txtX.Text, out baseX); double baseY; bool flag6 = double.TryParse(txtY.Text, out baseY); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { RgPoint pt = new RgPoint(); pt.X = baseX + i * rwidth; pt.Y = baseY + j * rheight; layer.AddFeature(pt); } } } if (chkGridLine.Checked) { RGeos.Carto.FetureLayer layer = new RGeos.Carto.FetureLayer(); layer.Name = "GridLine"; layer.ShapeType = RgEnumShapeType.RgLineString; map.AddLayer(layer); double baseX; bool flag5 = double.TryParse(txtX.Text, out baseX); double baseY; bool flag6 = double.TryParse(txtY.Text, out baseY); RgPoint ptLowerLeft = new RgPoint(); ptLowerLeft.X = baseX; ptLowerLeft.Y = baseY; RgPoint ptLowerRight = new RgPoint(); ptLowerRight.X = baseX + col * rwidth; ptLowerRight.Y = baseY; RgPoint ptTopRight = new RgPoint(); ptTopRight.X = baseX + col * rwidth; ptTopRight.Y = baseY + row * rheight; RgPoint ptTopLeft = new RgPoint(); ptTopLeft.X = baseX; ptTopLeft.Y = baseY + row * rheight; List <RgPoint> ptBounds = new List <RgPoint>(); ptBounds.Add(ptLowerLeft); ptBounds.Add(ptLowerRight); ptBounds.Add(ptTopRight); ptBounds.Add(ptTopLeft); ptBounds.Add(ptLowerLeft); LineString lineBounds = new LineString(ptBounds); layer.AddFeature(lineBounds); for (int i = 1; i < row; i++) { RgPoint ptStart = new RgPoint(); ptStart.X = baseX; ptStart.Y = baseY + i * rheight; RgPoint ptEnd = new RgPoint(); ptEnd.X = baseX + col * rwidth; ptEnd.Y = baseY + i * rheight; List <RgPoint> pts = new List <RgPoint>(); pts.Add(ptStart); pts.Add(ptEnd); LineString line = new LineString(pts); layer.AddFeature(line); } for (int j = 1; j < col; j++) { RgPoint ptStart = new RgPoint(); ptStart.X = baseX + j * rwidth; ptStart.Y = baseY; RgPoint ptEnd = new RgPoint(); ptEnd.X = baseX + j * rwidth; ptEnd.Y = baseY + row * rheight; List <RgPoint> pts = new List <RgPoint>(); pts.Add(ptStart); pts.Add(ptEnd); LineString line = new LineString(pts); layer.AddFeature(line); } } mapCtrl.Refresh(); }
public override void OnMouseUp(int x, int y) { if (m_selection != null) { List <Feature> SelectFeatures = new List <Feature>(); screenSelRect = m_selection.ScreenRect(); RgPoint lowLeft = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(screenSelRect.Left, screenSelRect.Bottom)); RgPoint upRight = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(screenSelRect.Right, screenSelRect.Top)); BoundingBox box = new BoundingBox(lowLeft, upRight); //RectangleF selectionRect = m_selection.Selection(m_canvaswrapper); if (screenSelRect != Rectangle.Empty) { // is any selection rectangle. use it for selection for (int i = 0; i < mMap.Layers.Count; i++) { ILayer lyr = mMap.Layers[i]; if (lyr is FetureLayer) { Carto.FetureLayer featlyr = lyr as Carto.FetureLayer; SelectFeatures = featlyr.GetHitObjects(box, m_selection.AnyPoint()); if (SelectFeatures != null) { for (int j = 0; j < SelectFeatures.Count; j++) { SelectFeatures[j].IsSelected = true; } if (mMap.Selection == null) { mMap.Selection = new MapSelection(); } mMap.Selection.SelectedFeatures.AddRange(SelectFeatures); } } } } else { for (int i = 0; i < mMap.Layers.Count; i++) { ILayer lyr = mMap.Layers[i]; if (lyr is FetureLayer) { Carto.FetureLayer featlyr = lyr as Carto.FetureLayer; RgPoint mousepoint = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y)); SelectFeatures = featlyr.GetHitObjects(mousepoint, 0.1); if (SelectFeatures != null) { for (int j = 0; j < SelectFeatures.Count; j++) { SelectFeatures[j].IsSelected = true; } if (mMap.Selection == null) { mMap.Selection = new MapSelection(); } mMap.Selection.SelectedFeatures.AddRange(SelectFeatures); } } } } mMapCtrl.Refresh(); m_selection = null; } }
/// <summary> /// Converts a Coordinate to <Point Tagged Text> format, /// then Appends it to the writer. /// </summary> /// <param name="coordinate">the <code>Coordinate</code> to process</param> /// <param name="writer">the output writer to Append to</param> private static void AppendPointTaggedText(RgPoint coordinate, StringWriter writer) { writer.Write("POINT "); AppendPointText(coordinate, writer); }
public SnapPointBase(IGeometry owner, RgPoint snappoint) { m_owner = owner; m_snappoint = snappoint; }