Public
Edited
Jan 8, 2023
2 forks
Importers
2 stars
Insert cell
Insert cell
function normalizeWinding(features) {
return rewind({ ...features }, true);
}
Insert cell
function featureFilterFeatures(
geo,
allowedFeatures = [
"Point",
"LineString",
"Polygon",
"MultiPoint",
"MultiLineString",
"MultiPolygon"
]
) {
const polys = featureFilter(geo, (f) =>
allowedFeatures.includes(turf.getType(f))
);

return { ...geo, features: polys };
}
Insert cell
function featureRemoveNonPolygonFeatures(geo) {
const polys = featureFilter(geo, (f) =>
["Polygon", "MultiPolygon"].includes(turf.getType(f))
);

return { ...geo, features: polys };
}
Insert cell
function featureMap(geo, fn = (d) => d) {
return turf.featureReduce(geo, (acc, curr, index) => [...acc, fn(curr, index, geo)], []);
}
Insert cell
function featureFilter(geo, fn = (d) => d) {
return turf.featureReduce(
geo,
(acc, curr, index) => {
if (Boolean(fn(curr, index, geo))) {
return [...acc, curr];
}
return acc;
},
[]
);
}
Insert cell
function featureGroupBy(geo, fn = (k) => k) {
const obj = turf.featureReduce(
geo,
(acc, curr, index) => {
const key = fn(curr) || null;

return { ...acc, [key]: [...(acc[key] || []), curr] };
},
{}
);

return new Map(Object.entries(obj));
}
Insert cell
function createFeatureCollection(geos) {
const features = geos.flatMap(
(f) => (Array.isArray(f.features) ? f.features : [f]) // Assume it is a single feature
);
return geotoolbox.featurecollection(features)
}
Insert cell
function previewGeojson(arr) {
if (Array.isArray(arr)) {
return bertin.quickdraw(arr.map(normalizeWinding))
}

return bertin.quickdraw(normalizeWinding(arr))
}
Insert cell
point = turf.point
Insert cell
Insert cell
Insert cell
geotoolbox = require("geotoolbox@1.9.2/dist/index.min.js")
Insert cell
bertin = import('https://cdn.skypack.dev/bertin@1.5.9?min')
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more