Public
Edited
Nov 18, 2024
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
stmt = await conn.prepare(query);
Insert cell
arrowTable = await stmt.query();
Insert cell
geometryColumn = arrowTable.getChild("geo2")
Insert cell
/*
result = {
const stmt = await conn.prepare(query);
const arrowTable = await stmt.query();

const geometryColumn = arrowTable.getChild("geometry");
const polygonIndices = geometryColumn.data[0].valueOffsets;

return geometryColumn

/*
const ringIndices = geometryColumn.getChildAt(0).data[0].valueOffsets;
const resolvedIndices = new Int32Array(polygonIndices.length);
for (let i = 0; i < resolvedIndices.length; ++i) {
resolvedIndices[i] = ringIndices[polygonIndices[i]]
}
const resolvedPolygonIndices = resolvedIndices;


const coordinateVector = geometryColumn.getChildAt(0).getChildAt(0);
const flatCoordinateVector = geometryColumn.getChildAt(0).getChildAt(0).getChildAt(0);

const flatCoordinateArray = flatCoordinateVector.data[0].values

const data = {
length: arrowTable.numRows,
startIndices: resolvedPolygonIndices,
attributes: {
getPolygon: { value: flatCoordinateArray, size: 2 },
}
};

const arrowLayer = new deck.SolidPolygonLayer({
id:"arrow2-layer",
data:data,
_normalize: false,
getFillColor: [255, 0, 0],
getLineColor: [80, 80, 80],
})
console.log(data)
deckgl.setProps({layers: [tileLayer, arrowLayer]})

const text = await arrowTable.toString(); //resultをテキストに変換
return JSON.parse(text); //resultをJSONに変換
}
*/
Insert cell
Insert cell
Insert cell
Insert cell
Inputs.table(result)
Insert cell
Insert cell
getDb = async () => {
// JSDELIVR_BUNDLESからDuckDBのバンドルを選択して取得する
const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);
// 新しいWeb Workerを作成するためのURLを生成する
// Blobを使用して、インポートスクリプトを含む新しいJavaScriptファイルを作成する
const worker_url = URL.createObjectURL(
new Blob([`importScripts("${bundle.mainWorker}");`], {
type: "text/javascript",
})
);
// 上記で作成したURLを使用して新しいWeb Workerを作成
const worker = new Worker(worker_url);
// コンソールにログを出力するためのロガーを作成
const logger = new duckdb.ConsoleLogger();
// 作成したWeb Workerとロガーを使用して、非同期DuckDBインスタンスを作成
const db = new duckdb.AsyncDuckDB(logger, worker);
// DuckDBインスタンスを初期化
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
// Web WorkerのURLを解放
URL.revokeObjectURL(worker_url);
// 初期化されたDuckDBインスタンスを返す
return db;
}
Insert cell
Insert cell
db = getDb()
Insert cell
Insert cell
conn = db.connect()
Insert cell
{
await conn.query(`INSTALL spatial;`);
await conn.query(`LOAD spatial;`);
}
Insert cell
Insert cell
deckgl = new deck.DeckGL({
container,
controller: true,
initialViewState:{
longitude: -71.51,
latitude: 47.895,
zoom: 7.5,
minZoom: 5,
maxZoom: 15,
}
});
Insert cell
deckgl.setProps({layers: [tileLayer]})
Insert cell
Insert cell
duckdb = import("https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm/+esm")
Insert cell
JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles()
Insert cell
deck = require.alias({
// optional dependencjei
h3: {}
})('deck.gl@^8.3.7/dist.min.js')
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