{"id":20705250,"url":"https://github.com/whosonfirst/go-whosonfirst-spatial-sqlite","last_synced_at":"2025-10-16T01:57:07.025Z","repository":{"id":51101251,"uuid":"318601532","full_name":"whosonfirst/go-whosonfirst-spatial-sqlite","owner":"whosonfirst","description":"SQLite-backed implementation of the go-whosonfirst-spatial interfaces.","archived":false,"fork":false,"pushed_at":"2024-08-12T17:09:07.000Z","size":32906,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-08-12T19:59:25.434Z","etag":null,"topics":["golang","sqlite","whosonfirst","whosonfirst-spatial"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whosonfirst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-04T18:21:48.000Z","updated_at":"2024-08-12T17:08:43.000Z","dependencies_parsed_at":"2024-04-02T22:41:53.565Z","dependency_job_id":"894b9d6d-6a65-4bc9-943a-3deee8f2caed","html_url":"https://github.com/whosonfirst/go-whosonfirst-spatial-sqlite","commit_stats":null,"previous_names":["whosonfirst/go-whosonfirst-spatial-database-sqlite"],"tags_count":75,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whosonfirst%2Fgo-whosonfirst-spatial-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whosonfirst%2Fgo-whosonfirst-spatial-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whosonfirst%2Fgo-whosonfirst-spatial-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whosonfirst%2Fgo-whosonfirst-spatial-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whosonfirst","download_url":"https://codeload.github.com/whosonfirst/go-whosonfirst-spatial-sqlite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224986318,"owners_count":17402957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","sqlite","whosonfirst","whosonfirst-spatial"],"created_at":"2024-11-17T01:16:54.704Z","updated_at":"2025-10-16T01:57:07.020Z","avatar_url":"https://github.com/whosonfirst.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-whosonfirst-spatial-sqlite\n\nSQLite-backed implementation of the go-whosonfirst-spatial interfaces.\n\n## Important\n\nThis is work in progress. It may change still. The goal is to have a package that conforms to the [database.SpatialDatabase](https://github.com/whosonfirst/go-whosonfirst-spatial#spatialdatabase) interface using [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) and SQLite's [RTree](https://www.sqlite.org/rtree.html) extension.\n\n## Documentation\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/whosonfirst/go-whosonfirst-spatial-sqlite.svg)](https://pkg.go.dev/github.com/whosonfirst/go-whosonfirst-spatial-sqlite)\n\nDocumentation is incomplete.\n\n## Databases\n\nThis code depends on (4) tables as indexed by the `go-whosonfirst-sqlite-features` package:\n\n* [rtree](https://github.com/whosonfirst/go-whosonfirst-database/blob/main/sql/tables/rtree.sqlite.schema) - this table is used to perform point-in-polygon spatial queries.\n* [spr](https://github.com/whosonfirst/go-whosonfirst-database/blob/main/sql/tables/spr.sqlite.schema) - this table is used to generate [standard place response](#) (SPR) results.\n* [properties](https://github.com/whosonfirst/go-whosonfirst-database/blob/main/sql/tables/properties.sqlite.schema) - this table is used to append extra properties (to the SPR response) for `spatial.PropertiesResponseResults` responses.\n* [geojson](https://github.com/whosonfirst/go-whosonfirst-database/blob/main/sql/tables/geojson.sqlite.schema) - this table is used to satisfy the `whosonfirst/go-reader.Reader` requirements in the `spatial.SpatialDatabase` interface. It is meant to be a simple ID to bytes (or filehandle) lookup rather than a data structure that is parsed or queried.\n\nHere's an example of the creating a compatible SQLite database for all the [administative data in Canada](https://github.com/whosonfirst-data/whosonfirst-data-admin-ca) using the `wof-sqlite-index` tool which is part of the [go-whosonfirst-database](https://github.com/whosonfirst/go-whosonfirst-database) package:\n\n```\n$\u003e ./bin/wof-sqlite-index \\\n\t-index-alt-files \\\n\t-spatial-tables \\\n\t-timings \\\n\t-database-uri 'sql://sqlite3?dsn=/usr/local/ca-alt.db' \\\n\t-iterator-uri repo:// \\\n\t/usr/local/data/whosonfirst-data-admin-ca/\n\n13:09:44.642004 [wof-sqlite-index-features] STATUS time to index rtree (11860) : 30.469010289s\n13:09:44.642136 [wof-sqlite-index-features] STATUS time to index geometry (11860) : 5.155172377s\n13:09:44.642141 [wof-sqlite-index-features] STATUS time to index properties (11860) : 4.631908497s\n13:09:44.642143 [wof-sqlite-index-features] STATUS time to index spr (11860) : 19.160260741s\n13:09:44.642146 [wof-sqlite-index-features] STATUS time to index all (11860) : 1m0.000182571s\n13:10:44.642848 [wof-sqlite-index-features] STATUS time to index spr (32724) : 39.852608874s\n13:10:44.642861 [wof-sqlite-index-features] STATUS time to index rtree (32724) : 57.361318918s\n13:10:44.642864 [wof-sqlite-index-features] STATUS time to index geometry (32724) : 10.242155898s\n13:10:44.642868 [wof-sqlite-index-features] STATUS time to index properties (32724) : 10.815961878s\n13:10:44.642871 [wof-sqlite-index-features] STATUS time to index all (32724) : 2m0.000429956s\n```\n\nAnd then...\n\n```\n$\u003e ./bin/pip \\\n\t-database-uri 'sqlite://sqlite3?dsn=/usr/local/data/ca-alt.db' \\\n\t-latitude 45.572744 \\\n\t-longitude -73.586295\n| jq \\\n| grep wof:id\n\n2020/12/16 13:25:32 Time to point in polygon, 395.201983ms\n      \"wof:id\": \"85633041\",\n      \"wof:id\": \"85874359\",\n      \"wof:id\": \"1108955735\",\n      \"wof:id\": \"85874359\",\n      \"wof:id\": \"85633041\",\n      \"wof:id\": \"890458661\",\n      \"wof:id\": \"136251273\",\n      \"wof:id\": \"136251273\",\n      \"wof:id\": \"85633041\",\n      \"wof:id\": \"136251273\",\n      \"wof:id\": \"85633041\",\n```\n\n_TBW: Indexing tables on start-up._\n\n## Database URIs and \"drivers\"\n\nDatabase URIs for the `go-whosonfirst-spatial-sqlite` package take the form of:\n\n```\n\"sqlite://\" + {DATABASE_SQL_ENGINE} + \"?dsn=\" + {DATABASE_SQL_DSN}\n```\n\nWhere `DATABASE_SQL` refers to the build-in [database/sql](https://pkg.go.dev/database/sql) package.\n\nFor example:\n\n```\nsqlite://sqlite3?dsn=test.db\n```\n\nBy default this package bundles support for the [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) driver but does NOT enable it by default. You will need to pass in the `-tag mattn` argument when building tools to enable it. This is the default behaviour in the `cli` Makefile target for building binary tools.\n\nIf you want or need to use the [modernc.org/sqlite](https://pkg.go.dev/modernc.org/sqlite) driver take a look at the [database_mattn.go](database_mattn.go) file for an example of how you might go about enabling it. As of this writing the `modernc.org/sqlite` package is not bundled with this package because it adds ~200MB of code to the `vendor` directory.\n\n## Example\n\n```\npackage main\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"fmt\"\n\n\t_ \"github.com/mattn/go-sqlite3\"\n\t_ \"github.com/whosonfirst/go-whosonfirst-spatial-sqlite\"\n\t\n\t\"github.com/whosonfirst/go-whosonfirst-spatial/database\"\n\t\"github.com/whosonfirst/go-whosonfirst-spatial/filter\"\n\t\"github.com/whosonfirst/go-whosonfirst-spatial/geo\"\n\t\"github.com/whosonfirst/go-whosonfirst-spatial/properties\"\n\t\"github.com/whosonfirst/go-whosonfirst-spr\"\n)\n\nfunc main() {\n\n\tdatabase_uri := \"sqlite://sqlite3?dsn=whosonfirst.db\"\n\tproperties_uri := \"sqlite://sqlite3?dsn=whosonfirst.db\"\n\tlatitude := 37.616951\n\tlongitude := -122.383747\n\n\tprops := []string{\n\t\t\"wof:concordances\",\n\t\t\"wof:hierarchy\",\n\t\t\"sfomuseum:*\",\n\t}\n\n\tctx := context.Background()\n\t\n\tdb, _ := database.NewSpatialDatabase(ctx, *database_uri)\n\tpr, _ := properties.NewPropertiesReader(ctx, *properties_uri)\n\t\n\tc, _ := geo.NewCoordinate(*longitude, *latitude)\n\tf, _ := filter.NewSPRFilter()\n\tr, _ := db.PointInPolygon(ctx, c, f)\n\n\tr, _ = pr.PropertiesResponseResultsWithStandardPlacesResults(ctx, r, props)\n\n\tenc, _ := json.Marshal(r)\n\tfmt.Println(string(enc))\n}\n```\n\n_Error handling removed for the sake of brevity._\n\n## Filters\n\n_To be written_\n\n## Tools\n\n```\n$\u003e make cli\ngo build -tags mattn -ldflags=\"-s -w\" -mod vendor -o bin/http-server cmd/http-server/main.go\ngo build -tags mattn -ldflags=\"-s -w\" -mod vendor -o bin/grpc-server cmd/grpc-server/main.go\ngo build -tags mattn -ldflags=\"-s -w\" -mod vendor -o bin/grpc-client cmd/grpc-client/main.go\ngo build -tags mattn -ldflags=\"-s -w\" -mod vendor -o bin/update-hierarchies cmd/update-hierarchies/main.go\ngo build -tags mattn -ldflags=\"-s -w\" -mod vendor -o bin/pip cmd/pip/main.go\ngo build -tags mattn -ldflags=\"-s -w\" -mod vendor -o bin/intersects cmd/intersects/main.go\n```\n\n### pip\n\nDocumentation for the `pip` tool has been moved in to [cmd/pip/README.md](cmd/pip/README.md)\n\n### intersects\n\nDocumentation for the `pip` tool can be found in [cmd/intersects/README.md](cmd/intersects/README.md)\n\n### http-server\n\nDocumentation for the `pip` tool has been moved in to [cmd/http-server/README.md](cmd/http-server/README.md)\n\n### grpc-server\n\nDocumentation for the `pip` tool has been moved in to [cmd/grpc-server/README.md](cmd/grpc-server/README.md)\n\n### grpc-client\n\nDocumentation for the `pip` tool has been moved in to [cmd/grpc-client/README.md](cmd/grpc-client/README.md)\n\n## See also\n\n* https://github.com/whosonfirst/go-whosonfirst-spatial\n* https://github.com/whosonfirst/go-whosonfirst-spatial-www\n* https://github.com/whosonfirst/go-whosonfirst-spatial-grpc\n* https://github.com/whosonfirst/go-whosonfirst-database\n* https://github.com/whosonfirst/go-reader\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhosonfirst%2Fgo-whosonfirst-spatial-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhosonfirst%2Fgo-whosonfirst-spatial-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhosonfirst%2Fgo-whosonfirst-spatial-sqlite/lists"}