Find points near LineString in mongodb sorted by distance

后端 未结 2 524
难免孤独
难免孤独 2021-02-04 10:28

I have an array of points representing a street (black line) and points, representing a places on map (red points). I want to find all the points near the specified street, sort

2条回答
  •  感情败类
    2021-02-04 10:55

    As you said Mongo's $near only works on points not lines as the centre point however if you flip your premise from find points near the line to find the line near the point then you can use your points as the centre and line as the target

    this is the difference between

    foreach line find points near it
    

    and

    foreach point find line near it
    

    if you have a large number of points to check you can combine this with nevi_me's answer to reduce the list of points that need checking to a much smaller subset

提交回复
热议问题