-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.html
More file actions
808 lines (788 loc) · 40.2 KB
/
README.html
File metadata and controls
808 lines (788 loc) · 40.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.8.27">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>readme</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="README_files/libs/clipboard/clipboard.min.js"></script>
<script src="README_files/libs/quarto-html/quarto.js" type="module"></script>
<script src="README_files/libs/quarto-html/tabsets/tabsets.js" type="module"></script>
<script src="README_files/libs/quarto-html/axe/axe-check.js" type="module"></script>
<script src="README_files/libs/quarto-html/popper.min.js"></script>
<script src="README_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="README_files/libs/quarto-html/anchor.min.js"></script>
<link href="README_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="README_files/libs/quarto-html/quarto-syntax-highlighting-ed96de9b727972fe78a7b5d16c58bf87.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="README_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="README_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="README_files/libs/bootstrap/bootstrap-9e3ffae467580fdb927a41352e75a2e0.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent quarto-light">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<section id="spatial-sql-explorer" class="level1">
<h1>Spatial SQL Explorer</h1>
<p>A client-side spatial data analysis tool that lets you load GeoJSON, CSV, TSV, and Parquet files, run SQL queries with DuckDB, and explore results interactively on a map — all in the browser with no backend required.</p>
<p><img src="https://img.shields.io/badge/built%20with-DuckDB%20WASM-f0a500?style=flat-square.png" class="img-fluid" alt="Spatial SQL Explorer"> <img src="https://img.shields.io/badge/map-MapLibre%20GL%20v5-3ddc84?style=flat-square.png" class="img-fluid" alt="MapLibre GL"> <img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square.png" class="img-fluid" alt="License"></p>
<hr>
<section id="overview" class="level2">
<h2 class="anchored" data-anchor-id="overview">Overview</h2>
<p>Spatial SQL Explorer brings together a SQL engine, an interactive map, and a live results table in a single-page application. Every computation runs in your browser using WebAssembly — your data never leaves your machine.</p>
<p>It was inspired by <a href="https://personal.tcu.edu/kylewalker/urbangis/sql-explorer/">Kyle Walker’s Spatial SQL Explorer</a> and built to be fully open, self-hostable, and extensible.</p>
<hr>
</section>
<section id="features" class="level2">
<h2 class="anchored" data-anchor-id="features">Features</h2>
<ul>
<li><strong>Client-side SQL</strong> — Full DuckDB WASM engine with the spatial extension loaded in-browser. Supports spatial functions like <code>ST_Within</code>, <code>ST_Intersects</code>, <code>ST_Area</code>, and more.</li>
<li><strong>Multi-format file loading</strong> — Load GeoJSON, CSV, TSV, and Parquet files via drag-and-drop or file picker. Each file is registered as a named DuckDB table. Multiple tables can be loaded and queried simultaneously.</li>
<li><strong>Live map rendering</strong> — Query results with geometry render instantly on a MapLibre GL globe. Points, lines, and polygons each get dedicated styled layers.</li>
<li><strong>Map styling</strong> — Style query results using Single color, Graduated (choropleth), or Categorical modes. Graduated mode supports Quantile, Equal Interval, and Natural Breaks classification with 3–9 classes and multiple color ramps. Categorical mode auto-assigns colors to up to 20 unique values.</li>
<li><strong>Interactive legend</strong> — An on-map legend updates live after applying a style. Graduated legends include a draggable range-filter slider to subset visible features without re-running SQL. Categorical legends support toggling individual categories on and off.</li>
<li><strong>Two-way selection</strong> — Click a feature on the map to highlight its row in the table. Check a row in the table to highlight its feature on the map. Multi-select supported.</li>
<li><strong>Client-side filtering and sorting</strong> — Filter any column with a live text input. Sort any column ascending or descending. Both operate on the current result set without re-running SQL.</li>
<li><strong>Session persistence</strong> — Loaded tables, query history, and your last query are saved to IndexedDB and restored automatically on next visit. No data leaves your machine.</li>
<li><strong>Shareable links</strong> — The ⬡ Share button encodes the current SQL query and map style into a URL hash. Paste the link anywhere to share an exact view with others.</li>
<li><strong>Export</strong> — Download results as CSV or GeoJSON. Export the current map view as a PNG (with legend burned in).</li>
<li><strong>Multiple basemaps</strong> — Switch between Light, Dark, Satellite (Esri), and Topo (OpenTopoMap) basemaps. The basemap auto-switches to match the app theme when on Light or Dark.</li>
<li><strong>Light / dark theme</strong> — Toggle between themes with the ☾/☀ button. Follows your OS preference by default; manual selection is remembered.</li>
<li><strong>Globe projection</strong> — Starts in globe mode. Powered by MapLibre GL v5.</li>
<li><strong>Geocoder</strong> — Search any location worldwide via Nominatim (OpenStreetMap) to navigate the map.</li>
<li><strong>Auto-zoom</strong> — After each query, the map flies smoothly to the extent of the result features.</li>
<li><strong>SQL autocomplete</strong> — The editor is schema-aware: table names and column names from all loaded tables are available as autocomplete suggestions.</li>
<li><strong>Query history</strong> — Past queries are stored in the session with row counts and execution times. Click any history entry to restore it to the editor.</li>
<li><strong>Safety cap</strong> — Configurable row limit automatically appended to queries that don’t include one, preventing accidental rendering of huge datasets.</li>
<li><strong>Resizable panels</strong> — Drag the handles between panels to resize the left, map, and right columns. Double-click a handle to reset to default.</li>
<li><strong>No backend, no build step</strong> — Pure HTML, CSS, and JavaScript. All dependencies loaded from CDN. Deploy anywhere static files are served.</li>
</ul>
<hr>
</section>
<section id="tech-stack" class="level2">
<h2 class="anchored" data-anchor-id="tech-stack">Tech Stack</h2>
<table class="caption-top table">
<thead>
<tr class="header">
<th>Component</th>
<th>Library</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>SQL engine</td>
<td><a href="https://duckdb.org/docs/api/wasm/overview">DuckDB WASM</a> v1.29</td>
<td>Runs entirely in-browser via WebAssembly</td>
</tr>
<tr class="even">
<td>Spatial extension</td>
<td>DuckDB spatial</td>
<td><code>ST_Read</code>, <code>ST_AsGeoJSON</code>, spatial predicates</td>
</tr>
<tr class="odd">
<td>Map</td>
<td><a href="https://maplibre.org/">MapLibre GL JS</a> v5</td>
<td>Globe projection, GeoJSON layers</td>
</tr>
<tr class="even">
<td>Map tiles</td>
<td><a href="https://openfreemap.org/">OpenFreeMap</a></td>
<td>Free, no API key required (Light + Dark)</td>
</tr>
<tr class="odd">
<td>SQL editor</td>
<td><a href="https://codemirror.net/">CodeMirror 6</a></td>
<td>SQL syntax highlighting, schema-aware autocomplete, <code>Ctrl+Enter</code> to run</td>
</tr>
<tr class="even">
<td>Geocoder</td>
<td><a href="https://github.com/maplibre/maplibre-gl-geocoder">maplibre-gl-geocoder</a> + <a href="https://nominatim.org/">Nominatim</a></td>
<td>Free, no API key required</td>
</tr>
<tr class="odd">
<td>Persistence</td>
<td>IndexedDB (browser-native)</td>
<td>Tables, history, and last query survive page reload</td>
</tr>
<tr class="even">
<td>SharedArrayBuffer</td>
<td><a href="https://github.com/gzuidhof/coi-serviceworker">coi-serviceworker</a></td>
<td>Enables DuckDB multithreading on GitHub Pages</td>
</tr>
</tbody>
</table>
<hr>
</section>
<section id="getting-started" class="level2">
<h2 class="anchored" data-anchor-id="getting-started">Getting Started</h2>
<section id="run-locally" class="level3">
<h3 class="anchored" data-anchor-id="run-locally">Run locally</h3>
<p>Clone the repo and serve it with any static file server. A simple option using Python:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">git</span> clone https://github.com/your-username/spatial-sql-explorer.git</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> spatial-sql-explorer</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="ex">python3</span> <span class="at">-m</span> http.server 8080</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<p>Then open <a href="http://localhost:8080">http://localhost:8080</a> in your browser.</p>
<blockquote class="blockquote">
<p><strong>Important:</strong> DuckDB WASM requires <code>SharedArrayBuffer</code>, which requires the page to be served over HTTP (not opened directly as a <code>file://</code> URL) and needs cross-origin isolation headers. The included <code>coi-serviceworker.min.js</code> handles this automatically.</p>
</blockquote>
</section>
<section id="deploy-to-github-pages" class="level3">
<h3 class="anchored" data-anchor-id="deploy-to-github-pages">Deploy to GitHub Pages</h3>
<ol type="1">
<li>Push the repository to GitHub.</li>
<li>Go to <strong>Settings → Pages</strong> in your repository.</li>
<li>Set the source to the <code>main</code> branch, root folder.</li>
<li>GitHub Pages will serve the app at <code>https://your-username.github.io/spatial-sql-explorer/</code>.</li>
</ol>
<p>The <code>coi-serviceworker.min.js</code> file in the project root handles the <code>Cross-Origin-Embedder-Policy</code> and <code>Cross-Origin-Opener-Policy</code> headers that GitHub Pages doesn’t set natively — no server configuration needed.</p>
<hr>
</section>
</section>
<section id="usage" class="level2">
<h2 class="anchored" data-anchor-id="usage">Usage</h2>
<section id="loading-data" class="level3">
<h3 class="anchored" data-anchor-id="loading-data">Loading data</h3>
<p><strong>Demo data</strong> — Click <strong>Demo Data</strong> to load the included sample dataset of points of interest in the Dallas–Fort Worth metro area. A default query runs automatically.</p>
<p><strong>Your own data</strong> — Drag and drop one or more files onto the drop zone, or click to browse. Supported formats:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Format</th>
<th>Extension</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>GeoJSON</td>
<td><code>.geojson</code>, <code>.json</code></td>
<td>Points, lines, polygons, multi-geometries, GeometryCollections</td>
</tr>
<tr class="even">
<td>CSV</td>
<td><code>.csv</code></td>
<td>Auto-detected delimiter and types</td>
</tr>
<tr class="odd">
<td>TSV</td>
<td><code>.tsv</code></td>
<td>Tab-separated</td>
</tr>
<tr class="even">
<td>Parquet</td>
<td><code>.parquet</code></td>
<td>Column-oriented binary format</td>
</tr>
</tbody>
</table>
<p>Each file is registered as a DuckDB table named after the file (e.g. <code>my_data.geojson</code> → table <code>my_data</code>). All loaded tables appear in the <strong>Loaded Tables</strong> registry at the top of the left panel, where you can query or remove them individually. Tables persist across page reloads via IndexedDB.</p>
</section>
<section id="writing-queries" class="level3">
<h3 class="anchored" data-anchor-id="writing-queries">Writing queries</h3>
<p>Use the SQL editor on the left. Press <strong>Ctrl+Enter</strong> (or <strong>Cmd+Enter</strong> on Mac) or click <strong>▶ Run Query</strong> to execute. The editor provides autocomplete for table names and column names from all loaded tables.</p>
<p>Any valid DuckDB SQL works. Some examples:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2"><pre class="sourceCode sql code-with-copy"><code class="sourceCode sql"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co">-- Basic select</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="kw">SELECT</span> <span class="op">*</span> <span class="kw">FROM</span> places <span class="kw">LIMIT</span> <span class="dv">100</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="co">-- Filter by attribute</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="kw">SELECT</span> <span class="op">*</span> <span class="kw">FROM</span> places <span class="kw">WHERE</span> <span class="kw">category</span> <span class="op">=</span> <span class="st">'restaurant'</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="co">-- Spatial filter: features within a bounding box</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="kw">SELECT</span> <span class="op">*</span> <span class="kw">FROM</span> places</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a><span class="kw">WHERE</span> ST_Within(geometry, ST_MakeEnvelope(<span class="op">-</span><span class="fl">97.0</span>, <span class="fl">32.7</span>, <span class="op">-</span><span class="fl">96.7</span>, <span class="fl">33.0</span>))</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a><span class="co">-- Aggregate</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a><span class="kw">SELECT</span> <span class="kw">category</span>, <span class="fu">COUNT</span>(<span class="op">*</span>) <span class="kw">AS</span> <span class="fu">count</span>, <span class="fu">AVG</span>(confidence) <span class="kw">AS</span> avg_conf</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a><span class="kw">FROM</span> places</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a><span class="kw">GROUP</span> <span class="kw">BY</span> <span class="kw">category</span></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a><span class="kw">ORDER</span> <span class="kw">BY</span> <span class="fu">count</span> <span class="kw">DESC</span></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a><span class="co">-- Spatial join: features within a polygon from another table</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a><span class="kw">SELECT</span> a.<span class="op">*</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a><span class="kw">FROM</span> points a, districts b</span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a><span class="kw">WHERE</span> ST_Within(a.geometry, b.geometry)</span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a><span class="kw">AND</span> b.name <span class="op">=</span> <span class="st">'Downtown'</span></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<p>If your query doesn’t include a <code>LIMIT</code> clause, the safety cap (default 50,000 rows) is appended automatically. You can adjust this in the <strong>LIMIT</strong> input next to the Run button.</p>
</section>
<section id="styling-the-map" class="level3">
<h3 class="anchored" data-anchor-id="styling-the-map">Styling the map</h3>
<p>After a query returns geometry results, the <strong>Map Style</strong> panel appears in the right column. Choose a mode with the pill toggle:</p>
<ul>
<li><strong>Single</strong> — Apply one color to all features.</li>
<li><strong>Graduated</strong> — Choropleth by a numeric column. Choose a classification method (Quantile, Equal Interval, Natural Breaks), number of classes (3–9), and a color ramp. Click ⇅ to invert the ramp.</li>
<li><strong>Categorical</strong> — Color features by a string or numeric column. Up to 20 unique categories are colored automatically.</li>
</ul>
<p>Use the <strong>Opacity</strong> slider to control transparency, then click <strong>Apply</strong> to render the style on the map.</p>
</section>
<section id="using-the-interactive-legend" class="level3">
<h3 class="anchored" data-anchor-id="using-the-interactive-legend">Using the interactive legend</h3>
<p>After clicking Apply, an interactive legend appears on the map:</p>
<ul>
<li><strong>Graduated</strong> — A draggable range-filter slider lets you narrow the visible features to a value range without re-running SQL. Drag the handles or slide the selection window.</li>
<li><strong>Categorical</strong> — Click any category row to toggle its visibility on the map.</li>
<li>Click <strong>✕</strong> to dismiss the legend and clear any active filter.</li>
</ul>
</section>
<section id="interacting-with-results" class="level3">
<h3 class="anchored" data-anchor-id="interacting-with-results">Interacting with results</h3>
<p><strong>Table filtering</strong> — Type in the filter input below any column header to filter rows in real time. Multiple column filters apply simultaneously.</p>
<p><strong>Table sorting</strong> — Click any column header to sort ascending. Click again to sort descending. Click a third time to clear the sort.</p>
<p><strong>Selecting features</strong> — Check the checkbox on any row to highlight the corresponding feature on the map in yellow. Click a feature on the map to check its row and scroll the table to it. Check the header checkbox to select all currently visible rows.</p>
</section>
<section id="exporting" class="level3">
<h3 class="anchored" data-anchor-id="exporting">Exporting</h3>
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Button</th>
<th>Output</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>CSV</strong></td>
<td>Current filtered result (non-geometry columns) as a <code>.csv</code> file</td>
</tr>
<tr class="even">
<td><strong>GeoJSON</strong></td>
<td>Current filtered result as a <code>.geojson</code> FeatureCollection</td>
</tr>
<tr class="odd">
<td><strong>⬡ Share</strong></td>
<td>Copies a URL to the clipboard encoding the current SQL query and map style</td>
</tr>
<tr class="even">
<td><strong>⬇ PNG</strong></td>
<td>Exports the current map view as a PNG with the legend burned in</td>
</tr>
</tbody>
</table>
<blockquote class="blockquote">
<p><strong>Note:</strong> PNG export works best with the Light or Dark basemap. Satellite and Topo tiles are CORS-restricted; if they block the canvas read, only the legend is exported.</p>
</blockquote>
</section>
<section id="navigating-the-map" class="level3">
<h3 class="anchored" data-anchor-id="navigating-the-map">Navigating the map</h3>
<ul>
<li><strong>Basemap switcher</strong> — Toggle between Light, Dark, Satellite, and Topo basemaps using the pill buttons in the top-left corner of the map.</li>
<li><strong>Theme toggle</strong> — Click ☾/☀ in the app header to switch between dark and light themes. Switching between Light/Dark themes also switches the basemap automatically.</li>
<li><strong>Geocoder</strong> — Search any place name or address using the search bar in the top-right corner.</li>
<li><strong>Globe toggle</strong> — Switch between globe and flat Mercator projection using the globe button.</li>
<li><strong>Zoom controls</strong> — Standard zoom in/out buttons.</li>
<li><strong>Auto-zoom</strong> — The map automatically flies to the extent of each query result.</li>
<li><strong>Resize panels</strong> — Drag the vertical handles between panels to adjust the width of the left, map, and right columns. Double-click a handle to reset it.</li>
</ul>
<hr>
</section>
</section>
<section id="project-structure" class="level2">
<h2 class="anchored" data-anchor-id="project-structure">Project Structure</h2>
<pre><code>spatial-sql-explorer/
├── index.html # App shell, CDN imports, three-column layout
├── coi-serviceworker.min.js # Cross-origin isolation for SharedArrayBuffer
├── css/
│ └── style.css # All styles — layout, panels, table, map, themes
├── js/
│ └── app.js # All application logic (ES module)
└── data/
└── demo.geojson # Sample DFW points of interest</code></pre>
<p>All logic lives in <code>app.js</code> as a single ES module. There is no bundler, no <code>node_modules</code>, and no build step. Dependencies are loaded via CDN at runtime.</p>
<hr>
</section>
<section id="browser-compatibility" class="level2">
<h2 class="anchored" data-anchor-id="browser-compatibility">Browser Compatibility</h2>
<p>Requires a modern browser with WebAssembly and ES module support. Tested in:</p>
<ul>
<li>Chrome / Edge 90+</li>
<li>Firefox 90+</li>
<li>Safari 15+</li>
</ul>
<p>Not supported in Internet Explorer.</p>
<hr>
</section>
<section id="known-limitations" class="level2">
<h2 class="anchored" data-anchor-id="known-limitations">Known Limitations</h2>
<ul>
<li><strong>Large files</strong> — Very large files (100MB+) may be slow to load or exceed browser memory. Consider filtering or simplifying large datasets before loading.</li>
<li><strong>Spatial extension</strong> — Installation of the DuckDB spatial extension requires an internet connection on first load, as it downloads the extension WASM binary from the DuckDB CDN.</li>
<li><strong>PNG export</strong> — Satellite and Topo basemaps use CORS-restricted tiles. If the map canvas is tainted, only the legend is exported. Switch to the Light basemap for a full map PNG.</li>
<li><strong>Share links and uploaded files</strong> — The ⬡ Share URL encodes SQL and style, but not the uploaded file data itself. Recipients need to load the same file(s) before the shared query will run.</li>
</ul>
<hr>
</section>
<section id="acknowledgements" class="level2">
<h2 class="anchored" data-anchor-id="acknowledgements">Acknowledgements</h2>
<ul>
<li>Inspired by <a href="https://personal.tcu.edu/kylewalker/urbangis/sql-explorer/">Kyle Walker’s Spatial SQL Explorer</a></li>
<li><a href="https://duckdb.org/">DuckDB</a> for the incredible in-process analytical SQL engine</li>
<li><a href="https://maplibre.org/">MapLibre GL JS</a> for open-source WebGL map rendering</li>
<li><a href="https://openfreemap.org/">OpenFreeMap</a> for free, open map tiles</li>
<li><a href="https://nominatim.org/">Nominatim</a> / <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors for geocoding</li>
</ul>
<hr>
</section>
<section id="license" class="level2">
<h2 class="anchored" data-anchor-id="license">License</h2>
<p>MIT — see <a href="LICENSE">LICENSE</a> for details.</p>
</section>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const onCopySuccess = function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
}
const getTextToCopy = function(trigger) {
const outerScaffold = trigger.parentElement.cloneNode(true);
const codeEl = outerScaffold.querySelector('code');
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
text: getTextToCopy
});
clipboard.on('success', onCopySuccess);
if (window.document.getElementById('quarto-embedded-source-code-modal')) {
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
text: getTextToCopy,
container: window.document.getElementById('quarto-embedded-source-code-modal')
});
clipboardModal.on('success', onCopySuccess);
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var mailtoRegex = new RegExp(/^mailto:/);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// undo the damage that might have been done by quarto-nav.js in the case of
// links that we want to consider external
if (link.dataset.originalHref !== undefined) {
link.href = link.dataset.originalHref;
}
}
}
function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
const config = {
allowHTML: true,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start',
};
if (contentFn) {
config.content = contentFn;
}
if (onTriggerFn) {
config.onTrigger = onTriggerFn;
}
if (onUntriggerFn) {
config.onUntrigger = onUntriggerFn;
}
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note) {
return note.innerHTML;
} else {
return "";
}
});
}
const xrefs = window.document.querySelectorAll('a.quarto-xref');
const processXRef = (id, note) => {
// Strip column container classes
const stripColumnClz = (el) => {
el.classList.remove("page-full", "page-columns");
if (el.children) {
for (const child of el.children) {
stripColumnClz(child);
}
}
}
stripColumnClz(note)
if (id === null || id.startsWith('sec-')) {
// Special case sections, only their first couple elements
const container = document.createElement("div");
if (note.children && note.children.length > 2) {
container.appendChild(note.children[0].cloneNode(true));
for (let i = 1; i < note.children.length; i++) {
const child = note.children[i];
if (child.tagName === "P" && child.innerText === "") {
continue;
} else {
container.appendChild(child.cloneNode(true));
break;
}
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(container);
}
return container.innerHTML
} else {
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
return note.innerHTML;
}
} else {
// Remove any anchor links if they are present
const anchorLink = note.querySelector('a.anchorjs-link');
if (anchorLink) {
anchorLink.remove();
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
if (note.classList.contains("callout")) {
return note.outerHTML;
} else {
return note.innerHTML;
}
}
}
for (var i=0; i<xrefs.length; i++) {
const xref = xrefs[i];
tippyHover(xref, undefined, function(instance) {
instance.disable();
let url = xref.getAttribute('href');
let hash = undefined;
if (url.startsWith('#')) {
hash = url;
} else {
try { hash = new URL(url).hash; } catch {}
}
if (hash) {
const id = hash.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note !== null) {
try {
const html = processXRef(id, note.cloneNode(true));
instance.setContent(html);
} finally {
instance.enable();
instance.show();
}
} else {
// See if we can fetch this
fetch(url.split('#')[0])
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.getElementById(id);
if (note !== null) {
const html = processXRef(id, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
} else {
// See if we can fetch a full url (with no hash to target)
// This is a special case and we should probably do some content thinning / targeting
fetch(url)
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.querySelector('main.content');
if (note !== null) {
// This should only happen for chapter cross references
// (since there is no id in the URL)
// remove the first header
if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
note.children[0].remove();
}
const html = processXRef(null, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
}, function(instance) {
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
div.style.left = 0;
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Handle positioning of the toggle
window.addEventListener(
"resize",
throttle(() => {
elRect = undefined;
if (selectedAnnoteEl) {
selectCodeLines(selectedAnnoteEl);
}
}, 10)
);
function throttle(fn, ms) {
let throttle = false;
let timer;
return (...args) => {
if(!throttle) { // first call gets through
fn.apply(this, args);
throttle = true;
} else { // all the others get throttled
if(timer) clearTimeout(timer); // cancel #2
timer = setTimeout(() => {
fn.apply(this, args);
timer = throttle = false;
}, ms);
}
};
}
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>