[R] PNG-import into R

Roger Bivand Roger.Bivand at nhh.no
Mon Nov 21 21:53:36 CET 2005


On Mon, 21 Nov 2005, Sydler, Dominik wrote:

> Hi there
> 
> I'm looking for a function to read PNG-bitmap-images from a file into R.
> I only found:
>  - the pixmap-package which cannot import png or similar formats
>  - the rimage-package which can only import lossy jpeg-images (the
> convertion from png to jpeg modifies the data!)
> 
> Is there any possibility to read PNG-files?

Under Linux, install GDAL directly then package rgdal from source, I guess 
some variant of this under OSX. Under Windows, install the rgdal binary 
package from Prof. Ripley's repository - for me:

> options("repos")
$repos
                                CRAN                            CRANextra 
                            "@CRAN@" "http://www.stats.ox.ac.uk/pub/RWin" 

or download from:
http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.2/
directly. Then:

> x.png <- GDAL.open(file.choose())
> getDriverLongName(getDriver(x.png))
[1] "Portable Network Graphics"

>From there you use getRasterData() on the bands and subscenes you want, 
GDAL.open() just returns a file handle, letting you choose the parts you 
need. That is probably the least resistance path.

> 
> Thanks for any help
>          Dominic Sydler
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list