So, currently I have successfully compiled the program (with RInside) for plotting coordinates on the static maps of Google (on Qt).
Now, I have to plot the coordinates on the map as they are received from the GPS.
Is it possible somehow to display the newly plotted points on the png "on the fly"?
I mean I don't wish to read the png from the harddisk every time I receive a new point.
From here: http://cran.r-project.org/web/packages/png/png.pdf
This package provides an easy and simple way to read,write and display bitmap images stored in the PNG format. It can read and write both files and in-memory raw vectors.
Can this be of any help?
#include <RInside.h>
#include <Rcpp.h>
#include <iostream>
int main (int argc, char *argv[])
{
std :: cout << "\nThank-SO :-)\n";
RInside R (argc, argv);
std :: string txtA = "library(RgoogleMaps)";
std :: string txtB = "png(filename='Rg.png', width=480, height=480)";
std :: string txtC = "lat = c(40.702147,40.718217,40.711614)";
std :: string txtD = "lon = c(-74.012318,-74.015794,-73.998284)";
std :: string txtE = "center = c(mean(lat), mean(lon))";
std :: string txtF = "zoom <- min(MaxZoom(range(lat), range(lon)))";
std :: string txtG = "MyMap <- GetMap(center=center, zoom=zoom, markers='&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc', destfile='My.png')";
std :: string txtH = "tmp <- PlotOnStaticMap(MyMap,lat=c(40.702147,40.711614,40.718217),lon=c(-74.015794,-74.012318,-73.998284),cex=1.5,pch=20,col=c('red', 'blue', 'green'),add=F)";
std :: string txtI = "dev.off()";
R.parseEvalQ (txtA);
R.parseEvalQ (txtB);
R.parseEvalQ (txtC);
R.parseEvalQ (txtD);
R.parseEvalQ (txtE);
R.parseEvalQ (txtF);
R.parseEvalQ (txtG);
R.parseEvalQ (txtH);
R.parseEvalQ (txtI);
return 0;
}
This is the C++
code written with RInside
.
You can plot the map yourself using the png
package that you mention (or other tools), then you need some way of mapping between the plot coordinates and the gps coordinates.
If the region of the map is small enough that you are happy with a cartesian approximation then a simple way is to use the updateusr
function in the TeachingDemos
package to change the plot coordinates to match with your lat/long information, you will need to know the lat and long for 2 points on the map and you can find their original coordinates using the locator
function (or if they are corners then you may not need locator
). Then you can just use the points
function to add points on top of the map without needing to reread or replot it. This is probably fine if the map is of a city or smaller region, but could start to suffer from the approximation if you are trying to show a whole country.
For different projections you can find a way to convert from lat/long to the current plots coordinates, then use points
with the converted coordinates. The sp
package and others may be of help here.
A couple of other packages to consider (if the current functions in the package are not enough, you could still look at the code to get ideas and/or modify the code to use your png file(s)) are RgoogleMaps
and ggmap
.