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

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