Skip to main content

Hello everyone,

 

I have a dataset contaning several polygons, with sometimes hundreds of vertices and one containing lines, each polygon is paired with a line by a unique ID. I am looking to build a workspace that reads the coordinates of each polygon vertex, projects them along the corresponding line and then calculates the two projections futher down each side of the line or its extension and returns their coordinates. I have used VertexCounter and CoordinateExtractor or CoordinateConcatenator to get the number of vertices and their coordinates and I have a workspace that can calculate the projection of a point along a line, but I am having trouble connecting the two through a Custom Transformer Loop to cycle through all vertices. Any help would be appreciated. Feel free to suggest any improvements to the overall thinking process as well.

Hi @nickmanolis​ I'm not sure of what you mean by projecting to a line. Can you attach some sample data and screen shots of a polygon and its vertices (and lines?) and the output you want to get? thanks


I'm assuming the NeighborFinder is doing the 'projecting the point along the line', with the _closest_candidate_x and y. I don't think this needs to be looped, you just need a Group By your Unique ID on the NeighborFinder, so that each input polygon vertex only considers its paired line. You can also use a Chopper to break a polygon into individual vertices, which may be easier.


Mind that NeighborFinder (and AnchoredSnapper) will not project perpendicular when the line is too short: in that case these transformers will project to the start or end of the line.

With some math, using XY of the vertices and XY of the start and end point of the line, you can calculate the projected point on the line or it's extension.


Hi @nickmanolis​ I'm not sure of what you mean by projecting to a line. Can you attach some sample data and screen shots of a polygon and its vertices (and lines?) and the output you want to get? thanks

Thank you for the reply. I added 2 pictures of an example dataset, as well as the expected results


I think you may need something like this:

Project_point_on_lineThe magic happens in the AttributeManager, where the coordinates of the projected point are calculated

xProj = @Evaluate(((@Value(x2)-@Value(x1))*(@Value(x0)-@Value(x1))+(@Value(y2)-@Value(y1))*(@Value(y0)-@Value(y1)))*(@Value(x2)-@Value(x1))/(@pow((@Value(x2)-@Value(x1)),2)+@pow((@Value(y2)-@Value(y1)),2))+@Value(x1))
 
yProj = @Evaluate(((@Value(x2)-@Value(x1))*(@Value(x0)-@Value(x1))+(@Value(y2)-@Value(y1))*(@Value(y0)-@Value(y1)))*(@Value(y2)-@Value(y1))/(@pow((@Value(x2)-@Value(x1)),2)+@pow((@Value(y2)-@Value(y1)),2))+@Value(y1))

x0,y0 are the coordinates of a vertex of a polygon, x1,y1 and x2,y2 are the coordinates of the start and end point of the corresponding line.

The attribute manager also shows the calculation of the coordinates of the projected point in several steps, as in http://www.sunshine2k.de/coding/java/PointOnLine/PointOnLine.html#step5


Reply