oce map projection

[This article was first published on Dan Kelley Blog/R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Introduction

Soon after map projections were added to Oce, bug reports showed that coastline plots in some projections were subject to anomalous lines that run horizontally on the plot. A ad-hoc scheme was code to try to prevent this, but it does not always work. Problems are compounded for filled coastlines.

I had thought this was a basic problem of all projection coding, until I happened to try using the projr package instead of mapproj to carry out the projections. The result is that the annoying lines went away.

I am still thinking about whether to make a transition in Oce. The proj4 syntax is too tricky for simple inclusion in Oce, and tricky, and users (including me) are accustomed to the existing syntax, so it would be necessary to convert the internal linkage in a somewhat nontrivial way. Nevertheless, the point of the present post is simply to illustrate that the problem is solved, at least in one test case.

Test case

First, load libraries and extract the coastline.

1
library(oce)
## Loading required package: methods
## Loading required package: mapproj
## Loading required package: maps
1
2
3
4
5
library(proj4)
library(mapproj)
data(coastlineWorld)
lon <- coastlineWorld[["longitude"]]
lat <- coastlineWorld[["latitude"]]

Next, plot with existing (mapproj) projection.

1
2
3
4
par(mar = c(3, 3, 1, 1), mgp = c(2, 0.7, 0))
xy <- mapproject(coastlineWorld[["longitude"]], coastlineWorld[["latitude"]], 
    proj = "mollweide")
plot(xy$x, xy$y, type = "l", asp = 1)

center

Finally, plot with proposed (proj4) projection.

1
2
3
par(mar = c(3, 3, 1, 1), mgp = c(2, 0.7, 0))
xy <- project(cbind(lon, lat), "+proj=moll")
plot(xy[, 1], xy[, 2], type = "l", asp = 1)

center

Conclusions

At least in this example, the proj4 package produces better coastlines, somehow being clever enough to cut the polygons that cross the “edge” of the earth.

I will do some more tests to see if this is a fluke case, but if I think proj4 is promising, I will see how to invent a scheme for handling the mapproj arguments called parameters and orientation with proj4. THis seems to be a bit tricky, at first glance, but let’s keep the cart behind the horse for now.

Resources

To leave a comment for the author, please follow the link and comment on their blog: Dan Kelley Blog/R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)