Skip to content

Instantly share code, notes, and snippets.

@nl-hugo
Last active September 5, 2015 11:28
Show Gist options
  • Save nl-hugo/ed577f1ea090b0a794b6 to your computer and use it in GitHub Desktop.
Save nl-hugo/ed577f1ea090b0a794b6 to your computer and use it in GitHub Desktop.
Dutch naval history II
CLIWOC15.csv
*.shp
ne*
.RData*
.Rhistory

In 1815, the Dutch naval ship Amsterdam (in dutch) left for the Dutch East Indies to retake control over the Dutch colonial possessions from the British. On it's way home, in 1817, it sunk in the Algoabaai, near South Africa.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.land {
fill: #ddd;
}
.position {
fill: #fe9929;
opacity: 0.8;
}
</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script>
<script>
var margin = {top: 100, right: 50, bottom: 50, left: 50},
width = 900 - margin.left - margin.right,
height = 600 - margin.bottom - margin.top;
var dateFormat = d3.time.format("%m/%d/%Y");
var projection = d3.geo.mercator()
.translate([width / 2, height / 2])
.scale((width - 1) / 2 / Math.PI);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
queue()
.defer(d3.json, "/nl-hugo/raw/bf8c60c081effd56f31b/world-110m.json")
.defer(d3.csv, "route.csv")
.await(ready);
function ready (error, world, data) {
if (error) return console.error(error);
data.forEach(function (d){
d.dd = new Date(+d.year, (+d.month)-1, +d.day);
});
console.log(data);
data.sort(function(a,b) { return a.dd - b.dd; });
svg.append("path")
.datum(topojson.feature(world, world.objects.ne_110m_land))
.attr("class", "land")
.attr("d", path);
var n = data.length,
i = 0,
interval = setInterval(function() {
if(i < n) {
// append message with route description
var message = svg.selectAll("text")
.data(data.filter(function(d,j) { return j === i; }), function(d) { return d.dd; });
message.enter().append("text")
.attr("class", "message")
.attr("transform", function(d) { return "translate(" + (width / 2 - margin.left) + "," + 0 + ")"; })
.text(function(d) {
return dateFormat(d.dd) + ": en route to " + d.voyageto;
});
message.exit().remove();
// append circles to indicate the route
var circle = svg.selectAll("circle")
.data(data.filter(function(d,j) { return j <= i; }));
circle.enter().append("circle")
.attr("class", "position")
.attr("r", 2.0)
.attr("transform", function(d) { return "translate(" + projection([+d.lon, +d.lat]) + ")"; });
// mark anchor places
circle.filter(function(d) { return d.anchored === "1"; })
.attr("r", 5.0)
.style("fill", "#2c7bb6")
.append("svg:title")
.text(function(d) { return dateFormat(d.dd) + ": " + d.anchorplace; });
// mark the last position in red
circle.filter(function(d,j) { return j === n - 1; })
.attr("r", 5.0)
.style("fill", "#d7191c");
} else {
clearInterval(interval);
}
// update counter
i++;
}, 100);
}
</script>
# data obtained from kaggle project website https://www.kaggle.com/c/climate-data-from-ocean-ships/download/CLIWOC.7z
# Dataset cannot be download automatically, Kaggle requires a user confirmation
# 7z cannot be unzipped automatically
# Read the data
cliwoc <- read.csv("CLIWOC15.csv")
# select ship named Amsterdam
# also include Year, because ship names were often reused!
# https://nl.wikipedia.org/wiki/Amsterdam_(1814)
ship <- subset(cliwoc, ShipName == "Amsterdam" & Year <= 1817)
# columns to export
cols <- c("Year","Month","Day","Lat3","Lon3","VoyageTo","Anchored","AnchorPlace")
route <- ship[cols]
# drop na's
route <- route[complete.cases(route), ]
# round lat/lon and remove duplicates to compress data (implies loss of
# precision)
route$Lat3 <- round(route$Lat3, 1)
route$Lon3 <- round(route$Lon3, 1)
route <- unique(route)
# rename columns
names(route)[names(route)=="Lat3"] <- "lat"
names(route)[names(route)=="Lon3"] <- "lon"
names(route) <- tolower(names(route))
# write to csv file
write.csv(route, "route.csv", quote=TRUE, row.names=FALSE)
year month day lat lon voyageto anchored anchorplace
1815 10 31 50 -3.9 Porto Praijo 0
1815 11 1 48.2 -7.1 Porto Praijo 0
1815 11 2 46.3 -9.3 Porto Praijo 0
1815 11 3 43.6 -10.8 Porto Praijo 0
1815 11 4 40.8 -11.7 Porto Praijo 0
1815 11 5 38.6 -12 Porto Praijo 0
1815 11 6 36.9 -11.9 Porto Praijo 0
1815 11 7 34.8 -12.1 Porto Praijo 0
1815 11 8 33 -12.9 Porto Praijo 0
1815 11 9 30.2 -16.1 Porto Praijo 0
1815 11 10 29.4 -16.3 Porto Praijo 0
1815 11 11 28.3 -16.2 Porto Praijo 0
1815 11 12 27.2 -16.1 Porto Praijo 0
1815 11 13 26.1 -16.3 Porto Praijo 0
1815 11 14 23.9 -18.1 Porto Praijo 0
1815 11 15 21.1 -19.6 Porto Praijo 0
1815 11 16 18.1 -20.6 Porto Praijo 0
1815 11 17 15.7 -21.2 Porto Praijo 0
1815 11 27 13.3 -22.8 Allerheiligen Baaij 0
1815 11 28 11.5 -21.8 Allerheiligen Baaij 0
1815 11 29 9.6 -21.2 Allerheiligen Baaij 0
1815 11 30 7.7 -20.4 Allerheiligen Baaij 0
1815 12 1 6.7 -20.4 Allerheiligen Baaij 0
1815 12 2 6.3 -20.6 Allerheiligen Baaij 0
1815 12 3 5.5 -21.4 Allerheiligen Baaij 0
1815 12 4 4.5 -23.1 Allerheiligen Baaij 0
1815 12 5 2.9 -24.2 Allerheiligen Baaij 0
1815 12 6 1.3 -25.1 Allerheiligen Baaij 0
1815 12 7 0.2 -26.2 Allerheiligen Baaij 0
1815 12 8 -1.4 -27.6 Allerheiligen Baaij 0
1815 12 9 -3.4 -28.3 Allerheiligen Baaij 0
1815 12 10 -5.8 -28.9 Allerheiligen Baaij 0
1815 12 11 -7.4 -29.8 Allerheiligen Baaij 0
1815 12 12 -8.4 -31.9 Allerheiligen Baaij 0
1815 12 13 -10.1 -35.5 Allerheiligen Baaij 0
1815 12 14 -10.6 -34.9 Allerheiligen Baaij 0
1815 12 15 -12.9 -35.6 Allerheiligen Baaij 1 Allerheiligen Baaij
1817 12 10 -34.7 23.8 Algoa Baai 0
1817 12 11 -34.8 23.2 Algoa Baai 0
1817 12 12 -35.3 23.7 Algoa Baai 0
1817 12 13 -35 24.1 Algoa Baai 0
1817 12 14 -34.6 25.1 Algoa Baai 0
1817 12 15 -34.2 25.4 Algoa Baai 1 Algoa Baai
1816 1 11 -14.7 -37.6 Tafelbaai 0
1816 1 12 -16.4 -36.6 Tafelbaai 0
1816 1 13 -18.5 -36.5 Tafelbaai 0
1816 1 14 -20.4 -36.1 Tafelbaai 0
1816 1 15 -22.5 -35.6 Tafelbaai 0
1816 1 16 -24.8 -35.1 Tafelbaai 0
1816 1 17 -25.9 -34.8 Tafelbaai 0
1816 1 20 -27 -31.8 Tafelbaai 0
1816 1 21 -27.9 -29 Tafelbaai 0
1816 1 22 -29.1 -25.7 Tafelbaai 0
1816 1 23 -30.2 -22.5 Tafelbaai 0
1816 1 24 -30.6 -21.2 Tafelbaai 0
1816 1 25 -29.9 -19.7 Tafelbaai 0
1816 1 26 -28.9 -17 Tafelbaai 0
1816 1 27 -30 -18.2 Tafelbaai 0
1816 1 28 -31 -19.2 Tafelbaai 0
1816 1 29 -31.5 -18.7 Tafelbaai 0
1816 1 30 -32.9 -18.6 Tafelbaai 0
1816 1 31 -34.5 -17.1 Tafelbaai 0
1816 2 1 -34.9 -16.1 Tafelbaai 0
1816 2 2 -35.6 -13.3 Tafelbaai 0
1816 2 3 -35.7 -9.2 Tafelbaai 0
1816 2 4 -35.7 -6.4 Tafelbaai 0
1816 2 5 -35.5 -4.7 Tafelbaai 0
1816 2 6 -35.9 -3.2 Tafelbaai 0
1816 2 7 -36.4 -0.8 Tafelbaai 0
1816 2 8 -36.3 1.3 Tafelbaai 0
1816 2 9 -36.2 2.8 Tafelbaai 0
1816 2 10 -36.6 4.2 Tafelbaai 0
1816 2 11 -35.9 6 Tafelbaai 0
1816 2 12 -34.8 8.6 Tafelbaai 0
1816 2 13 -35.8 9.2 Tafelbaai 0
1816 2 14 -35.7 13 Tafelbaai 0
1816 2 15 -35.2 15.4 Tafelbaai 0
1816 2 16 -34.1 17.6 Tafelbaai 0
1816 2 17 -33.8 18.4 Tafelbaai 1 Tafelbaai
1816 3 6 -34.5 17.1 Batavia 0
1816 3 7 -35.4 16.8 Batavia 0
1816 3 8 -37.7 18.6 Batavia 0
1816 3 9 -37.9 20.4 Batavia 0
1816 3 10 -39.2 22.5 Batavia 0
1816 3 11 -40.5 24.5 Batavia 0
1816 3 12 -39.8 27.2 Batavia 0
1816 3 13 -39 28.7 Batavia 0
1816 3 14 -38.2 33 Batavia 0
1816 3 15 -36.9 35.9 Batavia 0
1816 3 16 -37 36 Batavia 0
1816 3 17 -37.4 35 Batavia 0
1816 3 18 -37.2 34.1 Batavia 0
1816 3 19 -37.1 34.5 Batavia 0
1816 3 20 -37.6 36.1 Batavia 0
1816 3 21 -38.1 37.7 Batavia 0
1816 3 22 -36.9 40 Batavia 0
1816 3 23 -38.9 42.4 Batavia 0
1816 3 24 -39 46.3 Batavia 0
1816 3 25 -38.7 49.8 Batavia 0
1816 3 26 -38.4 52.1 Batavia 0
1816 3 27 -39.2 54.9 Batavia 0
1816 3 28 -38 57.8 Batavia 0
1816 3 29 -38.8 61.5 Batavia 0
1816 3 30 -38.6 65.5 Batavia 0
1816 3 31 -36 68.2 Batavia 0
1816 4 1 -35.5 69.5 Batavia 0
1816 4 2 -35.2 70.9 Batavia 0
1816 4 3 -34.7 72 Batavia 0
1816 4 4 -34.9 72.5 Batavia 0
1816 4 5 -35.9 75.7 Batavia 0
1816 4 6 -35.9 79.5 Batavia 0
1816 4 7 -36.2 82.1 Batavia 0
1816 4 8 -35.7 84.7 Batavia 0
1816 4 9 -35.1 87.4 Batavia 0
1816 4 10 -34.2 89.3 Batavia 0
1816 4 11 -33.4 91.7 Batavia 0
1816 4 12 -31.6 94.1 Batavia 0
1816 4 13 -29.4 94.7 Batavia 0
1816 4 14 -29.1 94.9 Batavia 0
1816 4 15 -27.7 96.6 Batavia 0
1816 4 16 -26.6 98.1 Batavia 0
1816 4 17 -25.3 98.8 Batavia 0
1816 4 18 -24.2 99.4 Batavia 0
1816 4 19 -22 99.9 Batavia 0
1816 4 20 -20 99.8 Batavia 0
1816 4 21 -20 99.9 Batavia 0
1816 4 22 -20 99.7 Batavia 0
1816 4 23 -18.9 100.3 Batavia 0
1816 4 24 -17.5 99.9 Batavia 0
1816 4 25 -15.8 100.3 Batavia 0
1816 4 26 -14.2 101.1 Batavia 0
1816 4 27 -12.3 101.8 Batavia 0
1816 4 28 -10.3 102.5 Batavia 0
1816 4 29 -8.4 103 Batavia 0
1816 4 30 -7 104.1 Batavia 0
1816 5 1 -6.8 105.2 Batavia 1 zw hoek van Java
1817 11 6 -6.9 103.1 Algoa Baai 0
1817 11 7 -7.8 100.6 Algoa Baai 0
1817 11 8 -8.2 98.8 Algoa Baai 0
1817 11 9 -9.2 96.9 Algoa Baai 0
1817 11 10 -10.7 94.5 Algoa Baai 0
1817 11 11 -12.6 90.8 Algoa Baai 0
1817 11 12 -14.5 87.8 Algoa Baai 0
1817 11 13 -15.8 85.2 Algoa Baai 0
1817 11 14 -17.1 82.8 Algoa Baai 0
1817 11 15 -17.9 80.2 Algoa Baai 0
1817 11 16 -18.4 78.6 Algoa Baai 0
1817 11 17 -19.1 77.2 Algoa Baai 0
1817 11 18 -19.4 77 Algoa Baai 0
1817 11 19 -19.9 74.6 Algoa Baai 0
1817 11 20 -20.3 74.3 Algoa Baai 0
1817 11 21 -20.5 73.2 Algoa Baai 0
1817 11 22 -21.7 70.2 Algoa Baai 0
1817 11 23 -22.4 67.5 Algoa Baai 0
1817 11 24 -23 64 Algoa Baai 0
1817 11 25 -23.5 60.4 Algoa Baai 0
1817 11 26 -24.1 57.2 Algoa Baai 0
1817 11 27 -24.6 54.7 Algoa Baai 0
1817 11 28 -26 52.2 Algoa Baai 0
1817 11 29 -26.1 49.4 Algoa Baai 0
1817 11 30 -27.6 47.3 Algoa Baai 0
1817 12 1 -28.9 44.4 Algoa Baai 0
1817 12 2 -29.6 41.6 Algoa Baai 0
1817 12 3 -29.9 40.3 Algoa Baai 0
1817 12 4 -29.8 39.3 Algoa Baai 0
1817 12 5 -30.8 36.1 Algoa Baai 0
1817 12 6 -31.6 33.6 Algoa Baai 0
1817 12 7 -31.5 31.2 Algoa Baai 0
1817 12 8 -32.5 29.2 Algoa Baai 0
1817 12 9 -35 25.5 Algoa Baai 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment