0

Can I use QGIS 3.10 to display overlaid encoded google polylines, with the purpose of showing road network activity?

I am using QGIS 3.10.

I have a series of GPS points that go from one origin to ten different destinations, with average journey length 1,000km. The points were uploaded by CSV file and are sorted by journey, then by the appropriate consecutive next location i.e. everything is sequential. The points are derived from an encoded Google overview polyline that has been decoded.

The road network is a separate layer.

The first image shows all journeys' GPS points along a short section of one of the roads (yellow spots, along the yellow road). GPS points along road section

I used the "points to path" tool to make the purple lines, where the paths are created on a per-journey basis and in the correct sequential order. Some sections of the created paths do not align with the road network, despite individual points being accurate. Road, points and lines

The section of road in the screenshot is approximately 35km long, and the max variation between the "point to path" line and the road is 1,750m. This is one of many examples where the variation is significant. I understand QGIS has just drawn from, say, [journey 2; point 21] to [journey 2; point 22] when making the line, and that it has not dropped extra points in between to ensure snapping to the road.

I would like the purple lines (created by "points to path") to follow the road network when they connect the yellow spots. This is because I would like to make a heatmap of road network use. The plan was to follow instructions in Doing heatmap from line data in QGIS? to use QChainage to break the paths back into regularly-spaced points.

Currently, when I plot a heatmap of the individual GPS locations used, I get erroneous gaps. The origin for each journey shown is at the left-hand side of the image, and no destinations exist within the picture. That is, this road has been used a uniform number of times, so the heatmap should be one uniform colour. Heatmap

The heatmap shows what it does because of the random number of GPS locations at random intervals along the same road, I understand that.

How do I make it so that if I plotted a path linking the individual journey points in their respective consecutive order, that path would snap to the road network?

The purpose being I would like to then break the paths back to points, to make a heatmap (unless there is a better way to show something similar with overlaid lines/paths).

Can I make the "point to path" lines snap to the road network?

Or, to put it another way, how do I make the "point to path" lines follow the road when they are created?

The lines are clearly made point-to-point as fits the particular journey, I have no issue with that, but I would like the created paths to snap to the roads and I can't figure out how to do it.

I acknowledge the network analysis "shortest path" tool could help here, but it is incredibly slow on my computer, and the underlying data is already the result of a "shortest path" analysis. Once I work out how to plot the data in this little dataset I will be plotting thousands more journeys.

I am happy to learn Python if it makes this problem go away.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
James
  • 9
  • 2
  • You did not tell us if you have a separate layer for the roads or not. Also, you don't provide sample data or a screenshot of how your data (attributes) look like: do you have some attributes included that makes it possible to identify which point belongs to which journey? This information is critical to be able to help you. – Babel Jun 02 '21 at 05:21
  • If you have a road network you want to use, than you could use network analysis tool, shortest path and set start- and end-point of your gpx-journeys as input. If the gxp-teack follows the shortest possible way in the network, you get what you want. – Babel Jun 02 '21 at 05:25
  • Imagine QGIS putting extra points between 2:21 and 2:22 - that would create a totally weird line. Before calling for a "fix" of the data, have you verified that the other data, the lines, are actually correct? Or maybe they are generalized and your points actually are the correct ones (yeah, unlikely, since GPS, esp. in mountaineous areas, tends to be jumpy). – Erik Jun 02 '21 at 06:37
  • how have you ordered the points in the points to path tool? – JGH Jun 02 '21 at 10:05
  • What happens when you use the Points to Paths (note the plural Paths) plugin, with the Line per Vertex option checked on? – Stu Smith Jun 02 '21 at 13:57
  • @babel - my apologies. Yes there is a separate layer for the roads. The data points were originally uploaded from a CSV, where column A indicated the journey, column B indicated the sequence of the point within the journey, columns C and D had lats and longs. Effectively the points were uploaded in sequential order, so when the paths were plotted they were done in the correct order, if you get what I mean? – James Jun 03 '21 at 07:53
  • @Babel to your second point, yes the network analysis tool looks like it's going to be the winner. However, the journeys are already the product of shortest path computations (done externally to QGIS) and I'm trying to save recalculating. Truth be told I have a few thousand journeys' data but I'm attempting to get everything configured on a small dataset before launching in to what will be a huge amount of processing. The network analysis tool is very slow when compared to, say, the Google Directions API. – James Jun 03 '21 at 07:56
  • @Erik, you're right, it would be odd. When looking at the individual locations without the connecting lines, they are spot on, but they're just at random intervals. The whole thing came about by using the Google Directions API overview polyline and converting it to lats/longs. The whole process has been a massive learning curve. I am flying totally blind. I used MS Excel and VBA to get XML outputs from the API, then a Czech dude's polyline decoder. I totally bastardised the borrowed VBA code, and the decoder was free (massive shout out to Martin). – James Jun 03 '21 at 08:01
  • @JGH per above, they're ordered by virtue of the uploading process through the CSV. Pre-CSV they're ordered by the Google encoded polyline. – James Jun 03 '21 at 08:02
  • @Erik to continue on - I can't work out how to extract the individual steps from the GD API, but that's for another time, and probably another forum. I flat out don't have the skills. Additionally, because I'm working with a large set of origins and destinations, the polyline-to-lats/longs file is huge, and the added accuracy (which I need now!) would totally bog me down.

    I am learning the hard way that taking shortcuts is not the answer. I need to build this whole thing as a database, and use the accurate data accurately.

    – James Jun 03 '21 at 08:07
  • @StuSmith, I just tried, but that plugin doesn't work with 3.10. Thanks for the tip though. There's got to be a way (doesn't there?)! – James Jun 03 '21 at 08:11
  • Do I understand you correct: you could project each point to the nearest line of the network and keep only those lines with points on it (to make it super easy)? – Babel Jun 03 '21 at 10:06
  • James, the PointstoPaths plugin is available at 3.18. You might consider upgrading QGIS in order to get that plugin, plus other features... – Stu Smith Jun 03 '21 at 14:12
  • @Babel yes I suppose so, but then when I make a heatmap of the busy sections of the road network it has random gaps in it. If I plot points, join them with lines, break the lines back into multiple points and make a heatmap there are no gaps, but the heatmap strays from the road network. I will attempt to put extra info into the question above, with screen grabs. – James Jun 04 '21 at 03:59

0 Answers0