<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: tg</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/tg.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2023-09-25T19:45:03+00:00</updated><author><name>Simon Willison</name></author><entry><title>Geospatial SQL queries in SQLite using TG, sqlite-tg and datasette-sqlite-tg</title><link href="https://simonwillison.net/2023/Sep/25/tg-sqlite/#atom-tag" rel="alternate"/><published>2023-09-25T19:45:03+00:00</published><updated>2023-09-25T19:45:03+00:00</updated><id>https://simonwillison.net/2023/Sep/25/tg-sqlite/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://til.simonwillison.net/sqlite/sqlite-tg"&gt;Geospatial SQL queries in SQLite using TG, sqlite-tg and datasette-sqlite-tg&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Alex Garcia built sqlite-tg—a SQLite extension that uses the brand new TG geospatial library to provide a whole suite of custom SQL functions for working with geospatial data.&lt;/p&gt;

&lt;p&gt;Here are my notes on trying out his initial alpha releases. The extension already provides tools for converting between GeoJSON, WKT and WKB, plus the all important tg_intersects() function for testing if a polygon or point overlap each other.&lt;/p&gt;

&lt;p&gt;It’s pretty useful already. Without any geospatial indexing at all I was still able to get 700ms replies to a brute-force point-in-polygon query against 150MB of GeoJSON timezone boundaries stored as JSON text in a table.


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/geospatial"&gt;geospatial&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/sqlite"&gt;sqlite&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/geojson"&gt;geojson&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/datasette"&gt;datasette&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/alex-garcia"&gt;alex-garcia&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/tg"&gt;tg&lt;/a&gt;&lt;/p&gt;



</summary><category term="geospatial"/><category term="sqlite"/><category term="geojson"/><category term="datasette"/><category term="alex-garcia"/><category term="tg"/></entry><entry><title>TG: Polygon indexing</title><link href="https://simonwillison.net/2023/Sep/23/tg-polygon-indexing/#atom-tag" rel="alternate"/><published>2023-09-23T04:32:14+00:00</published><updated>2023-09-23T04:32:14+00:00</updated><id>https://simonwillison.net/2023/Sep/23/tg-polygon-indexing/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/tidwall/tg/blob/v0.1.0/docs/POLYGON_INDEXING.md"&gt;TG: Polygon indexing&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
TG is a brand new geospatial library by Josh Baker, author of the Tile38 in-memory spatial server (kind of a geospatial Redis). TG is written in pure C and delivered as a single C file, reminiscent of the SQLite amalgamation.&lt;/p&gt;

&lt;p&gt;TG looks really interesting. It implements almost the exact subset of geospatial functionality that I find most useful: point-in-polygon, intersect, WKT, WKB, and GeoJSON—all with no additional dependencies.&lt;/p&gt;

&lt;p&gt;The most interesting thing about it is the way it handles indexing. In this documentation Josh describes two approaches he uses to speeding up point-in-polygon and intersection using a novel approach that goes beyond the usual RTree implementation.&lt;/p&gt;

&lt;p&gt;I think this could make the basis of a really useful SQLite extension—a lighter-weight alternative to SpatiaLite.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="https://news.ycombinator.com/item?id=37619100"&gt;Hacker News&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/c"&gt;c&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/geospatial"&gt;geospatial&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/spatialite"&gt;spatialite&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/sqlite"&gt;sqlite&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/geojson"&gt;geojson&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/tg"&gt;tg&lt;/a&gt;&lt;/p&gt;



</summary><category term="c"/><category term="geospatial"/><category term="spatialite"/><category term="sqlite"/><category term="geojson"/><category term="tg"/></entry></feed>