Save plot as Geotiff

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Save plot as Geotiff

Arnaud Mosnier
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
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Save plot as Geotiff

Barry Rowlingson
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.

 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 <[hidden email]> 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
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Save plot as Geotiff

Arnaud Mosnier
Thanks Barry. That's a good idea that I may use/test if there is no other
option (I hope another one exists! :-) )

Arnaud

2018-02-07 11:00 GMT-05:00 Barry Rowlingson <[hidden email]>:

> 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.
>
>  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 <[hidden email]>
> 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
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Save plot as Geotiff

Roger Bivand
Administrator
In reply to this post by Barry Rowlingson
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 <[hidden email]> 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
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> 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: [hidden email]
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Save plot as Geotiff

Arnaud Mosnier
Better late than never.
Thanks Roger !

Arnaud

2018-02-07 13:58 GMT-05:00 Roger Bivand <[hidden email]>:

> 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 <[hidden email]>
>> 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
>>> [hidden email]
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> 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: [hidden email]
> http://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo