0

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.

enter image description here

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.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103
bsha
  • 1
  • 3
  • Example data & expected o/p might be helpful in understanding question better. – Abhishek Jul 03 '22 at 12:59
  • @Abhishek I have updated the question with example data and expected output. – bsha Jul 03 '22 at 20:05
  • You say that each node represents a city. Then you say that you shift each node a certain distance. How do you shift a city!? – ravenspoint Jul 04 '22 at 01:33
  • Initially, each node is created using the latitude and longitude of cities. If the randomly created edges between the nodes are closer to the stations, then we create new latitude and longitude for each node by scaling (expanding or shrinking) the network nodes to a certain distance. For example, move each node either apart or close to every other node by 10 meters to expand or shrink the network. – bsha Jul 04 '22 at 02:37

1 Answers1

0

If you have great many point and lines then you will need to avoid checking the distance ( an expensive calculation ) from a line to EVERY point.

You need to consider only points that are reasonable close to the line, and not bother calculating the distance to points that are hopelessly far away.

This is a standard problem. It is solved by storing the points in a quadtree ( for 2D problems https://en.wikipedia.org/wiki/Quadtree ) or an octree ( for 3D problems )

Comparing performance of quadtree and simple search through vector of points in finding neighbours of a point. If there are less than 100 points to search, the performance is similar, at less than a microsecond for each search. For more than 100 points, the advantage of a quadtree becomes significant.

enter image description here


re "expanding or shrinking a line"

I do not know what this means. Something like this?

enter image description here

The circle is a station and the line is bent to pass close to the station.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103
  • I have updated the question with example data. Can you please provide more information or an example algorithm that may be helpful? – bsha Jul 03 '22 at 20:08
  • Do you know how to store your Stations in a quadtree ( you are working in 2D )? You might want to look at my C++ implementation of this at https://github.com/JamesBremner/quadtree ( I notice you are using python which will not have sufficient performance if you have a large number of stations ( > 100 ) ) – ravenspoint Jul 03 '22 at 20:41
  • Yes, I am working in 2D and using Python. I looked at your C++ implementation but could not properly understand that how it will fit to solve my problem or I could write a Python equivalent of it? Can you please describe it in a general algorithmic way if not in Python? Furthermore, how can I know when and how to shrink and expand the network size? Sorry, if I am asking a bit silly questions. – bsha Jul 03 '22 at 20:50
  • Have you read the Wikipedia article about quadtrees. In general terms, the quadtree allows you to address the stations and only the stations that are close to your road. Setting up the quadtree is a performance hit, but avoiding having to search EVERY station each time will prove beneficial if you have a lot of stations. Did you look at the performance graph I posted to the github repo? – ravenspoint Jul 03 '22 at 21:01
  • Yes, I looked at the performance graph. In my case, it is a direct skyway line between any two locations rather than a road. I just want to compute the distance from each line to the closest station and move each line equally inside (shrink) or outside (expand) in the graph network to make them closer to the stations. However, I don't know how can I find when to shrink or expand and how to shrink and expand each line by a certain distance to make them closer to the stations? – bsha Jul 03 '22 at 21:15
  • I do not understand what you mean by expanding or shrinking a line. Please post a sketch showing what this looks like for a line and a station. – ravenspoint Jul 03 '22 at 21:19
  • Please edit the title of your question. It asks about finding points, not what seems to be your real concern. – ravenspoint Jul 03 '22 at 21:24
  • I have added an example figure to illustrate the expansion and shrinking. I have also updated the title. – bsha Jul 03 '22 at 21:38