I have two separate lists of points and line segments. Each point represents a weather station in a geographical region (e.g., in a state) given by its longitude and latitude. Example data is:
StationID | StationName | StationLongitude | StationLatitude |
---|---|---|---|
S1234 | ABC | -29.3074694 | 130.5229888 |
S222 | XYZ | -30.2906283 | 125.4760338 |
Each line segment is randomly created between any two cities to create a graph network. Example data is:
StartCity | EndCity | StartCityLongitude | StartCityLatitude | EndCityLongitude | EndCityLatitude |
---|---|---|---|---|---|
DEF | STU | -28.9537399 | 124.0125158 | -27.98326 | 121.1545431 |
STU | PML | -27.98326 | 121.1545431 | -26.5812059 | 120.9944966 |
I want to compute the points (i.e., stations) closer to each line segment within a range of 1km and associate the closest point to the respective line segment. In this case, a single point may be close to and associated with more than one line segment.
I can do this using a nested for loop where each line segment is compared to each point and find the minimum distance between them. However, I am looking for any other faster solution that may be available.
Furthermore, if 70% of the total line segments do not have points (i.e., stations) close to them and are associated with at least one station, I want to expand or shrink the line segments (keeping the topology as it is) to make the line segments (at least 70%) associated with closer stations. An example figure is attached to illustrate the problem.
The expected output is a graph network where each edge (in the best case) or at least 70% of edges are associated with stations close to them.
Any help in this regard is appreciated.