Public
Edited
Jul 20, 2024
Importers
Insert cell
Insert cell
Insert cell
Insert cell
usshapezip = FileAttachment("cb_2023_us_state_5m.zip") //.zip()
Insert cell
us_county_shp = read_zipped_shapefile(usshapezip)
Insert cell
Insert cell
// nation = fetch_read_zipped_shapefile("https://www2.census.gov/geo/tiger/GENZ2023/shp/cb_2023_us_nation_5m.zip")
Insert cell
//states = fetch_read_zipped_shapefile("https://www2.census.gov/geo/tiger/GENZ2023/shp/cb_2023_us_state_5m.zip")
Insert cell
//counties = fetch_read_zipped_shapefile("https://www2.census.gov/geo/tiger/GENZ2023/shp/cb_2023_us_county_5m.zip")
Insert cell
Insert cell
//us_cartographic = topojson.topology({ nation, states, counties })
Insert cell
Insert cell
Insert cell
nation = FileAttachment("nation.json").json()
Insert cell
states = FileAttachment("states.json").json()
Insert cell
counties = FileAttachment("counties.json").json()
Insert cell
us_cartographic_5m = FileAttachment("us_cartographic@1.json").json()
Insert cell
Insert cell
// us = d3.json("https://unpkg.com/us-atlas@3/counties-10m.json")
Insert cell
//nation = topojson.feature(us, us.objects.nation)
Insert cell
//states = topojson.feature(us, us.objects.states)
Insert cell
//counties = topojson.feature(us, us.objects.counties)
Insert cell
Insert cell
Insert cell
topojson = require("topojson-client", "topojson-server")
Insert cell
shp = require("https://unpkg.com/shpjs@latest/dist/shp.js")
Insert cell
read_zipped_shapefile = async (ZipFile) => {
return await shp(await ZipFile.arrayBuffer());
}
Insert cell
fetch_read_zipped_shapefile = async (targetUrl) => {
const proxyUrl = "https://api.allorigins.win/get?url=";
const response = await fetch(proxyUrl + encodeURIComponent(targetUrl));
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
// Extracting the zip file content from base64 data
const base64Data = data.contents.split(",")[1]; // Extract base64 content
const arrayBuffer = await Uint8Array.from(atob(base64Data), (c) =>
c.charCodeAt(0)
).buffer;
const shapeFileData = await shp(arrayBuffer);
return shapeFileData;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more