/// <summary> /// Adds a termination point (or re-use a point if it happens to be the offset point). /// </summary> /// <param name="loc">The location for the termination point.</param> /// <returns>The point feature at the termination point (may be the position that was /// used to define the offset to the parallel line).</returns> PointFeature AddPoint(IPosition loc) { CadastralMapModel map = CadastralMapModel.Current; // Add the split point (with default entity type). If a // point already exists at the location, you'll get back // that point instead. // We do this in case the user has decided to // terminate on a line connected to the offset point // that defines the offset to the parallel (which the // UI lets the user do). PointFeature p = this.OffsetPoint; if (p != null) { IPointGeometry pg = PointGeometry.Create(loc); if (p.IsCoincident(pg)) { return(p); } } p = map.AddPoint(p, map.DefaultPointType, this); p.SetNextId(); return(p); }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { // Get the radius, in meters on the ground. double rad = m_Radius.GetDistance(m_Center).Meters; if (rad < Constants.TINY) { throw new Exception("NewCircleOperation.CalculateGeometry - Radius is too close to zero."); } // If the closing point was created by this edit, define it's position ArcFeature arc = (ArcFeature)this.Line; PointFeature p = arc.StartPoint; if (p.Creator == this) { PointGeometry pg = new PointGeometry(m_Center.X, m_Center.Y + rad); p.ApplyPointGeometry(ctx, pg); } // Define the radius of the circle and include in the map model Circle circle = arc.Circle; Debug.Assert(circle != null); circle.Radius = rad; // Refer the center point to the circle. circle.AddReferences(); }
/// <summary> /// Initializes a new instance of the <see cref="MovePolygonPositionOperation"/> class /// </summary> /// <param name="label">The polygon label to modify</param> internal MovePolygonPositionOperation(TextFeature label) : base() { m_Label = label; m_OldPosition = null; m_NewPosition = null; }
/// <summary> /// Performs the data processing associated with this face. /// </summary> /// <param name="parentLine">The line that is being subdivided</param> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal void CalculateGeometry(LineFeature parentLine, EditingContext ctx) { // Get adjusted lengths for each section double[] adjray = GetAdjustedLengths(parentLine, m_Distances); double edist = 0.0; // Distance to end of section. PointFeature start = parentLine.StartPoint; LineGeometry lineGeom = parentLine.LineGeometry; for (int i = 0; i < adjray.Length; i++) { // Calculate the position at the end of the span edist += adjray[i]; IPosition to; if (!lineGeom.GetPosition(new Length(edist), out to)) { throw new Exception("Cannot adjust line section"); } // Get the point feature at the end of the span LineFeature line = m_Sections[i]; PointFeature end = line.EndPoint; // Assign the calculated position so long as we're not at // the end of the line if (end != parentLine.EndPoint) { end.ApplyPointGeometry(ctx, PointGeometry.Create(to)); } // The end of the current span is the start of the next one start = end; } }
/// <summary> /// Draws the text that is currently being added, together with a rectangle representing /// the outline of the label. /// </summary> /// <param name="refpos">Reference position for the label</param> protected void DrawText(IPosition refpos) { if (refpos == null) { return; } // Draw the outline of the label. IPosition[] outline = GetOutline(refpos); IDrawStyle style = new DrawStyle(); // black style.Render(ActiveDisplay, outline); // Draw the text PointGeometry p = PointGeometry.Create(refpos); IFont font = (m_Entity == null ? null : m_Entity.Font); MiscTextGeometry text = new MiscTextGeometry(m_Text, p, font, m_Height, m_Width, (float)m_Rotation); style.Render(ActiveDisplay, text); // If doing auto-angle stuff, draw an additional line // at the position used to search for candidate lines // ... perhaps (the auto-angle stuff needs to move to // this class from CuiNewLabel) // Remember the specified position as the "last" position. m_LastPos = refpos; }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { //IPosition p = (base.CheckPosition == null ? Calculate() : base.CheckPosition); IPosition p = Calculate(); if (p == null) { p = CheckPosition; Log(String.Format("Id={0} (CEdit={1:0.0}E {2:0.0}N", this.EditSequence, p.X, p.Y)); } else if (CheckPosition != null) { double d = Geom.Distance(p, CheckPosition); if (d > 1.0) { Log(String.Format("Id={0} (CEdit={1:0.0}E {2:0.0}N) (Backsight={3:0.0}E {4:0.0}N) Delta={5:0.000}", this.EditSequence, CheckPosition.Easting.Meters, CheckPosition.Northing.Meters, p.X, p.Y, d)); } p = CheckPosition; } PointGeometry pg = PointGeometry.Create(p); m_Intersection.ApplyPointGeometry(ctx, pg); }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { IPosition p = Calculate(); PointGeometry pg = PointGeometry.Create(p); m_To.ApplyPointGeometry(ctx, pg); }
/// <summary> /// Attaches geometry to the spans along a leg. /// </summary> /// <param name="ctx">The context in which the geometry is being defined.</param> /// <param name="spans">Information about each observed span</param> /// <param name="sections">The geometry that corresponds to each span</param> void AttachGeometry(EditingContext ctx, SpanInfo[] spans, ILineGeometry[] sections) { Debug.Assert(spans.Length == sections.Length); for (int i = 0; i < spans.Length; i++) { SpanInfo data = spans[i]; Feature feat = data.CreatedFeature; PointFeature endPoint = null; if (feat is PointFeature) { endPoint = (PointFeature)feat; } else if (feat is LineFeature) { endPoint = (feat as LineFeature).EndPoint; } if (endPoint != null && endPoint.PointGeometry == null) { PointGeometry pg = PointGeometry.Create(sections[i].End); endPoint.ApplyPointGeometry(ctx, pg); } } }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { IPosition p = Calculate(); PointGeometry pg = PointGeometry.Create(p); m_NewPoint.ApplyPointGeometry(ctx, pg); // If the extension line was a circular arc, we also need to define it's geometry. // This COULD have been defined at an earlier stage (e.g. as part of CreateFeature), // but it's more consistent to do it as part of this method. if (m_NewLine is ArcFeature) { ArcFeature arc = m_ExtendLine.GetArcBase(); Circle circle = arc.Circle; Debug.Assert(circle != null); bool iscw = arc.IsClockwise; if (!m_IsExtendFromEnd) { iscw = !iscw; } ArcGeometry geom = new ArcGeometry(circle, m_NewLine.StartPoint, m_NewLine.EndPoint, iscw); (m_NewLine as ArcFeature).Geometry = geom; } }
public DealerFeature(string id, PointGeometry geometry, DealerProperties properties) { Id = id; Properties = properties; Geometry = geometry; Type = "Feature"; }
/// <summary> /// Applies changes to this editing operation. /// </summary> /// <param name="ctx">The editing context (null if the model is being deserialized)</param> /// <param name="data">The changes to apply</param> void ApplyUpdateItems(EditingContext ctx, UpdateItemCollection data) { double x = data.ExchangeValue <double>(DataField.X, m_NewPoint.Easting.Meters); double y = data.ExchangeValue <double>(DataField.Y, m_NewPoint.Northing.Meters); PointGeometry pg = new PointGeometry(x, y); m_NewPoint.ApplyPointGeometry(ctx, pg); }
/// <summary> /// Initializes a new instance of the <see cref="MoveTextOperation"/> class /// </summary> /// <param name="text">The text to be moved</param> internal MoveTextOperation(TextFeature text) : base() { m_Text = text; m_OldPosition = null; m_OldPolPosition = null; m_NewPosition = null; }
/// <summary> /// Initializes a new instance of the <see cref="IntersectOperation"/> class /// using the data read from persistent storage. /// </summary> /// <param name="editDeserializer">The mechanism for reading back content.</param> protected IntersectOperation(EditDeserializer editDeserializer) : base(editDeserializer) { // If the data was produced via export from an old CEdit file, we'll have the absolute position if (editDeserializer.IsNextField(DataField.X)) { CheckPosition = editDeserializer.ReadPointGeometry(DataField.X, DataField.Y); } }
/// <summary> /// Handles mouse-move. /// </summary> /// <param name="p">The new position of the mouse</param> internal override void MouseMove(IPosition p) { // Erase the text at its previous position, and draw it at the new position. Controller.ActiveDisplay.RestoreLastDraw(); // Remember the mouse position. We'll draw at this new position when // the Paint method gets called m_LastPosition = PointGeometry.Create(p); }
protected override void OnCreate(Android.OS.Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStylePositron); // read json from assets and add to map string json; using (System.IO.StreamReader sr = new System.IO.StreamReader(Assets.Open("cities15000.geojson"))) { json = sr.ReadToEnd(); } // Initialize a local vector data source LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection); // Initialize a vector layer with the previous data source ClusteredVectorLayer layer = new ClusteredVectorLayer(source, new MyClusterElementBuilder(this)); layer.MinimumClusterDistance = 50; new System.Threading.Thread((obj) => { // Create a basic style, as the ClusterElementBuilder will set the real style var markerStyleBuilder = new MarkerStyleBuilder(); markerStyleBuilder.Size = 14; MarkerStyle style = markerStyleBuilder.BuildStyle(); // Read GeoJSON, parse it using SDK GeoJSON parser GeoJSONGeometryReader reader = new GeoJSONGeometryReader(); // Set target projection to base (mercator) reader.TargetProjection = BaseProjection; Alert("Starting load from .geojson"); // Read features from local asset FeatureCollection features = reader.ReadFeatureCollection(json); Alert("Finished load from .geojson"); VectorElementVector elements = new VectorElementVector(); for (int i = 0; i < features.FeatureCount; i++) { // This data set features point geometry, // however, it can also be LineGeometry or PolygonGeometry PointGeometry geometry = (PointGeometry)features.GetFeature(i).Geometry; elements.Add(new Marker(geometry, style)); } source.AddAll(elements); Alert("Clustering started. Please wait..."); // Add the clustered vector layer to the map MapView.Layers.Add(layer); }).Start(); }
/// <summary> /// Handles mouse-move. /// </summary> /// <param name="pos">The new position of the mouse</param> internal override void MouseMove(IPosition pos) { // If we previously drew a text outline, erase it now. EraseRect(); // Find the polygon (if any) that encloses the mouse position. CadastralMapModel map = CadastralMapModel.Current; ISpatialIndex index = map.Index; IPointGeometry pg = PointGeometry.Create(pos); Polygon enc = new FindPointContainerQuery(index, pg).Result; // If it's different from what we previously had, remember the // new enclosing polygon. if (!Object.ReferenceEquals(enc, m_Polygon)) { // If we had something before, and we filled it, erase // the fill now. //DrawPolygon(false); // Remember the polygon we're now enclosed by (if any). m_Polygon = enc; // Draw the new polygon. //DrawPolygon(true); // Ensure any calculated position has been cleared m_AutoPosition = null; // See if a new orientation applies CheckOrientation(pg); // If the enclosing polygon does not have a label, use the // standard cursor and fill the polygon. Otherwise use the // gray cursor. SetCommandCursor(); } // Draw a rectangle representing the outline of the text. if (m_IsAutoPos && m_Polygon != null) { if (m_AutoPosition == null) { m_AutoPosition = m_Polygon.GetLabelPosition(Width, Height); } } if (m_IsAutoPos && m_AutoPosition != null) { DrawText(m_AutoPosition); } else { DrawText(pos); } }
/// <summary> /// Sees whether the orientation of the new text should be altered. This /// occurs if the auto-angle capability is enabled, and the specified /// position is close to any visible line. /// </summary> /// <param name="refpos">The current mouse position (reference position /// for the new label)</param> /// <returns>True if the orientation angle got changed.</returns> bool CheckOrientation(IPointGeometry refpos) { // Return if the auto-angle function is disabled. if (!m_IsAutoAngle) { return(false); } // Return if the auto-position function is enabled if (m_IsAutoPos) { return(false); } // Try to get an orientation line LineFeature orient = GetOrientation(refpos); if (!Object.ReferenceEquals(orient, m_Orient)) { ErasePainting(); } m_Orient = null; if (orient == null) { return(false); } // Locate the closest point on the line (we SHOULD find it, // but if we don't, just bail out) ISpatialDisplay display = ActiveDisplay; ILength tol = new Length(0.002 * display.MapScale); IPosition closest = orient.LineGeometry.GetClosest(refpos, tol); if (closest == null) { return(false); } m_Orient = orient; if (m_Orient == null) { return(false); } // Highlight the new orientation line m_Orient.Render(display, new HighlightStyle()); // Get the rotation angle IPointGeometry cg = PointGeometry.Create(closest); double rot = m_Orient.LineGeometry.GetRotation(cg); SetRotation(rot); return(true); }
internal override bool LButtonDown(IPosition p) { // Quit if we don't have a selected line if (m_Line == null) { AbortCommand(); return(false); } // Get the position on the selected line that is closest // to the supplied position. ISpatialDisplay draw = ActiveDisplay; ILength tol = new Length(0.001 * draw.MapScale); IPointGeometry pg = PointGeometry.Create(p); IPosition pos = m_Line.LineGeometry.GetClosest(pg, tol); if (pos == null) { MessageBox.Show("You appear to be moving the mouse too fast"); return(false); } // Obtain the position ratio uint pr = AttachPointOperation.GetPositionRatio(m_Line, pos); // Attach a new point to the line AttachPointOperation op = null; try { op = new AttachPointOperation(m_Line, pr); FeatureFactory ff = new FeatureFactory(op); ff.PointType = m_PointType; op.Execute(ff); // Ensure the draw includes the extra point (perhaps a bit of overkill to // draw just one point). Controller.RefreshAllDisplays(); } catch (Exception ex) { MessageBox.Show(ex.StackTrace, ex.Message); return(true); } // Exit the command if we're not supposed to repeat if (!m_Repeat) { AbortCommand(); } return(true); }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { IPosition to = Calculate(m_Direction, m_Distance, m_From, m_Default); PointGeometry pg = PointGeometry.Create(to); m_To.ApplyPointGeometry(ctx, pg); // There's no need to calculate new geometry for the line segments // created by the edit, since their geometry is dependent on the // position of the end points - we calculated one end above, the // other end should have been calculated by a previous edit. }
/// <summary> /// Initializes a new instance of the <see cref="MoveTextOperation"/> class /// using the data read from persistent storage. /// </summary> /// <param name="editDeserializer">The mechanism for reading back content.</param> internal MoveTextOperation(EditDeserializer editDeserializer) : base(editDeserializer) { m_Text = editDeserializer.ReadFeatureRef<TextFeature>(DataField.Text); m_OldPosition = editDeserializer.ReadPointGeometry(DataField.OldX, DataField.OldY); m_NewPosition = editDeserializer.ReadPointGeometry(DataField.NewX, DataField.NewY); if (editDeserializer.IsNextField(DataField.OldPolygonX)) m_OldPolPosition = editDeserializer.ReadPointGeometry(DataField.OldPolygonX, DataField.OldPolygonY); else m_OldPolPosition = null; }
/// <summary> /// Applies changes to this editing operation. /// </summary> /// <param name="ctx">The editing context (null if the model is being deserialized)</param> /// <param name="data">The changes to apply</param> void ApplyUpdateItems(EditingContext ctx, UpdateItemCollection data) { // Locate the specific point that was modified //string id = data.GetValue<string>(DataField.Id); //InternalIdValue iid = new InternalIdValue(id); //PointFeature p = this.MapModel.Find<PointFeature>(iid); PointFeature p = data.GetValue <PointFeature>(DataField.UpdatedPoint); double x = data.ExchangeValue <double>(DataField.X, p.Easting.Meters); double y = data.ExchangeValue <double>(DataField.Y, p.Northing.Meters); PointGeometry pg = new PointGeometry(x, y); p.ApplyPointGeometry(ctx, pg); }
/// <summary> /// Does a position coincide with a point feature that was used to define the /// offset to the parallel line? /// </summary> /// <param name="loc">The test position</param> /// <returns>True if the offset was defined using a point feature (as opposed to an /// explicit distance), and the supplied position is exactly coincident.</returns> bool IsPositionAtOffsetPoint(IPosition loc) { PointFeature p = this.OffsetPoint; if (p == null) { return(false); } IPointGeometry pg = PointGeometry.Create(loc); return(p.IsCoincident(pg)); }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { IPosition p = Calculate(); if (p == null) { p = CheckPosition; } PointGeometry pg = PointGeometry.Create(p); m_Intersection.ApplyPointGeometry(ctx, pg); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); // Add default base layer AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStylePositron); // Initialize a local vector data source LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection); // Initialize a vector layer with the previous data source var layer = new ClusteredVectorLayer(source, new MyClusterElementBuilder()); // Default is 100. A good value depends on data layer.MinimumClusterDistance = 50; // read json from assets and add to map string json = System.IO.File.ReadAllText(AssetUtils.CalculateResourcePath("cities15000.geojson")); // Create a basic style, as the ClusterElementBuilder will set the real style var markerStyleBuilder = new MarkerStyleBuilder(); markerStyleBuilder.Size = 14; MarkerStyle style = markerStyleBuilder.BuildStyle(); // Read GeoJSON, parse it using SDK GeoJSON parser GeoJSONGeometryReader reader = new GeoJSONGeometryReader(); // Set target projection to base (mercator) reader.TargetProjection = BaseProjection; // Read features from local asset FeatureCollection features = reader.ReadFeatureCollection(json); VectorElementVector elements = new VectorElementVector(); for (int i = 0; i < features.FeatureCount; i++) { // This data set features point geometry, // however, it can also be LineGeometry or PolygonGeometry PointGeometry geometry = (PointGeometry)features.GetFeature(i).Geometry; elements.Add(new Marker(geometry, style)); } // Add the clustered vector layer to the map source.AddAll(elements); MapView.Layers.Add(layer); }
/// <summary> /// Reads data that was previously written using <see cref="WriteData"/> /// </summary> /// <param name="editDeserializer">The mechanism for reading back content.</param> /// <param name="label">The polygon label that was modified</param> /// <param name="newPosition">The revised position of the reference point.</param> /// <param name="oldPosition">The original position of the reference point.</param> static void ReadData(EditDeserializer editDeserializer, out TextFeature label, out PointGeometry newPosition, out PointGeometry oldPosition) { label = editDeserializer.ReadFeatureRef <TextFeature>(DataField.Label); newPosition = editDeserializer.ReadPointGeometry(DataField.NewX, DataField.NewY); if (editDeserializer.IsNextField(DataField.OldX)) { oldPosition = editDeserializer.ReadPointGeometry(DataField.OldX, DataField.OldY); } else { oldPosition = null; } }
/// <summary> /// Handles mouse-move. /// </summary> /// <param name="p">The new position of the mouse</param> internal override void MouseMove(IPosition p) { if (m_LastPolygon == null || !m_LastPolygon.IsEnclosing(p)) { IPointGeometry pg = PointGeometry.Create(p); ISpatialIndex index = CadastralMapModel.Current.Index; Polygon pol = new FindPointContainerQuery(index, pg).Result; if (pol != null || (m_LastPolygon != null && pol == null)) { Controller.ActiveDisplay.RestoreLastDraw(); m_LastPolygon = pol; } } }
/// <summary> /// Initializes a new instance of the <see cref="MoveTextOperation"/> class /// using the data read from persistent storage. /// </summary> /// <param name="editDeserializer">The mechanism for reading back content.</param> internal MoveTextOperation(EditDeserializer editDeserializer) : base(editDeserializer) { m_Text = editDeserializer.ReadFeatureRef <TextFeature>(DataField.Text); m_OldPosition = editDeserializer.ReadPointGeometry(DataField.OldX, DataField.OldY); m_NewPosition = editDeserializer.ReadPointGeometry(DataField.NewX, DataField.NewY); if (editDeserializer.IsNextField(DataField.OldPolygonX)) { m_OldPolPosition = editDeserializer.ReadPointGeometry(DataField.OldPolygonX, DataField.OldPolygonY); } else { m_OldPolPosition = null; } }
public static void QueryFeatures(this MapView map, CartoSQLService service, LocalVectorDataSource source, PointStyle style, string query) { System.Threading.Tasks.Task.Run(delegate { FeatureCollection features = service.QueryFeatures(query, map.Options.BaseProjection); for (int i = 0; i < features.FeatureCount; i++) { Feature feature = features.GetFeature(i); PointGeometry geometry = (PointGeometry)feature.Geometry; var point = new Point(geometry, style); source.Add(point); } }); }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { // Calculate the end positions IPosition spos, epos; if (!Calculate(out spos, out epos)) { throw new Exception("Failed to calculate parallel line positions"); } // Apply the calculated positions so long as the end points of the parallel line // were created by this edit if (m_ParLine.StartPoint.Creator == this) { m_ParLine.StartPoint.ApplyPointGeometry(ctx, PointGeometry.Create(spos)); } if (m_ParLine.EndPoint.Creator == this) { m_ParLine.EndPoint.ApplyPointGeometry(ctx, PointGeometry.Create(epos)); } // If the parallel is an arc, define the geometry if (m_ParLine is ArcFeature) { // Get the center of the reference line ArcFeature refArc = m_RefLine.GetArcBase(); PointFeature center = refArc.Circle.CenterPoint; // Obtain a circle for the parallel double radius = Geom.Distance(center, m_ParLine.StartPoint); Circle circle = MapModel.AddCircle(center, radius); // Define arc direction bool iscw = refArc.IsClockwise; if (IsArcReversed) { iscw = !iscw; } ArcGeometry geom = new ArcGeometry(circle, m_ParLine.StartPoint, m_ParLine.EndPoint, iscw); (m_ParLine as ArcFeature).Geometry = geom; } }
/// <summary> /// Handles a mouse down event /// </summary> /// <param name="p">The position where the click occurred</param> /// <returns>True, indicating that the text was moved.</returns> internal override bool LButtonDown(IPosition p) { MoveTextOperation op = null; try { op = new MoveTextOperation(m_Text); op.Execute(PointGeometry.Create(p)); FinishCommand(); return(true); } catch (Exception ex) { //Session.CurrentSession.Remove(op); MessageBox.Show(ex.StackTrace, ex.Message); } return(false); }
/// <summary> /// Executes the move operation. /// </summary> /// <param name="to">The position to move to</param> internal void Execute(PointGeometry to) { // Remember the old and new positions. m_OldPosition = PointGeometry.Create(m_Text.Position); // Remember old polygon reference position if it's different from the text position m_OldPolPosition = PointGeometry.Create(m_Text.GetPolPosition()); if (m_OldPosition.IsCoincident(m_OldPolPosition)) { m_OldPolPosition = null; } m_NewPosition = to; // Move the text and ensure any enclosing polygon has been reworked m_Text.Move(to); m_Text.RecalculateEnclosingPolygon(); // Peform standard completion steps Complete(); }
/// <summary> /// Applies changes to this editing operation. /// </summary> /// <param name="ctx">The editing context (null if the model is being deserialized)</param> /// <param name="data">The changes to apply</param> void ApplyUpdateItems(EditingContext ctx, UpdateItemCollection data) { // Locate the specific point that was modified //string id = data.GetValue<string>(DataField.Id); //InternalIdValue iid = new InternalIdValue(id); //PointFeature p = this.MapModel.Find<PointFeature>(iid); PointFeature p = data.GetValue<PointFeature>(DataField.UpdatedPoint); double x = data.ExchangeValue<double>(DataField.X, p.Easting.Meters); double y = data.ExchangeValue<double>(DataField.Y, p.Northing.Meters); PointGeometry pg = new PointGeometry(x, y); p.ApplyPointGeometry(ctx, pg); }
/// <summary> /// Returns the intersection of the parallel with a line. /// </summary> /// <param name="refline">The reference line.</param> /// <param name="parpos">Search position that coincides with the parallel.</param> /// <param name="line">The line to intersect with.</param> /// <returns>The intersection (if any). In cases where the line intersects the /// parallel more than once, you get the intersection that is closest to the /// search position.</returns> internal static IPosition GetIntersect(LineFeature refline, IPosition parpos, LineFeature line) { // Make sure the intersection is undefined. IPosition result = null; // Return if the parallel point is undefined. if (parpos==null) return null; // If the reference line is a circular arc (or a section based on an arc), get the curve info. ArcFeature arc = refline.GetArcBase(); if (arc != null) { Circle circle = arc.Circle; double radius = circle.Radius; IPointGeometry centre = circle.Center; bool iscw = arc.IsClockwise; // Construct a circle that passes through the search position double parrad = Geom.Distance(centre, parpos); // Intersect the circle with the line to intersect with. IntersectionResult xres = new IntersectionResult(line); uint nx = xres.Intersect(centre, parrad); if (nx==0) return null; // If there is only one intersection, that's what we want. if (nx==1) return xres.Intersections[0].P1; // Get the intersection that is closest to the search position. xres.GetClosest(parpos, out result, 0.0); } else { // Get the bearing from the start to the end of the reference line. IPosition spos = refline.StartPoint; IPosition epos = refline.EndPoint; double bearing = Geom.BearingInRadians(spos, epos); // Project the parallel line to positions that are a long way away (but make sure we // don't end up with negative numbers). Window searchWindow = new Window(line.Extent); searchWindow.Union(refline.Extent); searchWindow.Union(parpos); double dist = Geom.Distance(searchWindow.Min, searchWindow.Max); IPosition start = Geom.Polar(parpos, bearing+Constants.PI, dist); IPosition end = Geom.Polar(parpos, bearing, dist); // Intersect the line segment with the line to intersect with. IntersectionResult xres = new IntersectionResult(line); IPointGeometry sg = new PointGeometry(start); IPointGeometry eg = new PointGeometry(end); uint nx = xres.Intersect(sg, eg); if (nx==0) return null; // If there is only one intersection, that's what we want. if (nx==1) return xres.Intersections[0].P1; // Get the intersection that is closest to the search position xres.GetClosest(parpos, out result, 0.0); } return result; }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { // Get the radius, in meters on the ground. double rad = m_Radius.GetDistance(m_Center).Meters; if (rad < Constants.TINY) throw new Exception("NewCircleOperation.CalculateGeometry - Radius is too close to zero."); // If the closing point was created by this edit, define it's position ArcFeature arc = (ArcFeature)this.Line; PointFeature p = arc.StartPoint; if (p.Creator == this) { PointGeometry pg = new PointGeometry(m_Center.X, m_Center.Y+rad); p.ApplyPointGeometry(ctx, pg); } // Define the radius of the circle and include in the map model Circle circle = arc.Circle; Debug.Assert(circle != null); circle.Radius = rad; // Refer the center point to the circle. circle.AddReferences(); }
/// <summary> /// Executes the move operation. /// </summary> /// <param name="to">The position to move to</param> internal void Execute(PointGeometry to) { // Remember the old and new positions. m_OldPosition = PointGeometry.Create(m_Text.Position); // Remember old polygon reference position if it's different from the text position m_OldPolPosition = PointGeometry.Create(m_Text.GetPolPosition()); if (m_OldPosition.IsCoincident(m_OldPolPosition)) m_OldPolPosition = null; m_NewPosition = to; // Move the text and ensure any enclosing polygon has been reworked m_Text.Move(to); m_Text.RecalculateEnclosingPolygon(); // Peform standard completion steps Complete(); }
/// <summary> /// Executes the move operation. /// </summary> /// <param name="to">The revised position of the reference point.</param> internal void Execute(PointGeometry to) { // Remember the old and new positions. IPointGeometry txtPos = m_Label.Position; IPointGeometry polPos = m_Label.GetPolPosition(); if (txtPos.IsCoincident(polPos)) m_OldPosition = null; else m_OldPosition = PointGeometry.Create(polPos); m_NewPosition = to; // Move the reference position (and rework any enclosing polygon) m_Label.SetPolPosition(m_NewPosition); // Peform standard completion steps Complete(); }
/// <summary> /// Reads data that was previously written using <see cref="WriteData"/> /// </summary> /// <param name="editDeserializer">The mechanism for reading back content.</param> /// <param name="label">The polygon label that was modified</param> /// <param name="newPosition">The revised position of the reference point.</param> /// <param name="oldPosition">The original position of the reference point.</param> static void ReadData(EditDeserializer editDeserializer, out TextFeature label, out PointGeometry newPosition, out PointGeometry oldPosition) { label = editDeserializer.ReadFeatureRef<TextFeature>(DataField.Label); newPosition = editDeserializer.ReadPointGeometry(DataField.NewX, DataField.NewY); if (editDeserializer.IsNextField(DataField.OldX)) oldPosition = editDeserializer.ReadPointGeometry(DataField.OldX, DataField.OldY); else oldPosition = null; }
/// <summary> /// Applies changes to this editing operation. /// </summary> /// <param name="ctx">The editing context (null if the model is being deserialized)</param> /// <param name="data">The changes to apply</param> void ApplyUpdateItems(EditingContext ctx, UpdateItemCollection data) { double x = data.ExchangeValue<double>(DataField.X, m_NewPoint.Easting.Meters); double y = data.ExchangeValue<double>(DataField.Y, m_NewPoint.Northing.Meters); PointGeometry pg = new PointGeometry(x, y); m_NewPoint.ApplyPointGeometry(ctx, pg); }