/// <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> /// Calculates the position of the sideshot point. /// </summary> /// <param name="dir">The direction observation (if any).</param> /// <param name="len">The length observation (if any). Could be a <c>Distance</c> or an /// <c>OffsetPoint</c>.</param> /// <returns>The position of the sideshot point (null if there is insufficient data /// to calculate a position)</returns> internal static IPosition Calculate(Direction dir, Observation len) { // Return if there is insufficient data. if (dir == null || len == null) { return(null); } // Get the position of the point the sideshot should radiate from. PointFeature from = dir.From; // Get the position of the start of the direction line (which may be offset). IPosition start = dir.StartPosition; // Get the bearing of the direction. double bearing = dir.Bearing.Radians; // Get the length of the sideshot arm. double length = len.GetDistance(from).Meters; // Calculate the resultant position. Note that the length is the length along the // bearing -- if an offset was specified, the actual length of the line from-to = // sqrt(offset*offset + length*length) IPosition to = Geom.Polar(start, bearing, length); // Return if the length is an offset point. In that case, the length we have obtained // is already a length on the mapping plane, so no further reduction should be done // (although it's debateable). if (len is OffsetPoint) { return(to); } // Using the position we've just got, reduce the length we used to a length on the // mapping plane (it's actually a length on the ground). ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem; double sfac = sys.GetLineScaleFactor(start, to); return(Geom.Polar(start, bearing, length * sfac)); }
/// <summary> /// Intersects this direction with a specific entity type. /// </summary> /// <param name="ent">The entity type to look for.</param> /// <param name="maxdist">Observation defining the maximum distance between the /// direction's from-point & the intersection. This can either be a <c>Distance</c> /// or an <c>OffsetPoint</c> object.</param> /// <param name="xsect">The position of the intersection (if any). Null if no intersection found.</param> /// <returns>True if an intersection was found.</returns> bool Intersect(IEntity ent, Observation maxdist, out IPosition xsect) { // Initialize the intersection. xsect = null; // Get the max distance. It has to be defined to be SOMETHING. double dist = maxdist.GetDistance(this.From).Meters; if (Math.Abs(dist) < Constants.TINY) { return(false); } // Define the position of the direction line. IPosition from = this.StartPosition; IPosition to = Geom.Polar(from, this.Bearing.Radians, dist); throw new NotImplementedException("Direction.Intersect"); /* * // Construct a corresponding line segment. * CeLocation start(vfrom); * CeLocation end(vto); * CeSegment seg(start,end); * * // Intersect the segment with the map (all features on * // the currently active theme). * CeLayerList curlayer; * CeXObject xseg(seg,&curlayer); * * // Get the first intersection (if any) with the specified * // entity type. * * UINT4 nprim = xseg.GetCount(); // How many primitives did we intersect? * FLOAT8 bestdsq = 10e+38; // Closest distance (squared) so far. * FLOAT8 tdistsq; // Test distance (squared). * LOGICAL gotone=FALSE; * * for ( UINT4 i=0; i<nprim; i++ ) { * * // Get the next thing we intersected. * const CeXResult& xres = xseg[i]; * const CeLine* const pLine = * dynamic_cast<const CeLine* const>(xres.GetpObject()); * * // Skip if it wasn't a line. * if ( !pLine ) continue; * * // Find the attached arc that has the current theme. Has * // to be topological(?) * const CeArc* const pArc = pLine->GetpArc(curlayer); * * // Skip if it doesn't have the desired entity type. * if ( pArc && pArc->GetpEntity()!=&ent ) continue; * * // Determine the intersection on the primitive that is * // closest to the start of the direction (ignoring any * // intersections that are right at the start of the * // direction line). * * gotone = TRUE; * UINT4 nx = xres.GetCount(); * CeVertex vtest; * * for ( UINT4 j=0; j<nx; j++ ) { * * vtest = xres.GetX1(j); * tdistsq = vfrom.DistanceSquared(vtest); * if ( tdistsq<bestdsq && tdistsq>TINY ) { * xsect = vtest; * bestdsq = tdistsq; * } * * // Check any grazing intersection too. * if ( xres.IsGrazing() ) { * vtest = xres.GetX2(j); * tdistsq = vfrom.DistanceSquared(vtest); * if ( tdistsq<bestdsq && tdistsq>TINY ) { * xsect = vtest; * bestdsq = tdistsq; * } * } * * } // next intersection * * } // next intersected primitive * * return gotone; * * } // end of Intersect */ }
/// <summary> /// Calculates intersection points. /// </summary> /// <param name="dist1">1st distance observation.</param> /// <param name="from1">The point the 1st distance was observed from.</param> /// <param name="dist2">2nd distance observation.</param> /// <param name="from2">The point the 2nd distance was observed from.</param> /// <param name="usedefault">True if the default intersection is required (the one that has the /// lowest bearing with respect to the 2 from points). False for the other one (if any).</param> /// <param name="xsect">The position of the intersection (if any).</param> /// <param name="xsect1">The 1st choice intersection (if any).</param> /// <param name="xsect2">The 2nd choice intersection (if any).</param> /// <returns>True if intersections were calculated. False if the distance circles /// don't intersect.</returns> internal static bool Calculate(Observation dist1, PointFeature from1, Observation dist2, PointFeature from2, bool usedefault, out IPosition xsect, out IPosition xsect1, out IPosition xsect2) { // Initialize intersection positions. xsect = xsect1 = xsect2 = null; // Get the 2 distances. double d1 = dist1.GetDistance(from1).Meters; double d2 = dist2.GetDistance(from2).Meters; if (d1 < Constants.TINY || d2 < Constants.TINY) { return(false); } // Form circles with radii that match the observed distances. ICircleGeometry circle1 = new CircleGeometry(from1, d1); ICircleGeometry circle2 = new CircleGeometry(from2, d2); // See if there is actually an intersection between the two circles. IPosition x1, x2; uint nx = IntersectionHelper.Intersect(circle1, circle2, out x1, out x2); if (nx == 0) { return(false); } // If we have 2 intersections, and we need the non-default one, pick up the 2nd // intersection. If only 1 intersection, use that, regardless of the setting for // the "use default" flag. if (nx == 2 && !usedefault) { xsect = x2; } else { xsect = x1; } // Return if both distances are offset points. OffsetPoint offset1 = (dist1 as OffsetPoint); OffsetPoint offset2 = (dist2 as OffsetPoint); if (offset1 != null && offset2 != null) { xsect1 = x1; xsect2 = x2; return(true); } // Reduce observed distances to the mapping plane. ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem; if (offset1 == null) { d1 = d1 * sys.GetLineScaleFactor(from1, xsect); } if (offset2 == null) { d2 = d2 * sys.GetLineScaleFactor(from2, xsect); } // And calculate the exact intersection (like above)... // Form circles with radii that match the observed distances. ICircleGeometry circle1p = new CircleGeometry(from1, d1); ICircleGeometry circle2p = new CircleGeometry(from2, d2); // See if there is still an intersection between the two circles. nx = IntersectionHelper.Intersect(circle1p, circle2p, out x1, out x2); if (nx == 0) { return(false); } // If we have 2 intersections, and we need the non-default one, pick up the 2nd // intersection. If only 1 intersection, use that, regardless of the setting for // the "use default" flag. if (nx == 2 && !usedefault) { xsect = x2; } else { xsect = x1; } xsect1 = x1; xsect2 = x2; return(true); }
/// <summary> /// Calculates the position of the sideshot point. /// </summary> /// <param name="dir">The direction observation (if any).</param> /// <param name="len">The length observation (if any). Could be a <c>Distance</c> or an /// <c>OffsetPoint</c>.</param> /// <returns>The position of the sideshot point (null if there is insufficient data /// to calculate a position)</returns> internal static IPosition Calculate(Direction dir, Observation len) { // Return if there is insufficient data. if (dir == null || len == null) return null; // Get the position of the point the sideshot should radiate from. PointFeature from = dir.From; // Get the position of the start of the direction line (which may be offset). IPosition start = dir.StartPosition; // Get the bearing of the direction. double bearing = dir.Bearing.Radians; // Get the length of the sideshot arm. double length = len.GetDistance(from).Meters; // Calculate the resultant position. Note that the length is the length along the // bearing -- if an offset was specified, the actual length of the line from-to = // sqrt(offset*offset + length*length) IPosition to = Geom.Polar(start, bearing, length); // Return if the length is an offset point. In that case, the length we have obtained // is already a length on the mapping plane, so no further reduction should be done // (although it's debateable). if (len is OffsetPoint) return to; // Using the position we've just got, reduce the length we used to a length on the // mapping plane (it's actually a length on the ground). ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem; double sfac = sys.GetLineScaleFactor(start, to); return Geom.Polar(start, bearing, length * sfac); }
/// <summary> /// Intersects this direction with a specific entity type. /// </summary> /// <param name="ent">The entity type to look for.</param> /// <param name="maxdist">Observation defining the maximum distance between the /// direction's from-point & the intersection. This can either be a <c>Distance</c> /// or an <c>OffsetPoint</c> object.</param> /// <param name="xsect">The position of the intersection (if any). Null if no intersection found.</param> /// <returns>True if an intersection was found.</returns> bool Intersect(IEntity ent, Observation maxdist, out IPosition xsect) { // Initialize the intersection. xsect = null; // Get the max distance. It has to be defined to be SOMETHING. double dist = maxdist.GetDistance(this.From).Meters; if (Math.Abs(dist) < Constants.TINY) return false; // Define the position of the direction line. IPosition from = this.StartPosition; IPosition to = Geom.Polar(from, this.Bearing.Radians, dist); throw new NotImplementedException("Direction.Intersect"); /* // Construct a corresponding line segment. CeLocation start(vfrom); CeLocation end(vto); CeSegment seg(start,end); // Intersect the segment with the map (all features on // the currently active theme). CeLayerList curlayer; CeXObject xseg(seg,&curlayer); // Get the first intersection (if any) with the specified // entity type. UINT4 nprim = xseg.GetCount(); // How many primitives did we intersect? FLOAT8 bestdsq = 10e+38; // Closest distance (squared) so far. FLOAT8 tdistsq; // Test distance (squared). LOGICAL gotone=FALSE; for ( UINT4 i=0; i<nprim; i++ ) { // Get the next thing we intersected. const CeXResult& xres = xseg[i]; const CeLine* const pLine = dynamic_cast<const CeLine* const>(xres.GetpObject()); // Skip if it wasn't a line. if ( !pLine ) continue; // Find the attached arc that has the current theme. Has // to be topological(?) const CeArc* const pArc = pLine->GetpArc(curlayer); // Skip if it doesn't have the desired entity type. if ( pArc && pArc->GetpEntity()!=&ent ) continue; // Determine the intersection on the primitive that is // closest to the start of the direction (ignoring any // intersections that are right at the start of the // direction line). gotone = TRUE; UINT4 nx = xres.GetCount(); CeVertex vtest; for ( UINT4 j=0; j<nx; j++ ) { vtest = xres.GetX1(j); tdistsq = vfrom.DistanceSquared(vtest); if ( tdistsq<bestdsq && tdistsq>TINY ) { xsect = vtest; bestdsq = tdistsq; } // Check any grazing intersection too. if ( xres.IsGrazing() ) { vtest = xres.GetX2(j); tdistsq = vfrom.DistanceSquared(vtest); if ( tdistsq<bestdsq && tdistsq>TINY ) { xsect = vtest; bestdsq = tdistsq; } } } // next intersection } // next intersected primitive return gotone; } // end of Intersect */ }
/// <summary> /// Calculates the intersection point. /// </summary> /// <param name="dir">Direction observation.</param> /// <param name="distance">Distance observation.</param> /// <param name="from">The point the distance was observed from.</param> /// <param name="usedefault">True if the default intersection is required (the one /// closer to the origin of the direction line). False for the other one (if any).</param> /// <param name="xsect">The position of the intersection (if any).</param> /// <param name="xsect1">The 1st choice intersection (if any).</param> /// <param name="xsect2">The 2nd choice intersection (if any).</param> /// <returns>True if intersections were calculated. False if the distance circles /// don't intersect.</returns> internal static bool Calculate(Direction dir, Observation distance, PointFeature from, bool usedefault, out IPosition xsect, out IPosition xsect1, out IPosition xsect2) { // Initialize intersection positions. xsect = xsect1 = xsect2 = null; // Get the distance. double dist = distance.GetDistance(from).Meters; if (dist < Constants.TINY) return false; // Form circle with a radius that matches the observed distance. ICircleGeometry circle = new CircleGeometry(from, dist); // See if there is actually an intersection between the direction & the circle. IPosition x1, x2; uint nx = dir.Intersect(circle, out x1, out x2); if (nx==0) return false; // If we have 2 intersections, and we need the non-default one, pick up the 2nd // intersection. If only 1 intersection, use that, regardless of the setting for // the "use default" flag. if (nx==2 && !usedefault) xsect = x2; else xsect = x1; // Return if the distance is an offset point. OffsetPoint offset = (distance as OffsetPoint); if (offset!=null) { xsect1 = x1; xsect2 = x2; return true; } // Reduce observed distance to the mapping plane. ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem; dist = dist * sys.GetLineScaleFactor(from, xsect); // And calculate the exact intersection (like above)... // Form circle with a radius that matches the reduced distance. ICircleGeometry circlep = new CircleGeometry(from, dist); // See if there is actually an intersection between the direction & the circle. nx = dir.Intersect(circlep, out x1, out x2); if (nx==0) return false; // If we have 2 intersections, and we need the non-default one, pick up the 2nd // intersection. If only 1 intersection, use that, regardless of the setting for // the "use default" flag. if (nx==2 && !usedefault) xsect = x2; else xsect = x1; xsect1 = x1; xsect2 = x2; return true; }
/// <summary> /// Calculates intersection points. /// </summary> /// <param name="dist1">1st distance observation.</param> /// <param name="from1">The point the 1st distance was observed from.</param> /// <param name="dist2">2nd distance observation.</param> /// <param name="from2">The point the 2nd distance was observed from.</param> /// <param name="usedefault">True if the default intersection is required (the one that has the /// lowest bearing with respect to the 2 from points). False for the other one (if any).</param> /// <param name="xsect">The position of the intersection (if any).</param> /// <param name="xsect1">The 1st choice intersection (if any).</param> /// <param name="xsect2">The 2nd choice intersection (if any).</param> /// <returns>True if intersections were calculated. False if the distance circles /// don't intersect.</returns> internal static bool Calculate(Observation dist1, PointFeature from1, Observation dist2, PointFeature from2, bool usedefault, out IPosition xsect, out IPosition xsect1, out IPosition xsect2) { // Initialize intersection positions. xsect = xsect1 = xsect2 = null; // Get the 2 distances. double d1 = dist1.GetDistance(from1).Meters; double d2 = dist2.GetDistance(from2).Meters; if (d1 < Constants.TINY || d2 < Constants.TINY) return false; // Form circles with radii that match the observed distances. ICircleGeometry circle1 = new CircleGeometry(from1, d1); ICircleGeometry circle2 = new CircleGeometry(from2, d2); // See if there is actually an intersection between the two circles. IPosition x1, x2; uint nx = IntersectionHelper.Intersect(circle1, circle2, out x1, out x2); if (nx==0) return false; // If we have 2 intersections, and we need the non-default one, pick up the 2nd // intersection. If only 1 intersection, use that, regardless of the setting for // the "use default" flag. if (nx==2 && !usedefault) xsect = x2; else xsect = x1; // Return if both distances are offset points. OffsetPoint offset1 = (dist1 as OffsetPoint); OffsetPoint offset2 = (dist2 as OffsetPoint); if (offset1!=null && offset2!=null) { xsect1 = x1; xsect2 = x2; return true; } // Reduce observed distances to the mapping plane. ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem; if (offset1==null) d1 = d1 * sys.GetLineScaleFactor(from1, xsect); if (offset2==null) d2 = d2 * sys.GetLineScaleFactor(from2, xsect); // And calculate the exact intersection (like above)... // Form circles with radii that match the observed distances. ICircleGeometry circle1p = new CircleGeometry(from1, d1); ICircleGeometry circle2p = new CircleGeometry(from2, d2); // See if there is still an intersection between the two circles. nx = IntersectionHelper.Intersect(circle1p, circle2p, out x1, out x2); if (nx==0) return false; // If we have 2 intersections, and we need the non-default one, pick up the 2nd // intersection. If only 1 intersection, use that, regardless of the setting for // the "use default" flag. if (nx==2 && !usedefault) xsect = x2; else xsect = x1; xsect1 = x1; xsect2 = x2; return true; }
/// <summary> /// Calculates the intersection point. /// </summary> /// <param name="dir">Direction observation.</param> /// <param name="distance">Distance observation.</param> /// <param name="from">The point the distance was observed from.</param> /// <param name="usedefault">True if the default intersection is required (the one /// closer to the origin of the direction line). False for the other one (if any).</param> /// <param name="xsect">The position of the intersection (if any).</param> /// <param name="xsect1">The 1st choice intersection (if any).</param> /// <param name="xsect2">The 2nd choice intersection (if any).</param> /// <returns>True if intersections were calculated. False if the distance circles /// don't intersect.</returns> internal static bool Calculate(Direction dir, Observation distance, PointFeature from, bool usedefault, out IPosition xsect, out IPosition xsect1, out IPosition xsect2) { // Initialize intersection positions. xsect = xsect1 = xsect2 = null; // Get the distance. double dist = distance.GetDistance(from).Meters; if (dist < Constants.TINY) { return(false); } // Form circle with a radius that matches the observed distance. ICircleGeometry circle = new CircleGeometry(from, dist); // See if there is actually an intersection between the direction & the circle. IPosition x1, x2; uint nx = dir.Intersect(circle, out x1, out x2); if (nx == 0) { return(false); } // If we have 2 intersections, and we need the non-default one, pick up the 2nd // intersection. If only 1 intersection, use that, regardless of the setting for // the "use default" flag. if (nx == 2 && !usedefault) { xsect = x2; } else { xsect = x1; } // Return if the distance is an offset point. OffsetPoint offset = (distance as OffsetPoint); if (offset != null) { xsect1 = x1; xsect2 = x2; return(true); } // Reduce observed distance to the mapping plane. ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem; dist = dist * sys.GetLineScaleFactor(from, xsect); // And calculate the exact intersection (like above)... // Form circle with a radius that matches the reduced distance. ICircleGeometry circlep = new CircleGeometry(from, dist); // See if there is actually an intersection between the direction & the circle. nx = dir.Intersect(circlep, out x1, out x2); if (nx == 0) { return(false); } // If we have 2 intersections, and we need the non-default one, pick up the 2nd // intersection. If only 1 intersection, use that, regardless of the setting for // the "use default" flag. if (nx == 2 && !usedefault) { xsect = x2; } else { xsect = x1; } xsect1 = x1; xsect2 = x2; return(true); }