public IEnumerable <IGeometry> GetSnapCandidateGeometriesFromLayers(ICoordinate original, double tolerance) { IGeometry pointGeom = new Geometry(GeometryType.Point); pointGeom.Points.Add(original.Clone()); pointGeom = pointGeom.Buffer(tolerance * 2, 6); IList <IGeometry> geometriesToTest = new List <IGeometry>(); foreach (var layer in Layers.Where(l => l.IsVector && l.Visible && l.LayerVisibleAtCurrentScale)) { var results = new int[] { }; if (layer.FeatureSet.GetRelatedShapes(pointGeom, SpatialRelation.Intersects, ref results)) { try { foreach (var index in results) { var feature = layer.FeatureSet.Features[index]; geometriesToTest.Add(feature.Geometry.Clone()); } } catch (IndexOutOfRangeException) { // ignore } } } return(geometriesToTest); }
private IPolygon CreateSelectionPolygon(ICoordinate worldPosition) { if (MultiSelectionMode == MultiSelectionMode.Rectangle) { if (0 == Math.Abs(mouseDownLocation.X - worldPosition.X)) { return(null); } if (0 == Math.Abs(mouseDownLocation.Y - worldPosition.Y)) { return(null); } return(CreatePolygon(Math.Min(mouseDownLocation.X, worldPosition.X), Math.Max(mouseDownLocation.Y, worldPosition.Y), Math.Max(mouseDownLocation.X, worldPosition.X), Math.Min(mouseDownLocation.Y, worldPosition.Y))); } var vertices = new List <ICoordinate>(); foreach (var point in selectPoints) { vertices.Add(Map.ImageToWorld(point)); } if (vertices.Count == 1) { // too few points to create a polygon return(null); } vertices.Add((ICoordinate)worldPosition.Clone()); vertices.Add((ICoordinate)vertices[0].Clone()); ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray()); return(GeometryFactory.CreatePolygon(newLinearRing, null)); }
/// <summary> /// /// </summary> /// <param name="errorType"></param> /// <param name="pt"></param> public TopologyValidationError(TopologyValidationErrors errorType, ICoordinate pt) { this.errorType = errorType; if (pt != null) { this.pt = (ICoordinate)pt.Clone(); } }
/// <summary> /// 源坐标转目标坐标 /// </summary> /// <param name="sourceCoordinate">源坐标</param> /// <returns>目标坐标</returns> public ICoordinate SourceToTarget(ICoordinate sourceCoordinate) { if (sourceCoordinate == null) { return(null); } // 两个中间变量 SpherePoint spTemp = null; PlanePoint ppTemp = null; // 如果源是平面坐标 // 1.平面坐标转高斯坐标;2.高斯反算,转为球面坐标 if (sourceCT == CoordinateType.Plane) { GaussKrugerTransform gauss_source = new GaussKrugerTransform(sourceCS); ppTemp = gauss_source.PlaneToGauss((PlanePoint)sourceCoordinate); spTemp = gauss_source.GaussKrugerReverse(ppTemp, sourceMeridian); } else { spTemp = (SpherePoint)sourceCoordinate.Clone(); } // 大地坐标转空间直角坐标 GeodeticTransform geo_source = new GeodeticTransform(sourceCS, sourceMeridian); ppTemp = geo_source.GeodeticToThreeDimensions(spTemp); // 七参数模型,对空间直角坐标进行转换,转换后同样是空间直角坐标 BursaWolfTransform bursa_source = new BursaWolfTransform(sevenParams); ppTemp = (PlanePoint)bursa_source.Transform(ppTemp); // 空间直角坐标转大地坐标 GeodeticTransform geo_target = new GeodeticTransform(targetCS, targetMeridian); spTemp = geo_target.ThreeDimensionsToGeodetic(ppTemp); ICoordinate result = null; // 如果目标是平面坐标 // 1.高斯正算,转为高斯坐标;2.高斯坐标转平面坐标 if (targetCT == CoordinateType.Plane) { GaussKrugerTransform gauss_target = new GaussKrugerTransform(targetCS); ppTemp = gauss_target.GaussKrugerForward(spTemp, targetMeridian); ppTemp = gauss_target.GaussToPlane(ppTemp); result = ppTemp.Clone(); } else { result = spTemp.Clone(); } return(result); }
private void SetClickOnExistingSelection(bool set, ICoordinate worldPosition) { clickOnExistingSelection = set; if (clickOnExistingSelection) { orgMouseDownLocation = (ICoordinate)worldPosition.Clone(); } else { orgMouseDownLocation = null; } }
private void TestUserYButton_Click(object sender, EventArgs e) { Feature polygonFeature = new Feature(FeatureType.Polygon); ICoordinate coordinate0 = _initialRectangle.Min; ICoordinate coordinate1 = ((ICoordinate)coordinate0.Clone()); coordinate1.Translate(0, DefaultCellSize * 20); ICoordinate coordinate2 = ((ICoordinate)coordinate0.Clone()); coordinate2.Translate(DefaultCellSize * 10, DefaultCellSize * 10); Polygon polygon = new Polygon(new [] { coordinate0, coordinate1, coordinate2 }); polygonFeature.Polygon = polygon; _userRegionLayer.AddFeature(polygonFeature); RedrawMap(); }
public ICoordinate Transform(ICoordinate coordinate) { var xy = new[] { coordinate.X, coordinate.Y }; var z = new[] { coordinate.Z }; Reproject.ReprojectPoints(xy, z, Source, Target, 0, 1); var ret = (ICoordinate)coordinate.Clone(); ret.X = xy[0]; ret.Y = xy[1]; ret.Z = z[0]; return(ret); }
public T AtLoc(ICoordinate <S> coordinate) { if (coordinate.Dimentions != System.Dimentions) { throw new ArgumentException("Value retrival failed - number of ordinates provided was inapropriate for the number of dimentions in the coordinate system."); } if (Casche.ContainsKey(coordinate)) { return(Casche[coordinate]); } else { T result = CalculateAtLoc(coordinate); Casche.Add((ICoordinate <S>)coordinate.Clone(), result); return(result); } }
private static ILineString AppendCurvePoint(ILineString lineString, ICoordinate worldPos) { List <ICoordinate> vertices = new List <ICoordinate>(); for (int i = 0; i < lineString.Coordinates.Length; i++) { if (1 == i) { // remove duplicate start points, see MouseDown if ((lineString.Coordinates[0].X != lineString.Coordinates[1].X) && (lineString.Coordinates[0].Y != lineString.Coordinates[1].Y)) { vertices.Add(lineString.Coordinates[i]); } } else { vertices.Add(lineString.Coordinates[i]); } } vertices.Add((ICoordinate)worldPos.Clone()); return(GeometryFactory.CreateLineString(vertices.ToArray())); }
/// <summary> /// /// </summary> /// <param name="errorType"></param> /// <param name="pt"></param> public TopologyValidationError(TopologyValidationErrors errorType, ICoordinate pt) { this.errorType = errorType; if(pt != null) this.pt = (ICoordinate) pt.Clone(); }
private double getAngle(ICoordinate p1, ICoordinate p2, ICoordinate p3, bool counterClockwise) { p1 = (ICoordinate)p1.Clone(); p2 = (ICoordinate)p2.Clone(); p3 = (ICoordinate)p3.Clone(); // translating the origin p1.X -= p2.X; p1.Y -= p2.Y; p3.X -= p2.X; p3.Y -= p2.Y; double alpha = p1.X != 0 ? Math.Atan(Math.Abs(p1.Y / p1.X)) : 0.5 * Math.PI; double betta = p3.X != 0 ? Math.Atan(Math.Abs(p3.Y / p3.X)) : 0.5 * Math.PI; alpha = translateAngleQuadrant(alpha, pointQuadrantNumber(p1)); betta = translateAngleQuadrant(betta, pointQuadrantNumber(p3)); if (counterClockwise) return alpha < betta ? (betta - alpha) : (2 * Math.PI - alpha + betta); else return alpha > betta ? (alpha - betta) : (2 * Math.PI - betta + alpha); }
public ICoordinate Transform(ICoordinate coordinate) { var xy = new[] {coordinate.X, coordinate.Y}; var z = new[] {coordinate.Z}; Reproject.ReprojectPoints(xy, z, Source, Target, 0, 1); var ret = (ICoordinate)coordinate.Clone(); ret.X = xy[0]; ret.Y = xy[1]; ret.Z = z[0]; return ret; }
private void insertNodeAt(int patchIndex, int coordinateIndex, ICoordinate coordinate) { EditAction forwardAction; EditAction backwardAction; EditActionParameters parameters = new EditActionParameters() { OldGeometry = _geometry, PatchIndex = patchIndex, NodeIndex = coordinateIndex, NodePosition = (ICoordinate)coordinate.Clone() }; forwardAction = new EditAction(EditActionType.InsertNode, parameters, out backwardAction); HistoryEntry pair = new HistoryEntry(forwardAction, backwardAction); _geometry = _history.DoAction(pair, _geometry); }
private static ILineString AppendCurvePoint(ILineString lineString, ICoordinate worldPos) { List<ICoordinate> vertices = new List<ICoordinate>(); for (int i = 0; i < lineString.Coordinates.Length; i++) { if (1 == i) { // remove duplicate start points, see MouseDown if ((lineString.Coordinates[0].X != lineString.Coordinates[1].X) && (lineString.Coordinates[0].Y != lineString.Coordinates[1].Y)) vertices.Add(lineString.Coordinates[i]); } else { vertices.Add(lineString.Coordinates[i]); } } vertices.Add((ICoordinate)worldPos.Clone()); return GeometryFactory.CreateLineString(vertices.ToArray()); }
/// <summary> /// Initializes a new instance of MapAround.Geometry.PlanarGraphNode. /// </summary> /// <param name="coordinate">Coordinate of a node</param> public PlanarGraphNode(ICoordinate coordinate) { _coordinate = (ICoordinate)coordinate.Clone(); }
private IPolygon CreateSelectionPolygon(ICoordinate worldPosition) { if (MultiSelectionMode == MultiSelectionMode.Rectangle) { if (0 == Math.Abs(mouseDownLocation.X - worldPosition.X)) { return null; } if (0 == Math.Abs(mouseDownLocation.Y - worldPosition.Y)) { return null; } return CreatePolygon(Math.Min(mouseDownLocation.X, worldPosition.X), Math.Max(mouseDownLocation.Y, worldPosition.Y), Math.Max(mouseDownLocation.X, worldPosition.X), Math.Min(mouseDownLocation.Y, worldPosition.Y)); } var vertices = new List<ICoordinate>(); foreach (var point in selectPoints) { vertices.Add(Map.ImageToWorld(point)); } if (vertices.Count == 1) { // too few points to create a polygon return null; } vertices.Add((ICoordinate)worldPosition.Clone()); vertices.Add((ICoordinate)vertices[0].Clone()); ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray()); return GeometryFactory.CreatePolygon(newLinearRing, null); }
/// <summary> /// Updates the position of the active node with the specified value /// </summary> /// <param name="coordinate">New position of the active node</param> /// <param name="commitIntoUndoList">A value indicating whether current update should be commited into undo list</param> /// <returns>true if the position has been updated, false otherwise</returns> public bool UpdateActiveNodePosition(ICoordinate coordinate, bool commitIntoUndoList) { if (ActivePatchIndex == -1) return false; if (commitIntoUndoList) { EditAction forwardAction; EditAction backwardAction; EditActionParameters parameters = new EditActionParameters() { OldGeometry = _geometry, PatchIndex = _activePatchIndex, NodeIndex = _activeCoordinateIndex, NodePosition = (ICoordinate)coordinate.Clone() }; // update active node with the old value // this is necessary for properly generation of the inverse action UpdateActiveNodePosition(oldActiveNodeCoordinate, false); forwardAction = new EditAction(EditActionType.SetNodePosition, parameters, out backwardAction); HistoryEntry pair = new HistoryEntry(forwardAction, backwardAction); _geometry = _history.DoAction(pair, _geometry); oldActiveNodeCoordinate = (ICoordinate)coordinate.Clone(); } else { if (_snapper != null && _snapper.SnapMethod != null) coordinate = _snapper.SnapMethod(coordinate); if (_geometry is Polyline) { Polyline polyline = (Polyline)_geometry; polyline.Paths[_activePatchIndex].Vertices[_activeCoordinateIndex].X = coordinate.X; polyline.Paths[_activePatchIndex].Vertices[_activeCoordinateIndex].Y = coordinate.Y; } if (_geometry is Polygon) { Polygon polygon = (Polygon)_geometry; polygon.Contours[_activePatchIndex].Vertices[_activeCoordinateIndex].X = coordinate.X; polygon.Contours[_activePatchIndex].Vertices[_activeCoordinateIndex].Y = coordinate.Y; } } return true; }