Hi,
I have a road with Lanes (Polygons) and a Center Line (ShapeLine). I need to get the Lanes intercepted in the TrackShapeLayer.
I need that the Lanes have a perfect cut (90 degrees angles). So my aproach was:
1 - Use the Track to intercept with the Center Line (Polilyne).- Done
2 - Get the two Points of interception.- Done
3 - Get the Distance to the Begining of the Line (first vertex). - Done
4- For each intercepted point, create a Perpendicular Line with a give lenght.
5- Use those new lines to cut the Polygons.
private void TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
{
try
{
//Get Envelope
AreaBaseShape areaBaseShape = (AreaBaseShape)winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[0].GetShape();
//Get the CenterLineLayer
ShapeFileFeatureLayer CenterLineLayer = (ShapeFileFeatureLayer)winformsMap1.StaticOverlay.Layers["CenterLineLayer"];
//Get All the Features for CenterLineLayer
Collection<Feature> features = CenterLineLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
foreach (Feature feature in features)
{
//Gets the MultipolygonShape and clip it using GetCrossing geometric function.
MultilineShape currentMultilineShape = (MultilineShape)(feature.GetShape());
MultipointShape overlapPointShape = currentMultilineShape.GetCrossing(areaBaseShape);
if (overlapPointShape != null && overlapPointShape.Points.Count >= 2)
{
//Measure Points Distance to origin
int count = 0;
double offset = 0;
Collection<PointShape> points = overlapPointShape.Points;
double[] Distances = new double[points.Count];
foreach (PointShape ps in points)
{
LineShape targetLineShape = currentMultilineShape.Lines[0];
LineShape tempLine = (LineShape)targetLineShape.GetLineOnALine(StartingPoint.FirstPoint, ps);
double crossPointDistance = tempLine.GetLength(GeographyUnit.Meter, DistanceUnit.Meter) - offset;
Distances[count] = crossPointDistance;
count++;
}
}
}
//Get All the Features for LanesLayer
ShapeFileFeatureLayer LanesLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer("LanesLayer");
Collection<Feature> Lanesfeatures = LanesLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
foreach (Feature feature in Lanesfeatures)
{
MultipolygonShape currentMultiPolygonShape = (MultipolygonShape)(feature.GetShape());
MultipolygonShape overlapMultiPolygonShape = currentMultiPolygonShape.GetIntersection(areaBaseShape);
if (overlapMultiPolygonShape != null)
{
SituationsLayer.EditTools.BeginTransaction();
SituationsLayer.EditTools.Add(overlapMultiPolygonShape.GetFeature());
SituationsLayer.EditTools.CommitTransaction();
}
}
//Referesh Map
winformsMap1.Refresh(StaticOverlay);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
//Clear Envelope
winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
}
In the image attached, the red line is the Center Line, there are two blue points and what I need to create are the two green lines and then cut the lanes.
Regards
Miguel