CS-GY 6313 - Information Visualization
New York University
2026-10-29
| User Interface | Graphics Library | Notebook(s) |
|---|---|---|
| observablehq.com | D3 | Week 8 Lab Notebook |
Today we will be a exploring the following topics:
GeoJSON is an open standard format designed for representing simple geographical features, along with their non-spatial attributes. It is based on the JSON format. - Wikipedia
geometry determines where the region is and what its shape is.properties provides information about that region.GeoJSON follows a geographic coordinate system where the positions are usually stored as:
| Coordinate | Valid range | Meaning |
|---|---|---|
| Longitude | −180° to +180° | West to East |
| Latitude | −90° to +90° | South to North |
GeoJSON follows a specific standard of long/lat coordinates called the World Geodetic System (WGS) - specifically, WGS 84 (or otherwise called EPSG:4326). You should remember that long/lat coordinates are not pixel positions; they are degrees relative to the Prime Meridian and Equator, respectively.
There are six (6) fundamental geometry types, plus GeometryCollection:
| Geometry Type | Description | Format |
|---|---|---|
Point |
A single coordinate point, such as a building or pin on a map | [lon, lat] |
MultiPoint |
Multiple independent points | [[lon, lat], ...] |
LineString |
A connected path, like a river or road | [[lon, lat], ...] |
MultiLineString |
Several independent lines | [[[lon, lat], ...], ...] |
Polygon |
One polygonal region, potentially with holes | [[[lon, lat], ...], ...] |
MultiPolygon |
Multiple polygonal groups, combined into a single entity | [[[[lon, lat], ...], ...], ...] |
All polygons are constructed from one or more rings. Each ring must begin and end at the same coordinate. Consider this example, which actually has two (2) rings: an exterior ring, and an interior hole.
GeoJSON requires that Exterior rings should be counterclockwise and that Interior holes should be clockwise, using the Right-Hand Rule (RHR).
Unlike geometry, properties usually contain metadata about the geometry. For example:
These are properties of the state of Alabama. This particular instance gives us a lot of info, such as which country the region is a part of, what kind of region it is to begin with, and other identifiers.
Geodata is usually a combination of different data sources:
.shp)..csv, Excel) and need to be mapped to GeoJSON features.You can find existing GeoJSON files in the wild, such as in Vega-Lite’s pre-existing US-Atlas GeoJSON or . However, you don’t really have much control over the fidelity and properties of the GeoJSON itself.
Let’s download the .shp data from the US Census Cartographic Boundary Files Datasets, then use MapShaper to convert it into GeoJSON
Rendering geoplots in D3.js is conceptually very similar to what we did with other non-scatter plot types such as Pie Charts and Histograms. Fundamentally, we need to:
// Determine our plot's dimensions
const usa_width = 800;
const usa_height = 550;
// Define projection using Albers USA, our plot's dimensions, and `us_state_5m` we imported
const usa_projection = d3.geoAlbersUsa()
.fitSize([usa_width, usa_height], us_state_5m);
// Create geographic path generator
const usa_path = d3.geoPath(usa_projection);d3.geoAzimuthalEqualArea()d3.geoAzimuthalEquidistant()d3.geoOrthographic()d3.geoConicConformal()d3.geoConicEqualArea()d3.geoAlbers()
d3.geoMercator()d3.geoEquirectangular()d3.geoEqualEarth()If we render our SVG as a series of paths:
// Create SVG
const usa_svg = d3.create("svg")
.attr("width", usa_width)
.attr("height", usa_height);
// Render each state as a path, with a fill, stroke, and stroke-width
usa_svg.selectAll("path")
.data(us_state_5m.features)
.enter()
.append("path")
.attr("d", usa_path)
.attr("fill", "#D9E5EA")
.attr("stroke", "#333")
.attr("stroke-width", 0.5);
… Uh oh.
This is a common problem with D3.js and GeoJSON. Namely, there is a discrepancy between GeoJSON’s Right-Hand-Rule (RHR) convention and D3.js’s spherical geometry implementation. To prevent issues like these, we need to consider:
null geometries in our data?Polygon and MultiPolygon geometries in our dataset the correct winding order?The winding direction issue is not always a mandatory fix - it really depends on where you are getting the data from. It is your responsibility to check if the GeoJSON data renders properly, and if not then fix the two likely problems above.
Attempt to generate the geodata of one other country other than the USA. You can use any of the references mentioned above for getting your ShapeFiles, converting them into GeoJSON, and troubleshooting their issues upon importing them.
When you are done, upload a screenshot of your plot to this Google Drive folder with your name, NetID, and country in the filename.
| Milestone | Due Date | Details |
|---|---|---|
| Data Analysis & Sketches | Nov 3 | Data tables and visualization sketches |
| First Draft | Nov 17 | Initial D3 implementations |
| Second Draft | Dec 1 | Refined narrative and polished visualizations |
| Final Submission | Dec 8 | Complete project with presentation |
