Assessing mapdata world coastline

January 27, 2015
By

(This article was first published on Dan Kelley Blog/R, and kindly contributed to R-bloggers)

Introduction

The mapdata R package contains a coastline called worldHires which is contained within a text file with a bit over 2 million lines. Since the coastlineWorldFine dataset in the ocedata package contains about 0.5 million points, I thought I would explore how much better the mapdata coastline might be.

Methods

First, I wrote the following C file to translate the data to something that R can read.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include 
char *file = "/Users/kelley/mapdata/src/worldHires.line";
int main()
{
    char tok1[100], tok2[100]; // needn't be anywhere near that long
    FILE *in = fopen(file, "r");
    int ok;
    int count = 0;
    int skip = 1;
    while (1) { //count++ < n) {
        if (skip) {
            fscanf(in, "%s", tok1);
            if (feof(in))
                return(0);
            fscanf(in, "%s", tok2);
            printf("NA NAn");
            skip = 0;
        } else {
            fscanf(in, "%s", tok1);
            if (tok1[0] == 'E') {
                skip = 1;
            } else {
                fscanf(in, "%s", tok2);
                printf("  %s %sn", tok1, tok2);
            }
        }
    }
}

Then, I created a datafile for plotting. It turns out that mapdata numbers are in radians, so a conversion was required.

I plotted this “new” dataset and the “old” one (containined in ocedata) and the results are shown below.

Results

center

Conclusions

There are some differences between the two, but nothing dramatic (e.g. no Northwest Arm of Halifax Harbour). Certainly it would be difficult to argue for exapanding the memory footprint of ocedata by a factor of 4.

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

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)