Public
Edited
Jul 11, 2023
2 forks
19 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gdal = {
const initGdalJS =
await require("gdal3.js@2.4.0/dist/package/gdal3.js").catch(
() => window["initGdalJs"]
);
return await initGdalJS({
path: "https://cdn.jsdelivr.net/npm/gdal3.js@2.4.0/dist/package",
useWorker: false
}).then((Gdal) => Gdal);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
input = gdal.open(await FileAttachment("afghanistan.gpkg")) // See https://gdal3.js.org/docs/module-f_open.html
Insert cell
Insert cell
gdal.getInfo(input.datasets[0]) // See https://gdal.org/programs/gdalinfo.html
Insert cell
Insert cell
shp = FileAttachment("cuba.zip").zip()
Insert cell
input2 = gdal.open(shp.filenames.map((d) => shp.file(d)))
Insert cell
gdal.getInfo(input.datasets[0])
Insert cell
Insert cell
Insert cell
mygeojson = JSON.parse(
new TextDecoder().decode(
await gdal.getFileBytes(
await gdal.ogr2ogr(input.datasets[0], [
"-f",
"GeoJSON",
"-t_srs",
"EPSG:4326"
])
)
)
)
Insert cell
Plot.plot({
marks: [Plot.geo(mygeojson)]
})
Insert cell
mygeojson2 = JSON.parse(
new TextDecoder().decode(
await gdal.getFileBytes(
await gdal.ogr2ogr(input2.datasets[0], [
"-f",
"GeoJSON",
"-t_srs",
"EPSG:4326"
])
)
)
)
Insert cell
Plot.plot({
marks: [Plot.geo(mygeojson2)]
})
Insert cell
Insert cell
Insert cell
toGeoJSON = async (fileOrFiles, params = { opts: [], openOpts: [] }) => {
const openOptions = params.openOpts || [];
const input = await gdal.open(fileOrFiles, openOptions);
const options = [
"-f",
"GeoJSON",
"-t_srs",
"EPSG:4326",
"-lco",
"RFC7946=YES"
].concat(params.opts || []);
const output = await gdal.ogr2ogr(input.datasets[0], options);
const bytes = await gdal.getFileBytes(output);
await gdal.close(input);
return JSON.parse(new TextDecoder().decode(bytes));
}
Insert cell
Insert cell
Insert cell
toGeoJSON(await FileAttachment("afghanistan.gpkg"))
Insert cell
Insert cell
Insert cell
Insert cell
input3 = await gdal.open(await FileAttachment("world.json"))
Insert cell
mygeojson3 = JSON.parse(
new TextDecoder().decode(
await gdal.getFileBytes(
await gdal.ogr2ogr(input3.datasets[0], [
"-f",
"GeoJSON",
"-t_srs",
"EPSG:3035"
])
)
)
)
Insert cell
Plot.plot({
projection: { type: "reflect-y", domain: mygeojson3 },
marks: [Plot.geo(mygeojson3)]
})
Insert cell
Insert cell
Insert cell
Insert cell
input5 = FileAttachment("bolivia.kmz")
.zip()
.then((d) => gdal.open(d.file("gadm41_BOL_2.kml")))
Insert cell
Insert cell
blob = new Blob([
await gdal.getFileBytes(
await gdal.ogr2ogr(input5.datasets[0], [
"-f",
"GPKG",
"-t_srs",
"EPSG:4326"
])
)
])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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