C # Dynamic Segmentation Based on the route Point Set

Source: Internet
Author: User

/// <Summary>
/// Segment the data based on the start and end point to return a set of result points
/// </Summary>
Public ObservableCollection <Point> BuildDrawLineData (ObservableCollection <Point> MapPointList, string StartPeg, string StopPeg)
{
ObservableCollection <Point> Result = new ObservableCollection <Point> ();
Double StartValue = this. MathPegNo (StartPeg );
Double StopValue = this. MathPegNo (StopPeg );
If (StartValue> 1)
MapPointList = this. SplitLineByStartLength (MapPointList, StartValue );
// Intercepted distance
Double ResultLength = StopValue-StartValue;
// The total distance in the segmentation Calculation
Double TotalLength = 0.0;
// Segment distance in segment Calculation
Double FtrLength = 0.0;
// Vertex object in Calculation
Point pt1, pt2;
// Cyclically vertex set and calculate
For (int I = 0; I <MapPointList. Count; I ++)
{
If (I + 1 <MapPointList. Count)
{
Pt1 = MapPointList [I];
Pt2 = MapPointList [I + 1];
FtrLength = this. GetDistance (pt1.Y, pt1.X, pt2.Y, pt2.X );
TotalLength + = FtrLength;
If (TotalLength <ResultLength)
{
// Add the midpoint of the Set
Result. Add (pt1 );
}
Else
{
// Obtain the point in the current line after exceeding the value
Double RemainderLength = 0;
// The Truncation of the last line
RemainderLength = ResultLength-(TotalLength-FtrLength );
// The triangle ratio is calculated for a street.
Double x = Math. Abs (pt2.X-pt1.X );
Double y = Math. Abs (pt2.Y-pt1.Y );
Double x_x = x * (RemainderLength/FtrLength );
Double y_y = y * (RemainderLength/FtrLength );
// Determine the direction and calculate X
If (pt1.X> pt2.X)
X_x = pt1.X-x_x;
Else
X_x = pt1.X + x_x;
// Determine the direction and calculate Y
If (pt1.Y> pt2.Y)
Y_y = pt1.Y-y_y;
Else
Y_y = pt1.Y + y_y;
// Add the last vertex to the result
Result. Add (new Point (x_x, y_y ));
Break;
}
}
Else // Add the last Vertex
Result. Add (MapPointList. Last ());
}
Return Result;
}

// Truncate the vertex set whose supervertex is not zero
Private ObservableCollection <Point> SplitLineByStartLength (ObservableCollection <Point> MapPointList, double StartLength)
{
ObservableCollection <Point> Result = new ObservableCollection <Point> ();
// The total distance in the segmentation Calculation
Double TotalLength = 0.0;
// Segment distance in segment Calculation
Double FtrLength = 0.0;
// Vertex object in Calculation
Point pt1, pt2;
// The amount before the start. This is the first check that exceeds the start point.
Bool IsFirst = true;
// Cyclically vertex set and calculate
For (int I = 0; I <MapPointList. Count; I ++)
{
If (I + 1 <MapPointList. Count)
{
Pt1 = MapPointList [I];
Pt2 = MapPointList [I + 1];
FtrLength = this. GetDistance (pt1.Y, pt1.X, pt2.Y, pt2.X );
TotalLength + = FtrLength;
If (TotalLength> StartLength)
{
If (IsFirst)
{
IsFirst = false;
// Obtain the point in the current line after exceeding the value
Double RemainderLength = 0;
// The Truncation of the last line
RemainderLength = StartLength-(TotalLength-FtrLength );
// The triangle ratio is calculated for a street.
Double x = Math. Abs (pt2.X-pt1.X );
Double y = Math. Abs (pt2.Y-pt1.Y );
Double x_x = x * (RemainderLength/FtrLength );
Double y_y = y * (RemainderLength/FtrLength );
// Determine the direction and calculate X
If (pt1.X> pt2.X)
X_x = pt1.X-x_x;
Else
X_x = pt1.X + x_x;
// Determine the direction and calculate Y
If (pt1.Y> pt2.Y)
Y_y = pt1.Y-y_y;
Else
Y_y = pt1.Y + y_y;
// Add the last vertex to the result
Result. Add (new Point (x_x, y_y ));
}
Else // sort the vertex set after the start point
Result. Add (pt1 );
}
}
Else // Add the last Vertex
Result. Add (MapPointList. Last ());
}
Return Result;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.