Ok. The point now is that I have the sources (in Fortran) of the program that produces the graph with the map. And have to attach the information about the xrange and yrange to this graph in order for them to be read from R. Id est, I have to write: first longitude, first latitude, last longitude, last latitude, and also, the "figure" coordinates of the bounding box of the map in the figure. If I produce the map in eps, I can open it as a text file from the same fortran rogram, and modify the contents of the eps file in order to put the coordinates information into it. Then, once the fortran program has ended, I convert the eps to png using ImageMagic, because the EBImage library doesn't read eps, but png. In order for the png to contain the same properties as the eps, these have to be correctly defined in the eps. So, the question now is: how can I properly define properties in a eps, so that these are preserved in the convertion to png?. Perhaps this is not for this forum, but I haven't found information about it in the internet. Antonio Serrano aasdelat at aim.com ? -----Original Message----- From: Jim Lemon <drjimlemon at gmail.com> To: Antonio Serrano <aasdelat at aim.com> Sent: Sun, Apr 26, 2015 1:03 am Subject: Re: [R] Interactive maps Hi Antonio, If you mean the normalized figure coordinates (i.e. from 0 to 1) then you want something like this: loc_convert<-function(n=1,xrange=c(0,1),yrange=c(0,1)) { plot_loc<-locator(n=n) plot_loc$x<-plot_loc$x/diff(xrange)+xrange[1] plot_loc$y<-plot_loc$y/diff(yrange)+yrange[1] return(plot$loc) } where xrange and yrange are the longitudes and latitudes respectively. Jim On Sun, Apr 26, 2015 at 1:09 AM, Antonio Serrano <aasdelat at aim.com> wrote:> Thankyou, Jim:> > I have tried your suggestion and I get the followingerror:> > Error en rasterImage(image = "map.eps", : > invalid colorname 'map.eps'> > I have tried with three formats of the same image: svg,gif and eps, with> the same result. > > But I have found a possible betterway to accomplish this objective in the> following thread: >http://r.789695.n4.nabble.com/Loading-an-image-picture-png-jpeg-to-screen-td2244923.html> >In short:> > library(gridExtra) > library(EBImage) > library(RGraphics) >x <- readImage("http://www.google.com/logos/teachersday09.gif")> g1 <-ebimageGrob(x)> dev.new(width=g1$width/72, height=g1$height/72) >plot.new()> grid.draw(g1) > c=locator(n=1, type="n") > > Then, when I clickon the map, I get the "figure" coordinates where I> clicked, and still have totranslate these to longitude-latitude.> > And here comes another question:How can I attach the first longitude, last> longitude, fisrt latitude, lastlatitude, to a JPEG, PNG or TIFF graphic?.> These are the formats supported bythe EBImage package.> > > > Antonio Serrano > aasdelat at aim.com >?> > > -----Original Message----- > From: Jim Lemon<drjimlemon at gmail.com>> To: Antonio Serrano <aasdelat at aim.com> > Sent: Sat,Apr 25, 2015 8:36 am> Subject: Re: [R] Interactive maps > > Hi Antonio, >Try the rasterImage function.> > Jim > > > On Sat, Apr 25, 2015 at > 4:19PM, Antonio Serrano <aasdelat at aim.com> wrote:>> Thank you, Jim. >> >> I >didn't know the existence of the locator() function. But I can see now>> thatI> don't know how to read a graphic image into R to work with it. >> How canI read> a pre-exisiting image into R?. >> >> Thanks again >> >> >>Antonio Serrano>> > aasdelat at aim.com >> ? >> >> >> -----OriginalMessage----->> From: Jim Lemon > <drjimlemon at gmail.com> >> To: AntonioSerrano <aasdelat at aim.com>>> Cc: r-help > mailing list<r-help at r-project.org>>> Sent: Sat, Apr 25, 2015 5:47 am >> > Subject: Re:[R] Interactive maps>> >> Hi Antonio, >> If you do create the map > in R,you can use>> locator(). >> >> Jim >> >> >> On Sat, Apr 25, 2015 at8:37> AM, Antonio Serrano via >> R-help >> <r-help at r-project.org>wrote:>>> >>> > Hello, all: >>> >>> I am new here, >> and have achallenge to present some> graphical data to the user in a >> convenient >>way.>>> >>> The challenge > is to present a map to the user which iscoloured>> with the value of a > variable. Say for example, temperature. Thisis a>> preexisting graph that I > can generate in any format, including svg.I don't>> have >> to produce it > using R. >>> >>> When the user clicksanywhere in the map, the>> coordinates > (longitude and latitude) have to bepassed to R so that this, R,>> can >> look > for the values of othervariables in that location and make another>> graph >> > withthem.>>> >>> Does anyubody know how could I accomplish >this?.>>> >>> >> Thanks in advance. >>> >>> >>> >>> AntonioSerrano>>> > aasdelat at aim.com >>> ? >>> >>> >>> >> [[alternative HTMLversion> deleted]] >>> >>> >>______________________________________________>>> > R-help at r-project.orgmailing>> list -- To UNSUBSCRIBE and more, see >>> >> >https://stat.ethz.ch/mailman/listinfo/r-help>>> PLEASE do read the posting >guide>> http://www.R-project.org/posting-guide.html >>> and providecommented,> minimal, >> self-contained, reproducible code.[[alternative HTML version deleted]]
Hi, You may want to redirect your question to the R-sig-Geo mailing list: https://stat.ethz.ch/mailman/listinfo/r-sig-geo In the meantime, you might consider writing to the 'rasterfile' format. The 'rasterfile' format is very well documented and is to read/write from R; I suspect it would easy for you to write to this format from Fortran. See the details here: http://cran.r-project.org/web/packages/raster/vignettes/rasterfile.pdf Cheers, Ben On Apr 27, 2015, at 11:55 AM, Antonio Serrano via R-help <r-help at r-project.org> wrote:> > > Ok. > > > The point now is that I have the sources (in Fortran) of the program that produces the graph with the map. And have to attach the information about the xrange and yrange to this graph in order for them to be read from R. Id est, I have to write: first longitude, first latitude, last longitude, last latitude, and also, the "figure" coordinates of the bounding box of the map in the figure. > > If I produce the map in eps, I can open it as a text file from the same fortran rogram, and modify the contents of the eps file in order to put the coordinates information into it. > > Then, once the fortran program has ended, I convert the eps to png using ImageMagic, because the EBImage library doesn't read eps, but png. > > In order for the png to contain the same properties as the eps, these have to be correctly defined in the eps. > > So, the question now is: how can I properly define properties in a eps, so that these are preserved in the convertion to png?. > > Perhaps this is not for this forum, but I haven't found information about it in the internet. > > > > > > Antonio Serrano > aasdelat at aim.com > ? > > > > > > > > > -----Original Message----- > From: Jim Lemon <drjimlemon at gmail.com> > To: Antonio Serrano <aasdelat at aim.com> > Sent: Sun, Apr 26, 2015 1:03 am > Subject: Re: [R] Interactive maps > > > > Hi Antonio, > If you mean the normalized figure coordinates (i.e. from 0 to 1) > then > you want something like > this: > > loc_convert<-function(n=1,xrange=c(0,1),yrange=c(0,1)) { > > plot_loc<-locator(n=n) > plot_loc$x<-plot_loc$x/diff(xrange)+xrange[1] > > plot_loc$y<-plot_loc$y/diff(yrange)+yrange[1] > return(plot$loc) > } > > where > xrange and yrange are the longitudes and latitudes respectively. > > Jim > > > On > Sun, Apr 26, 2015 at 1:09 AM, Antonio Serrano <aasdelat at aim.com> wrote: >> Thank > you, Jim: >> >> I have tried your suggestion and I get the following > error: >> >> Error en rasterImage(image = "map.eps", : >> invalid color > name 'map.eps' >> >> I have tried with three formats of the same image: svg, > gif and eps, with >> the same result. >> >> But I have found a possible better > way to accomplish this objective in the >> following thread: >> > http://r.789695.n4.nabble.com/Loading-an-image-picture-png-jpeg-to-screen-td2244923.html >> >> > In short: >> >> library(gridExtra) >> library(EBImage) >> library(RGraphics) >> > x <- readImage("http://www.google.com/logos/teachersday09.gif") >> g1 <- > ebimageGrob(x) >> dev.new(width=g1$width/72, height=g1$height/72) >> > plot.new() >> grid.draw(g1) >> c=locator(n=1, type="n") >> >> Then, when I click > on the map, I get the "figure" coordinates where I >> clicked, and still have to > translate these to longitude-latitude. >> >> And here comes another question: > How can I attach the first longitude, last >> longitude, fisrt latitude, last > latitude, to a JPEG, PNG or TIFF graphic?. >> These are the formats supported by > the EBImage package. >> >> >> >> Antonio Serrano >> aasdelat at aim.com >> > ? >> >> >> -----Original Message----- >> From: Jim Lemon > <drjimlemon at gmail.com> >> To: Antonio Serrano <aasdelat at aim.com> >> Sent: Sat, > Apr 25, 2015 8:36 am >> Subject: Re: [R] Interactive maps >> >> Hi Antonio, >> > Try the rasterImage function. >> >> Jim >> >> >> On Sat, Apr 25, 2015 at >> 4:19 > PM, Antonio Serrano <aasdelat at aim.com> wrote: >>> Thank you, Jim. >>> >>> I >> > didn't know the existence of the locator() function. But I can see now >>> that > I >> don't know how to read a graphic image into R to work with it. >>> How can > I read >> a pre-exisiting image into R?. >>> >>> Thanks again >>> >>> >>> > Antonio Serrano >>> >> aasdelat at aim.com >>> ? >>> >>> >>> -----Original > Message----- >>> From: Jim Lemon >> <drjimlemon at gmail.com> >>> To: Antonio > Serrano <aasdelat at aim.com> >>> Cc: r-help >> mailing list > <r-help at r-project.org> >>> Sent: Sat, Apr 25, 2015 5:47 am >>> >> Subject: Re: > [R] Interactive maps >>> >>> Hi Antonio, >>> If you do create the map >> in R, > you can use >>> locator(). >>> >>> Jim >>> >>> >>> On Sat, Apr 25, 2015 at > 8:37 >> AM, Antonio Serrano via >>> R-help >>> <r-help at r-project.org> > wrote: >>>> >>>> >> Hello, all: >>>> >>>> I am new here, >>> and have a > challenge to present some >> graphical data to the user in a >>> convenient >>> > way. >>>> >>>> The challenge >> is to present a map to the user which is > coloured >>> with the value of a >> variable. Say for example, temperature. This > is a >>> preexisting graph that I >> can generate in any format, including svg. > I don't >>> have >>> to produce it >> using R. >>>> >>>> When the user clicks > anywhere in the map, the >>> coordinates >> (longitude and latitude) have to be > passed to R so that this, R, >>> can >>> look >> for the values of other > variables in that location and make another >>> graph >>> >> with > them. >>>> >>>> Does anyubody know how could I accomplish >> > this?. >>>> >>>> >>> Thanks in advance. >>>> >>>> >>>> >>>> Antonio > Serrano >>>> >> aasdelat at aim.com >>>> ? >>>> >>>> >>>> >>> [[alternative HTML > version >> deleted]] >>>> >>>> >>> > ______________________________________________ >>>> >> R-help at r-project.org > mailing >>> list -- To UNSUBSCRIBE and more, see >>>> >>> >> > https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting >> > guide >>> http://www.R-project.org/posting-guide.html >>>> and provide > commented, >> minimal, >>> self-contained, reproducible code. > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org
Thank you, Ben. I've just subscribed to R-sig-geo as you recommend. I'll post this staff there. Antonio Serrano aasdelat at aim.com ? -----Original Message----- From: Ben Tupper <btupper at bigelow.org> To: Antonio Serrano <aasdelat at aim.com> Cc: r-help <r-help at r-project.org> Sent: Mon, Apr 27, 2015 7:59 pm Subject: Re: [R] Interactive maps Hi, You may want to redirect your question to the R-sig-Geo mailing list: https://stat.ethz.ch/mailman/listinfo/r-sig-geo In the meantime, you might consider writing to the 'rasterfile' format. The 'rasterfile' format is very well documented and is to read/write from R; I suspect it would easy for you to write to this format from Fortran. See the details here: http://cran.r-project.org/web/packages/raster/vignettes/rasterfile.pdf Cheers, Ben On Apr 27, 2015, at 11:55 AM, Antonio Serrano via R-help <r-help at r-project.org> wrote:> > > Ok. > > > The point now is that I have the sources (inFortran) of the program that produces the graph with the map. And have to attach the information about the xrange and yrange to this graph in order for them to be read from R. Id est, I have to write: first longitude, first latitude, last longitude, last latitude, and also, the "figure" coordinates of the bounding box of the map in the figure.> > If I produce the map in eps, I can open it as atext file from the same fortran rogram, and modify the contents of the eps file in order to put the coordinates information into it.> > Then, once thefortran program has ended, I convert the eps to png using ImageMagic, because the EBImage library doesn't read eps, but png.> > In order for the png tocontain the same properties as the eps, these have to be correctly defined in the eps.> > So, the question now is: how can I properly define properties ina eps, so that these are preserved in the convertion to png?.> > Perhapsthis is not for this forum, but I haven't found information about it in the internet.> > > > > > Antonio Serrano > aasdelat at aim.com >?> > > > > > > > > -----Original Message----- > From:Jim Lemon <drjimlemon at gmail.com>> To: Antonio Serrano <aasdelat at aim.com>> Sent: Sun, Apr 26, 2015 1:03 am > Subject: Re: [R] Interactive maps> > > > Hi Antonio, > If you mean the normalized figure coordinates(i.e. from 0 to 1)> then > you want something like > this: > >loc_convert<-function(n=1,xrange=c(0,1),yrange=c(0,1)) {> >plot_loc<-locator(n=n)> plot_loc$x<-plot_loc$x/diff(xrange)+xrange[1] > >plot_loc$y<-plot_loc$y/diff(yrange)+yrange[1]> return(plot$loc) > } > >where> xrange and yrange are the longitudes and latitudes respectively. > >Jim> > > On > Sun, Apr 26, 2015 at 1:09 AM, Antonio Serrano<aasdelat at aim.com> wrote:>> Thank > you, Jim: >> >> I have tried yoursuggestion and I get the following> error: >> >> Error enrasterImage(image = "map.eps", :>> invalid color > name 'map.eps' >> >>I have tried with three formats of the same image: svg,> gif and eps, with >>the same result.>> >> But I have found a possible better > way toaccomplish this objective in the>> following thread: >> >http://r.789695.n4.nabble.com/Loading-an-image-picture-png-jpeg-to-screen-td2244923.html>>>> > In short: >> >> library(gridExtra) >> library(EBImage) >>library(RGraphics)>> > x <-readImage("http://www.google.com/logos/teachersday09.gif")>> g1 <- >ebimageGrob(x)>> dev.new(width=g1$width/72, height=g1$height/72) >> >plot.new()>> grid.draw(g1) >> c=locator(n=1, type="n") >> >> Then, when Iclick> on the map, I get the "figure" coordinates where I >> clicked, andstill have to> translate these to longitude-latitude. >> >> And here comesanother question:> How can I attach the first longitude, last >> longitude,fisrt latitude, last> latitude, to a JPEG, PNG or TIFF graphic?. >> These arethe formats supported by> the EBImage package. >> >> >> >> AntonioSerrano>> aasdelat at aim.com >> > ? >> >> >> -----OriginalMessage----->> From: Jim Lemon > <drjimlemon at gmail.com> >> To: AntonioSerrano <aasdelat at aim.com>>> Sent: Sat, > Apr 25, 2015 8:36 am >> Subject:Re: [R] Interactive maps>> >> Hi Antonio, >> > Try the rasterImagefunction.>> >> Jim >> >> >> On Sat, Apr 25, 2015 at >> 4:19 > PM,Antonio Serrano <aasdelat at aim.com> wrote:>>> Thank you, Jim. >>> >>> I >>> didn't know the existence of the locator() function. But I can see now >>>that> I >> don't know how to read a graphic image into R to work withit.>>> How can > I read >> a pre-exisiting image into R?. >>> >>> Thanksagain>>> >>> >>> > Antonio Serrano >>> >> aasdelat at aim.com >>>?>>> >>> >>> -----Original > Message----- >>> From: Jim Lemon >><drjimlemon at gmail.com>>>> To: Antonio > Serrano <aasdelat at aim.com> >>> Cc:r-help>> mailing list > <r-help at r-project.org> >>> Sent: Sat, Apr 25, 20155:47 am>>> >> Subject: Re: > [R] Interactive maps >>> >>> HiAntonio,>>> If you do create the map >> in R, > you can use >>>locator().>>> >>> Jim >>> >>> >>> On Sat, Apr 25, 2015 at > 8:37 >>AM, Antonio Serrano via>>> R-help >>> <r-help at r-project.org> > wrote: >>>>>>>> >> Hello, all: >>>> >>>> I am new here, >>> and have a >challenge to present some>> graphical data to the user in a >>>convenient>>> > way. >>>> >>>> The challenge >> is to present a map tothe user which is> coloured >>> with the value of a >> variable. Say forexample, temperature. This> is a >>> preexisting graph that I >> cangenerate in any format, including svg.> I don't >>> have >>> to produceit>> using R. >>>> >>>> When the user clicks > anywhere in the map,the>>> coordinates >> (longitude and latitude) have to be > passed to R sothat this, R,>>> can >>> look >> for the values of other > variables inthat location and make another>>> graph >>> >> with > them. >>>> >>>>Does anyubody know how could I accomplish>> > this?. >>>> >>>> >>>Thanks in advance.>>>> >>>> >>>> >>>> Antonio > Serrano >>>> >>aasdelat at aim.com>>>> ? >>>> >>>> >>>> >>> [[alternative HTML >version>> deleted]] >>>> >>>> >>> >______________________________________________>>>> >>R-help at r-project.org> mailing >>> list -- To UNSUBSCRIBE and more, see >>>>>>> >> > https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do readthe posting>> > guide >>> http://www.R-project.org/posting-guide.html >>>>and provide> commented, >> minimal, >>> self-contained, reproduciblecode.> > > > > > [[alternative HTML version deleted]] > >______________________________________________> R-help at r-project.org mailinglist -- To UNSUBSCRIBE and more, see>https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal,self-contained, reproducible code. Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org [[alternative HTML version deleted]]