//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);
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.
You forgot attaching your demonstrated image, hope you can attached it if you still can not solve your problem.
From you description, I know you want to get the perpendicular line for specified line with specified point. You can look at following code, it will ignore the intercepted point which is exactly match a vertex of line.
// Check if the intercepted point is the vertex will be ignore, because we can not create perpendicular line crosses vertex. foreach (Vertex vertex in lineShape.Vertices) { if (new PointShape(vertex).IsWithin(searchingArea)) { continue; } }
Vertex vertex1 = new Vertex(); Vertex vertex2 = new Vertex(); // Find the crossing point is between which two vertices for (int i = 0; i < lineShape.Vertices.Count - 1; i++) { vertex1 = lineShape.Vertices[i]; vertex2 = lineShape.Vertices[i + 1]; LineShape currentLine = new LineShape(new Vertex[] { vertex1, vertex2 }); if (searchingArea.Intersects(currentLine)) { break; } }
Did you set DefaultLineStyle and ApplyUntilZoomLevel properties for InMemoryFeatureLayer which you mentioned.
SituationsLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.StandardColors.Red, 50); SituationsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
And how many perpLines in result collection, I think it should be 2, right? If you still can not see lines on the map, you can set the length longer, my sample code set it to 1.0 And my code is just a sample, it just want to guide you how to do that, but some parameter may not quite right, maybe mislead you. So about how to cut, I don’t want send your code, instead I tell you the steps and you can do by yourself, I think it’s better.
The following steps are how to get the polygons cut by two lines.
Get bounding box of original polygons.
Get the intersected points between two lines and bounding box.
Use four intersected points to create a new polygon.
Get intersection polygon between new polygon and original polygons.
The lines grow from the point in the CenterLine instead of Crossing the CenterLine. You can see it in the Red left line. The Red right line it's how it should be. I will have to review trigonometrybecause I don't use it for a long time.
Concerning the polygon interception, I didn't understud very well what you ment. The lanes can be a corner so if I get the envelope from the four interception points, I could left behind part of the lane.
What I think should be my aproach is (for each intercepted lane):
1) Create the lines
2) Intercept the lane, getting 4 points
3) Splitte the polygon in two polylines using each two points.
4) Join the obtained 2 lines with the original crossing lines an create the polygon.
//LineShape line = new LineShape(new Vertex[] { new Vertex(middleX, middleY), new Vertex(x, y) });
Vertex anotherVertex = new Vertex(middleX * 2 - x, middleY * 2 - y); LineShape line = new LineShape(new Vertex[] { anotherVertex, new Vertex(x, y) }); returnFeatures.Add(line);
The black polygon is a lane, two red lines are intercept lines which cross the lane. And the blue dash envelop is the bounding box of lane which I am said, four blue points are crossing points which you can create a new polygon.
- Split the lane in two polylines: First one from V2 to V4 (PolyLine1) and the other from V1 to V3 (PolyLine2).
- Cut the Intercept lines (the red ones) between V1 and V2 (PolyLine3) and the other from V3 to V4 (PolyLine4).
- Create a polygon using the four polylines (PolyLine1 + PolyLine2 + PolyLine3 + PolyLine4).
Just for you to understand what I'm trying to do.
This problem is only because of the TrackShape will create polygons with bad cut in the lanes.
At this point I can get the polygons intercepted by the TrackShape, that is easy. What I get at this moment is in the next picture (without the red lines).
So the centerLine in the middle (we can barely see it) will gave me the PKs (distances of interception in kilometers), and now I only need the green polygon between the red lines (drawn from one line to the other).
The next image show what I need (without the red lines).
Our developers write a Split method which pass in the polygon and line and return splitted two parts of polygon, I think you can look at it which will be helpful. But the line has some restriction, the start vertex and end vertex of the line should be outside the polygon, the line just has two crossing points with polygon, I think your requirement is fit for it.
I have updated the Split code and added a method called SplitPolygonShapeWithTwoLineShape which pass in a polygon and two lines, that will be more close to what you want.
Can you e-mail Val with this link and send him the code. I think this kind of feature would make a good addition to our code community at code.thinkgeo.com.