Public
Edited
Sep 30, 2022
1 fork
17 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
SPL = import("https://cdn.skypack.dev/spl.js@0.1.0-beta.7?min")
Insert cell
Insert cell
spl = SPL.default([]).then((spl) => spl)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db = {
let db = spl
.mount("data", [
{
name: "world.geojson",
data: await FileAttachment("world.json").arrayBuffer()
},
{
name: "cities.geojson",
data: await FileAttachment("majorcities.json").arrayBuffer()
}
])
.db();

// see https://www.gaia-gis.it/fossil/libspatialite/wiki?name=Supporting+GeoJSON
db.exec("SELECT InitSpatialMetaDataFull(1)")
.exec("SELECT ImportGeoJSON('/data/world.geojson', 'world')")
.exec(
"SELECT ImportGeoJSON(?, ?)", // Another syntax
["/data/cities.geojson", "cities"] // Another syntax
);

return db;
}
Insert cell
Insert cell
geometry_columns = db.exec("SELECT * FROM geometry_columns").get.objs
Insert cell
Inputs.table(geometry_columns)
Insert cell
db.exec("SELECT * FROM geometry_columns WHERE f_table_name LIKE 'world'").get
.first
Insert cell
db.exec("SELECT count(*) from world").get.first // OK
Insert cell
Inputs.table(db.exec("pragma table_info(world);").get.objs)
Insert cell
db.exec("SELECT count(*) from cities").get.first
Insert cell
Inputs.table(db.exec("pragma table_info(cities);").get.objs)
Insert cell
Inputs.table(db.exec("SELECT * from cities").get.objs)
Insert cell
Insert cell
Insert cell
Inputs.table(
db.exec(
"SELECT id, name, st_area(geometry, false) / 1000000 as area from world order by area desc"
).get.objs
)
Insert cell
Insert cell
Inputs.table(
db.exec(
"SELECT f.id as id1, f.name as name1, g.id as id2, g.name as name2, st_distance(st_centroid(f.geometry), st_centroid(g.geometry), true) AS distance FROM (SELECT * from world where id = 'BRA') AS f, world AS g"
).get.objs
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
countries = exec(db, "select * from world")
Insert cell
Insert cell
Insert cell
db
.exec(
"select json_object('id', id, 'name', name) as properties, geometry from world"
)
.get.objs.then((d) => ({ type: "FeatureCollection", features: d }))
Insert cell
Insert cell
Insert cell
centroids = exec(
db,
"select id, name, st_centroid(world.geometry) as geometry from world"
)
Insert cell
Insert cell
Insert cell
bound = exec(
db,
"select id, name, ST_Boundary(world.geometry) as geometry from world"
)
Insert cell
Insert cell
Insert cell
buff = exec(
db,
"select id, name, st_buffer(world.geometry, 2) as geometry from world where id = 'BRA'"
)
Insert cell
Insert cell
Insert cell
envelope = exec(
db,
"select id, name, ST_Envelope(world.geometry) as geometry from world where id = 'BRA'"
)
Insert cell
Insert cell
Insert cell
difference = exec(
db,
"select id, name, ST_Difference(ST_Buffer(geometry, 1),ST_Buffer(geometry, -1)) as geometry from world where id = 'BRA'"
)
Insert cell
Insert cell
Insert cell
intersection = exec(
db,
"SELECT f.id as id1, g.id as id2, 1 as dist, ST_Intersection(st_buffer(f.geometry, 1), st_buffer(g.geometry, 1)) AS geometry FROM (SELECT * from world where id = 'BRA') AS f, (SELECT * from world where id = 'BOL') AS g"
)
Insert cell
Insert cell
Insert cell
hull = exec(
db,
"select id, name, ConvexHull(world.geometry) as geometry from world where id = 'BRA'"
)
Insert cell
Insert cell
Insert cell
hull2 = exec(
db,
"select id, name, ConcaveHull(world.geometry) as geometry from world where id = 'BRA'"
)
Insert cell
Insert cell
Insert cell
delaunay = exec(
db,
"select ST_DelaunayTriangulation(ST_Collect(st_centroid(world.geometry)),1,0) as geometry from world"
)
Insert cell
Insert cell
Insert cell
voronoi = exec(
db,
"select ST_VoronojDiagram(ST_Collect(st_centroid(world.geometry)),1,0) as geometry from world"
)
Insert cell
Insert cell
Insert cell
contains = exec(
db,
"SELECT c.id, c.city as namen, c.geometry as geometry FROM (SELECT * from world where id = 'CHN') as b, cities as c where Contains(b.geometry, c.geometry)"
)
Insert cell
Insert cell
Insert cell
disjoint = exec(
db,
"SELECT c.id, c.city as namen, c.geometry as geometry FROM (SELECT * from world where id = 'CHN') as b, cities as c where Disjoint(b.geometry, c.geometry)"
)
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