NEWBIE : Can GMT plot trajectories on a map in realtime?

Hello,

I am complete newbie on GMT. I have no experience what so ever. I am in search of mapping tool to use in my thesis. I need to plot streaming trajectories on a map. The trajectories or routes of vehicles need to be update when the data becomes available. Can GMT do that.

I am long time linux/unix user. I understand the GMT philosophy but not sure about real time map update capabilities. If the answer is yes, I am going to invest on it. If the answer is no, could GMT community advise me a tool that can do that?

I am mainly coding in julia. GMT cought my attension since it has julia api.

I appreciate any directions, insights.

Thanks in advance

Hi @benibilme,

Thanks for your interest in GMT. But we need to know a bit more about your specific needs. In particular the β€œplot streaming trajectories”. How are those calculated? And the update procedure, you do that with some Julia code I guess.
Overall, I would say β€œno problem” but as mentioned, more info is wellcome.

1 Like

Hello,

Thank you for responding.

I am planing to plot vehicle data in general structure of (vehicle_id, time, lat, long). The data will be plotted as it is received from a channel.

For the sake of creating a working environment, I will try to plot open taxi data that exists in the internet for several cities, like new york, beijin, cincinnati, stockholm etc. I will read the data from file and send through channel to simulate the environment. Plotting process will simply plot received location of the vehicle on the map in addition to previously plotted locations. I need to extend the trajectory to last updated location for the trajectory to be seen. The underlaying map needs to be updated as soon as I update the trajectory. I will have to update the map at least every minute or so with many points of many trajectories.

Can GMT do that?

Ok, to be honest I don’t know without experimenting. Yes, sure it can do that. But will it be at stakes with your time constrains, that’s the point.

Let me explain a little more how GMT plotting works. It uses what we call the PostScript layer cake model. That is, successive plotting commands append to the same PS file. When finished we β€œclose” the postscript and call ghostscript to render the PS in the desired raster format (or PDF). While this is a fast process (seconds or less), depending on the figure complexity, the gs rasterization may take a while (or not).

Since you want to (continuously) update a figure, there are tricks one may do to make a copy of the (non closed) previous PS version, append a new layer, save it for next round, close it, rasterize and display.

So, yes it will work. But in due time? Well only experimenting with tell.

2 Likes

Hello,

vehicle-trajectory.csv.zip (28.1 KB)
I have uploaded a single vehicle trajectory with 1774 points. It is taken from a dataset known as swedish taxi dataset. File structure is as follows

date,lat,long,vehicle
2018-10-02T17:06:00.0,59.42190595212989,17.822133881640568,1

I am trying to read the gmz cookbok, it seems it will take some time to come up a solution that you describe. I looks heavy and I really do not know much about cartography. I really do not want to be rude and force you, but I really appreciate if you could try this out and share the code if possible along with your opinion. It may well be a future reference anyone interested.

You can think as if more or less at every time stamp, the data were being received and the map were needed to be updated.

Based on your opinion, I will commit to gmz.

Thanks for the support.

The GMT CookBook is a good read but is big and covers many parts that you probably are not interested. The other thing is that’s it uses plain GMT syntax and in Julia you’ll be using (if you will) the GMT.jl syntax where all options have long/understandable names. I recommend you to read the GMT.jl manual whose best version is currently hosted here Home It has several examples of different plot types.

Now your data. That’s a small dataset and I make here an example on how to plot it.

using GMT

D = gmtread("vehicle-trajectory.csv", colinfo=:T, header=1)
Comment:        ["date,lat,long,vehicle\n"]
BoundingBox: [1.53849996e9, 1.54228644e9, 59.1743319663827, 59.651614020949474, 17.624479301268085, 18.701834940784984, 1.0, 1.0]
1774Γ—4 GMTdataset{Float64, 2}
  Row β”‚ col.1      col.2    col.3    col.4
      β”‚ Float64    Float64  Float64  Float64
──────┼──────────────────────────────────────
    1 β”‚ 1.5385e9   59.4219  17.8221      1.0
    2 β”‚ 1.5385e9   59.4219  17.8221      1.0
    3 β”‚ 1.5385e9   59.4219  17.8221      1.0
    4 β”‚ 1.5385e9   59.4219  17.8221      1.0
...

the colinfo=:T and header=1 options were used to tell the data reader that first column has time and the file has one header line. Now we want to make a plot with columns 2 and 3 or, more exact, with columns 3 and 2 because GMT plots xy not yx (lat,long is the equivalent of y,x in Cartesian). If you look at the BoundingBox info above it has the min/max for each column so from it we can pick our map boundaries. To give an idea of the data location I’ll plot it over a basemap with land/ocean info. Since the data has many gaps that would make a first ugly map with stray lines connecting the gaps the easiest it plot the points locations.

coast(region=(17.6,18.75,59.1,59.7), land=:lightbrown, proj=:guess)
plot!(D[:,2:3], yx=true, marker=:point, show=1)

There ways of automatically detecting the track gaps (the gap option) that can be used to make line plots.

This is a small dataset so no need to worry with updating strategies, Just redo the plot again when new data arrive. But ofc there must be a limit to that.

I’m not very experimented with data that depends on time. GMT has the tools for it but you can also use DataFrames. This little seismicity tutorial is a good example on how to deal with time too.