Public
Edited
Jun 27, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
settlements_with_morphemes
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
d3.select(map).style("background", "hsl(205, 13%, 81%)")
Insert cell
// From https://colorbrewer2.org
colorScale = ["#edf8fb", "#b3cde3", "#8c96c6", "#8856a7", "#810f7c"] // ['#f6eff7','#bdc9e1','#67a9cf','#1c9099','#016c59']
Insert cell
aspectRatio = 5 / 4.5
Insert cell
graphicWidth = Math.max(640, width)
Insert cell
graphicHeight = Math.floor(graphicWidth * aspectRatio)
Insert cell
data = db.query(query)
Insert cell
db = DuckDBClient.of({
settlements: FileAttachment("india_settlements_name.csv")
})
Insert cell
Insert cell
query = `SELECT
*
FROM
'settlements'
WHERE ${whereClause}`
Insert cell
whereClause = {
let regexes = morphemes?.regexes?.slice() || [];
if (morphemes === undefined) {
regexes = customMorphes.trim().split("\n");
}

return regexes
.map(
(d) =>
`LOWER(name) LIKE '${d}' OR LOWER(alt_name) LIKE '${d}' OR LOWER(alt_name_2) LIKE '${d}'`
)
.join(" OR ");
}
Insert cell
tokenRegexMap = {
const presets = [
["-abad", ["%abad"]],
["-garh", ["%garh"]],
["-halli", ["%halli"]],
["-pete/pettai/pet", ["%pettai", "%pete", "%pet"]],
["-gram/gaon/gav", ["%gram", "%gaon", "%gav"]],
["-nagar/nagara/nagaram", ["%nagaram", "%nagara", "%nagar"]],
["-pore/pur/pura/puram", ["%puram", "%pore", "%pura", "%pur"]],
["-ooru/oor/ore/ur/uru", ["%ooru", "%oor", "%ore", "%uru", "%ur"]],
[
"-kote/kot/kottai/kota",
["%kottai", "%kote", "%kotai", "%kotta", "%kota", "%kot"]
]
]
.sort(sortBy(0))
.map(([k, v]) => [k, { regexes: v, key: k }]);
return new Map([...presets, [`✏️ Custom patterns`, undefined]]);
}
Insert cell
projection = proj4d3(indiaProj4)
Insert cell
sortBy = (key) => {
return (a, b) => (a[key] > b[key] ? 1 : b[key] > a[key] ? -1 : 0);
}
Insert cell
indiaProj4 = `+proj=aea +lat_2=12 +lat_1=28 +lat_0=20 +lon_0=78 +x_0=2000000 +y_0=2000000`
//`+proj=longlat +a=6377301.243 +rf=300.8017255 +no_defs +type=crs`
Insert cell
indiaStatesGeo = FileAttachment("india-states-simplified.geo.json").json()
Insert cell
eastIndianStatesGeo = {
const states = ["Bihar", "Jharkhand", "Odisha", "West Bengal"];
return filterFeatureByNames(indiaStatesGeo, states);
}
Insert cell
northEastIndianStatesGeo = {
const states = [
"Assam",
"Arunachal Pradesh",
"Manipur",
"Meghalaya",
"Mizoram",
"Nagaland",
"Tripura",
"Sikkim"
];
return filterFeatureByNames(indiaStatesGeo, states);
}
Insert cell
centreIndianStatesGeo = {
const states = [
"Chhattisgarh",
"Madhya Pradesh",
"Uttar Pradesh",
"Uttarakhand"
];
return filterFeatureByNames(indiaStatesGeo, states);
}
Insert cell
southIndianStatesGeo = {
const states = [
"Kerala",
"Tamil Nadu",
"Puducherry",
"Andaman and Nicobar Islands",
"Lakshadweep",
"Karnataka",
"Andhra Pradesh",
"Telangana"
];
return filterFeatureByNames(indiaStatesGeo, states);
}
Insert cell
westIndianStatesGeo = {
const states = [
"Maharashtra",
"Gujarat",
"Goa",
"The Dadra and Nagar Haveli and Daman and Diu"
];
return filterFeatureByNames(indiaStatesGeo, states);
}
Insert cell
northIndianStatesGeo = {
const states = [
"Chandigarh",
"Delhi",
"Haryana",
"Himachal Pradesh",
"Jammu and Kashmir",
"Ladakh",
"Punjab",
"Rajasthan"
];
return filterFeatureByNames(indiaStatesGeo, states);
}
Insert cell
function filterFeatureByNames(geo, states = []) {
return geotoolbox.filter(geo, (p) => states.includes(p.name));
}
Insert cell
zonesGeo = new Map([
["All India", indiaStatesGeo],
["Northern", northIndianStatesGeo],
["North Eastern", northEastIndianStatesGeo],
["Central", centreIndianStatesGeo],
["Eastern", eastIndianStatesGeo],
["Western", westIndianStatesGeo],
["Southern", southIndianStatesGeo]
])
Insert cell
Insert cell
Insert cell
Insert cell
import { hexgridGeoPlot } from "@saneef/hexgrid-geo-plot"
Insert cell
import { proj4d3 } from "@fil/proj4js-d3"
Insert cell
geotoolbox = require("geotoolbox@latest")
Insert cell
import { footer } from "@saneef/notebooks-footer"
Insert cell
Insert cell
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