Tuesday 16 February 2016

coordinate system - How to plot a point on a static Google map [png]?



http://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Ccolor:red%7Clabel:C%7C40.718217,-73.998284&sensor=false


shows a static map which is a png file.


If I do have a coordinate which lies between the coordinates of this static map file, then how should I plot that point on this map (which is basically a png)?


EDIT:


I would be doing it offline. Can't use the maps API. Will save that map as a PNG, then I have to plot the points.



Answer



The way to do this in R is as follows: http://cran.r-project.org/web/packages/RgoogleMaps/RgoogleMaps.pdf


library (RgoogleMaps)
png (filename = "plotted.png", width=480, height=480)


lat = c(40.702147,40.718217,40.711614)
lon = c(-74.012318,-74.015794,-73.998284)
center = c(mean(lat), mean(lon))
zoom <- min (MaxZoom (range(lat), range(lon)))

MyMap <- GetMap (center = center,
zoom = zoom,
markers = '&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc',
destfile = 'original.png');


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)

dev.off()


To compile the above R code in C++, R has provided a package named RInside:
http://dirk.eddelbuettel.com/code/rinside.html


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...