[R-sig-Geo] Save plot as Geotiff

Roger Bivand Roger.Bivand at nhh.no
Wed Feb 7 19:58:49 CET 2018


On Wed, 7 Feb 2018, Barry Rowlingson wrote:

> I'd do this by saving the image on the graphics device as a PNG, then
> creating a "world" file (with extension PNGW) from the coordinates of the
> corners and the resolution of the PNG. This is a six line text file with
> sufficient information to georeference a grid. That's enough for `gdal` to
> understand it, and then the `gdal` utilities can convert it to a GeoTIFF
> (or load into R using `raster` and then save as a GeoTIFF).
>
> The tricky bit might be finding the corner coordinates of the graphics
> device image. This is complicated by R leaving space for margins, or not
> using your coordinate system.

Right - see the example in ASDAR 1st edition, chapter 4 chunks 42-44 in

http://www.asdar-book.org/data.php?chapter=3 (zero-based php)

which has par(mar=c(0,0,0,0), xaxs="i", yaxs="i") and widths and heights 
from maptools::GE_SpatialGrid().

Roger

>
> If this is a base graphics plot using the coordinate system units then you
> can probably get them via some combination of the par() values, or you
> might have set the margins to zero and that gives you the corners from
> par()$usr (I think).
>
> If its grid graphics (like spplot) then.... uhhh. someone else probably
> knows how to do it.
>
> Barry
>
>
> On Wed, Feb 7, 2018 at 3:07 PM, Arnaud Mosnier <a.mosnier at gmail.com> wrote:
>
>> Hi,
>>
>> Long version:
>> I made a plot (a map) including SpatialPolygons representing the coast of
>> my region of interest, and a SpatialPointsDataframe representing locations
>> of cities, and I want to save this map in GeoTiff format to allow other
>> people to use this map as a georeferenced background without having to
>> manage the various data sources. Is there a package/function in R that
>> would allow me to do that?
>> Note that converting the Spatial* objects to the raster format is not an
>> option because I want to be able to see the names of the cities on the map.
>>
>>
>> In short:
>> Is there a way to save a plot composed of Spatial* elements in a GeoTiff
>> format?
>>
>> Thanks
>>
>> Arnaud
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand at nhh.no
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en



More information about the R-sig-Geo mailing list