Skip to main content
Solved

Nearest neighbour at an set angle


aron
Supporter
Forum|alt.badge.img+16
  • Supporter

I have a set of point objects with rotation attributes. I would like to use this rotational value to go in a straight line in that direction until it encounters something. In this case it will be a line object. Finally I would like to retrieve a attribute from this neighbouring line.

The Neighbour finder will pick the nearest object, but I want to pick the first object along the points bearing/heading. Is there some way to do this?

Best answer by takashi

Hi @aron, thanks for your additional description. I got it. My idea is:

  1. Counter x 2: Add unique ID (e.g. "_point_id") to the source points; add unique ID (e.g. "_line_id") to the target lines.
  2. CoordinateExtractor (Mode: Specify Coordinate, Coordinate Index: 0): Extract coordinates (_x, _y) of the source points.
  3. VertexCreator (Mode: Add Point, X Value: _x + <maximum distance>, Y Value: _y): Transform each point to a horizontal line. Here, the <maximum distance> is the distance within which you are going to find a neighboring line.
  4. Rotator (Rotation Angle: <rotation angle>, X Origin: _x, Y Origin: _y): Rotate the line around the coordinates of the source point in order to head the line to the "heading" direction.
  5. Intersector (Accumulation Mode: Merge Attributes): Send both the target lines and the rotated lines to the Intersector together.
  6. Tester: Select the Node (point) features which have both "_point_id" and "_line_id". The resulting features would be the intersections between the target lines and the rotated lines.
  7. NeighborFinder (Group By: _point_id, Number of Neighbors to Find:1, Maximum Distance: <maximum distance>): Send the source points (having "_point_id") to the Base port and send the intersections (having both "_point_id" and "_line_id") to the Candidate port. The features output via the Matched port would have "_line_id" of the closest line crossing the imaginary line drawn in the "heading" direction from the base point.
View original
Did this help you find an answer to your question?

7 replies

erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • February 5, 2018

The NeighborFinder can be set to use a list to find multiple objects.

It will also list the angle where it found the object.

Then you can select from the list (after sorting by distance) the first that matches the required angle).

Hope this helps.


aron
Supporter
Forum|alt.badge.img+16
  • Author
  • Supporter
  • February 5, 2018

Unfortunately I do not think that would solve my problem. None of the target lines are straight. And I believe that the NeighborFinder would return the nearest point to the base for each line? So it would be quite unlikely that any of these would be exactly the same as the bearing from the point object.


takashi
Influencer
  • February 5, 2018
I'm afraid that many users including me do not understand correctly what "bearing/heading" means. Could you please describe the requirement in plain words? It would be ideal if you could post screenshots illustrating desired spatial relations between the point and target line.

 

 


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • February 5, 2018

I would take your point and create an arbitrary long line along the bearing. Send the new line and the reference lines to a LineOnLineOverlayer. Then a SpatialFilter to get the line segment that intersects the original point.

 

That line segment will now have the attributes of the line that intersected it, which is the first line along your heading.

 

Caveat: the analysis would have to be run on a per point basis, as otherwise the first intersecting line might be from another point instead of a reference line.


aron
Supporter
Forum|alt.badge.img+16
  • Author
  • Supporter
  • February 5, 2018
takashi wrote:
I'm afraid that many users including me do not understand correctly what "bearing/heading" means. Could you please describe the requirement in plain words? It would be ideal if you could post screenshots illustrating desired spatial relations between the point and target line.

 

 

These are nautical terms i suppose, and I understand your confusion since I used them a bit carelessly. What I am after is the heading of my point object, the direction my nose would point if I was standing in that spot and rotated the same direction as the point object. What I would like to know is what I will "hit" if I start "walking" straight forward, following my nose, in the same direction as the rotation attribute.

 

 

So I have a point object with a rotation value. I then draw a imaginary line from that point at the same angle as the rotation. I would like to know which object out there my imaginary "heading line" touches first.

 

 

(A bearing is the angle from ones heading to a object eg a lighthouse or another boat. In this case they are kind of the same, but that is usually not the case, so sorry about any confusion)

 

 


takashi
Influencer
  • Best Answer
  • February 6, 2018

Hi @aron, thanks for your additional description. I got it. My idea is:

  1. Counter x 2: Add unique ID (e.g. "_point_id") to the source points; add unique ID (e.g. "_line_id") to the target lines.
  2. CoordinateExtractor (Mode: Specify Coordinate, Coordinate Index: 0): Extract coordinates (_x, _y) of the source points.
  3. VertexCreator (Mode: Add Point, X Value: _x + <maximum distance>, Y Value: _y): Transform each point to a horizontal line. Here, the <maximum distance> is the distance within which you are going to find a neighboring line.
  4. Rotator (Rotation Angle: <rotation angle>, X Origin: _x, Y Origin: _y): Rotate the line around the coordinates of the source point in order to head the line to the "heading" direction.
  5. Intersector (Accumulation Mode: Merge Attributes): Send both the target lines and the rotated lines to the Intersector together.
  6. Tester: Select the Node (point) features which have both "_point_id" and "_line_id". The resulting features would be the intersections between the target lines and the rotated lines.
  7. NeighborFinder (Group By: _point_id, Number of Neighbors to Find:1, Maximum Distance: <maximum distance>): Send the source points (having "_point_id") to the Base port and send the intersections (having both "_point_id" and "_line_id") to the Candidate port. The features output via the Matched port would have "_line_id" of the closest line crossing the imaginary line drawn in the "heading" direction from the base point.

takashi
Influencer
  • February 6, 2018
takashi wrote:

Hi @aron, thanks for your additional description. I got it. My idea is:

  1. Counter x 2: Add unique ID (e.g. "_point_id") to the source points; add unique ID (e.g. "_line_id") to the target lines.
  2. CoordinateExtractor (Mode: Specify Coordinate, Coordinate Index: 0): Extract coordinates (_x, _y) of the source points.
  3. VertexCreator (Mode: Add Point, X Value: _x + <maximum distance>, Y Value: _y): Transform each point to a horizontal line. Here, the <maximum distance> is the distance within which you are going to find a neighboring line.
  4. Rotator (Rotation Angle: <rotation angle>, X Origin: _x, Y Origin: _y): Rotate the line around the coordinates of the source point in order to head the line to the "heading" direction.
  5. Intersector (Accumulation Mode: Merge Attributes): Send both the target lines and the rotated lines to the Intersector together.
  6. Tester: Select the Node (point) features which have both "_point_id" and "_line_id". The resulting features would be the intersections between the target lines and the rotated lines.
  7. NeighborFinder (Group By: _point_id, Number of Neighbors to Find:1, Maximum Distance: <maximum distance>): Send the source points (having "_point_id") to the Base port and send the intersections (having both "_point_id" and "_line_id") to the Candidate port. The features output via the Matched port would have "_line_id" of the closest line crossing the imaginary line drawn in the "heading" direction from the base point.
This screenshot illustrates my intention.

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings