worldCharts = {
const size = 250;
const padding = 10;
const container = html`<div style="display: flex; gap: 20px; justify-content: center; flex-wrap: wrap;"></div>`;
const variations = [
{ name: "Longitudes", step: [15, 90] },
{ name: "Latitudes", step: [180, 10] }
];
variations.forEach(v => {
const svg = d3.select(container).append("svg")
.attr("width", size)
.attr("height", size);
const topMargin = 50;
const projection = d3.geoOrthographic()
.scale((size - padding * 2) / 2)
.translate([size / 2, size / 2])
.rotate([0, -30])
.clipAngle(90)
.fitExtent([[padding, topMargin], [size - padding, size - padding]], {type: "Sphere"});
const path = d3.geoPath().projection(projection);
svg.append("path")
.datum({type: "Sphere"})
.attr("d", path)
.attr("fill", "#f8f9fa")
.attr("stroke", themeColor);
svg.append("path")
.datum(d3.geoGraticule().step(v.step))
.attr("d", path)
.attr("fill", "none")
.attr("stroke", themeColor);
svg.append("text")
.attr("x", size / 2)
.attr("y", 25)
.attr("text-anchor", "middle")
.attr("fill", themeColor)
.style("font-family", "sans-serif")
.style("font-weight", "bold")
.text(v.name);
});
return container;
}Coordinate Systems
Displaying a 3D world in 2D
You’re probably familiar with longitude and latitude coordinates. You probably think of them as two numbers that can identify any point on Earth, but did you know there’s a third component that is necessary to determine exactly where a point really is? This third component is called a geographic coordinate system.
A geographic coordinate system is a model of the earth that specifies where on Earth we draw longitude and latitude lines. And thus, they determine where a given longitude and latitude is in the world!
This begs the question: why even are there multiple geographic coordinate systems? Shouldn’t we just choose one and all use that one? Well, we have multiple geographic coordinate systems because simply the Earth isn’t a perfect sphere. Different coordinate systems exist primarily for specific areas to accommodate local deviations from the sphere better. One such example of this is the North American Datum of 1983 (NAD 83), which is the geographic coordinate system US Census boundary files are in. Most often, longitude and latitude coordinates are represented in the World Geodetic System 1984 (WGS 1984), which is designed to work well for the entire world.
Just knowing where things are isn’t the whole picture though. We often want to represent the Earth on a 2-dimensional surface like a piece of paper or a screen. This introduces a whole new set of problems.
Take a look at this below example. These are three different ways of representing Earth. Focus on one specific area in the world and watch it change as we change how we represent Earth. Notice how the shape and area of that place change. As do the distances and angles between places.
Unfortunately, no matter how we try to unfurl the Earth’s surface on to a 2-dimensional plane, there is no way to flatten the Earth’s surface without tearing and stretching it. The process of tearing and stretching the surface introduces distortions, which can be consequential in many applications.
Thus, choosing the right 2D representation of the Earth for your area of interest and/or application of interest is essential. We call these 2D representations projected coordinate systems for how they project geographic coordinate systems into 2D space.
Projected coordinate systems can optimize for all kinds of properties like area, shape, distance, or direction. They also often only do so for specific areas. In the US, you will find that most states have several different projected coordinate systems, but typically there exists some one-size-fits-all coordinate system for which most operations can be done with moderate precision.
Most spatial data formats will store information about the coordinate system your data is in. Additionally, coordinate systems are assigned a Well-Known ID (WKID) which uniquely identifies them and can serve as an easy way to search for them. For example, WGS 1984’s WKID is 4326.
Once data is in one coordinate system, it does not necessarily need to stay that way. Most GIS software will have built in features to transform data between projections and it is a best practice to always be conscious of the projection you are working within.
For more information, check out these resources: