Hello Community,
I would like your help to combine nation, state, county data into one Topology type Json file.
I already managed to fetch and read the shape boundary files, please see this Notebook.Link
Code:
us_nation:
us_nation = fetch_read_zipped_shapefile(
"https://www2.census.gov/geo/tiger/GENZ2023/shp/cb_2023_us_nation_5m.zip"
)
us_state:
us_state = fetch_read_zipped_shapefile(
"https://www2.census.gov/geo/tiger/GENZ2023/shp/cb_2023_us_state_5m.zip"
)
function:
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;
}
For reference, Please check this Json
us = d3.json("https://unpkg.com/us-atlas@3/counties-10m.json")
The output will be:
us = Object {
type: "Topology",
bbox: Array(4) [-179.14733999999999, -14.552548999999999, 179.77847, 71.352561],
transform: Object {scale: Array(2), translate: Array(2)},
objects: Object {counties: Object, states: Object, nation: Object}
arcs: Array(9869)[],
So, I want to combine us_nation & us_state into one. Please help.
Thank you.
