Skip to content
This repository was archived by the owner on Dec 13, 2024. It is now read-only.

Commit d5b707d

Browse files
Update to use aaronland/go-sqlite/v2 (#11)
* snapshot: use aaronland/go-sqlite/v2; compiles and passes tests * snapshot: compiles but weird db closed bug to work out * works
1 parent e5b6f3b commit d5b707d

File tree

1,616 files changed

+3714068
-286163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,616 files changed

+3714068
-286163
lines changed

README.md

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,42 @@ go build -mod vendor -o bin/wof-sqlite-index-features cmd/wof-sqlite-index-featu
2121

2222
```
2323
$> ./bin/wof-sqlite-index-features -h
24-
Usage of ./bin/wof-sqlite-index-features:
2524
-all
2625
Index all tables (except the 'search' and 'geometries' tables which you need to specify explicitly)
2726
-ancestors
2827
Index the 'ancestors' tables
2928
-concordances
3029
Index the 'concordances' tables
31-
-driver string
32-
(default "sqlite3")
33-
-dsn string
34-
(default ":memory:")
30+
-database-uri string
31+
(default "modernc://mem")
3532
-geojson
3633
Index the 'geojson' table
3734
-geometries
3835
Index the 'geometries' table (requires that libspatialite already be installed)
39-
-geometry
40-
Index the 'geometry' table
4136
-index-alt-files
4237
Index alt geometries
4338
-index-relations
4439
Index the records related to a feature, specifically wof:belongsto, wof:depicts and wof:involves. Alt files for relations are not indexed at this time.
4540
-index-relations-reader-uri string
4641
A valid go-reader.Reader URI from which to read data for a relations candidate.
4742
-iterator-uri string
48-
A valid whosonfirst/go-whosonfirst-iterate/emitter URI. Supported emitter URI schemes are: directory://,featurecollection://,file://,filelist://,geojsonl://,git://,repo:// (default "repo://")
43+
A valid whosonfirst/go-whosonfirst-iterate/v2 URI. Supported emitter URI schemes are: directory://,featurecollection://,file://,filelist://,geojsonl://,git://,null://,repo:// (default "repo://")
4944
-live-hard-die-fast
5045
Enable various performance-related pragmas at the expense of possible (unlikely) database corruption (default true)
51-
-mode string
52-
A valid whosonfirst/go-whosonfirst-iterate/emitter URI. Supported emitter URI schemes are: directory://,featurecollection://,file://,filelist://,geojsonl://,git://,repo://. THIS FLAG IS DEPRECATED, please use -iterator-uri instead. (default "repo://")
5346
-names
5447
Index the 'names' table
5548
-optimize
5649
Attempt to optimize the database before closing connection (default true)
5750
-processes int
58-
The number of concurrent processes to index data with (default 16)
51+
The number of concurrent processes to index data with (default 8)
5952
-properties
6053
Index the 'properties' table
6154
-rtree
6255
Index the 'rtree' table
6356
-search
6457
Index the 'search' table (using SQLite FTS4 full-text indexer)
58+
-spatial-tables
59+
If true then index the necessary tables for use with the whosonfirst/go-whosonfirst-spatial-sqlite package.
6560
-spr
6661
Index the 'spr' table
6762
-strict-alt-files
@@ -76,7 +71,7 @@ For example:
7671

7772
```
7873
$> ./bin/wof-sqlite-index-features \
79-
-dsn microhoods.db \
74+
-database-uri modernc://cwd/microhoods.db \
8075
-all \
8176
-iterator-uri 'repo://?include=properties.wof:placetype=microhood' \
8277
/usr/local/data/whosonfirst-data-admin-us
@@ -104,7 +99,7 @@ do
10499
rm /usr/local/data/whosonfirst-sqlite/${FNAME}.db
105100
fi
106101
107-
./bin/wof-sqlite-index-features -timings -all -dsn /usr/local/data/whosonfirst-sqlite/${FNAME}-latest.db -mode repo:// ${REPO}
102+
./bin/wof-sqlite-index-features -timings -all -database-uri modernc:///usr/local/data/whosonfirst-sqlite/${FNAME}-latest.db -iterator-uri repo:// ${REPO}
108103
109104
done
110105
```
@@ -124,7 +119,7 @@ For example:
124119
```
125120
$> ./bin/wof-sqlite-index-features \
126121
-all \
127-
-dsn ca-region.db \
122+
-database-uri modernc://cwd/ca-region.db \
128123
-iterator-uri 'repo://?include=properties.wof:placetype=region' \
129124
/usr/local/data/whosonfirst-data-admin-ca
130125
@@ -153,7 +148,7 @@ You can pass multiple query parameters. For example:
153148
```
154149
$> ./bin/wof-sqlite-index-features \
155150
-all \
156-
-dsn ca-region.db \
151+
-database-uri modernc://cwd/ca-region.db \
157152
-iterator-uri 'repo://?include=properties.wof:placetype=region&include=properties.wof:name=(?i)new.*' \
158153
/usr/local/data/whosonfirst-data-admin-ca
159154
@@ -187,63 +182,10 @@ $> ./bin/wof-sqlite-index-features \
187182
-spr \
188183
-properties \
189184
-timings \
190-
-dsn /usr/local/ca-alt.db \
185+
-database-uri modernc:///usr/local/ca-alt.db \
191186
/usr/local/data/whosonfirst-data-admin-ca/
192187
```
193188

194-
### Spatialite
195-
196-
Spatial indexes are also available if you have the [Spatialite extension](https://www.gaia-gis.it/fossil/libspatialite/index) installed and have indexed the `geometries` table. For example:
197-
198-
```
199-
$> ./bin/wof-sqlite-index-features \
200-
-driver spatialite \
201-
-timings \
202-
-spr \
203-
-geometries \
204-
-dsn test.db /usr/local/data/whosonfirst-data-constituency-ca/
205-
206-
10:09:46.534281 [wof-sqlite-index-features] STATUS time to index geometries (87) : 21.251828704s
207-
10:09:46.534379 [wof-sqlite-index-features] STATUS time to index spr (87) : 3.206930799s
208-
10:09:46.534385 [wof-sqlite-index-features] STATUS time to index all (87) : 24.48004637s
209-
210-
$> sqlite3 test.db
211-
SQLite version 3.21.0 2017-10-24 18:55:49
212-
Enter ".help" for usage hints.
213-
214-
sqlite> SELECT load_extension('mod_spatialite.dylib');
215-
sqlite> SELECT s.id, s.name FROM spr s, geometries g WHERE ST_Intersects(g.geom, GeomFromText('POINT(-122.229137 49.450129)', 4326)) AND g.id = s.id;
216-
1108962831|Maple Ridge-Pitt Meadows
217-
```
218-
219-
Or:
220-
221-
```
222-
> spatialite whosonfirst-data-latest.db
223-
SpatiaLite version ..: 4.1.1 Supported Extensions:
224-
...spatialite chatter goes here...
225-
SQLite version 3.8.2 2013-12-06 14:53:30
226-
Enter ".help" for instructions
227-
Enter SQL statements terminated with a ";
228-
229-
spatialite> SELECT s.id, s.name FROM spr AS s, geometries AS g1, geometries AS g2 WHERE g1.id = 85834637 AND s.placetype = 'neighbourhood' AND g2.id = s.id AND ST_Touches(g1.geom, g2.geom) AND g2.ROWID IN (SELECT ROWID FROM SpatialIndex WHERE f_table_name = 'geometries' AND search_frame=g2.geom);
230-
102112179|La Lengua
231-
1108831803|Showplace Square
232-
233-
spatialite> SELECT s.id, s.name FROM spr AS s, geometries AS g1, geometries AS g2 WHERE g1.id != g2.id AND g1.id = 85865959 AND s.placetype = 'neighbourhood' AND s.is_current=1 AND g2.id = s.id AND (ST_Touches(g1.geom, g2.geom) OR ST_Intersects(g1.geom, g2.geom)) AND g2.ROWID IN (SELECT ROWID FROM SpatialIndex WHERE f_table_name = 'geometries' AND search_frame=g2.geom);
234-
1108831807|Fairmount
235-
85814471|Diamond Heights
236-
85869221|Eureka Valley
237-
238-
SELECT s.id, s.name, s.is_current FROM spr AS s, geometries AS g1, geometries AS g2 WHERE g1.id != g2.id AND g1.id = 102061079 AND s.placetype = 'neighbourhood' AND g2.id = s.id AND (ST_Touches(g1.geom, g2.geom) OR ST_Intersects(g1.geom, g2.geom)) AND g2.ROWID IN (SELECT ROWID FROM SpatialIndex WHERE f_table_name = 'geometries' AND search_frame=g2.geom);
239-
85892915|BoCoCa|0
240-
85869125|Boerum Hill|1
241-
420782915|Carroll Gardens|1
242-
85865587|Gowanus|1
243-
```
244-
245-
_Remember: When indexing geometries you will need to explcitly pass both the `-geometries` and `-driver spatialite` flags, even if you are already passing in the `-all` flag. This is so `-all` will continue to work as expected for people who don't have Spatialite installed on their computer._
246-
247189
## Indexing
248190

249191
Indexing time will vary depending on the specifics of your hardware (available RAM, CPU, disk I/O) but as a rule building indexes with the `geometries` table will take longer, and create a larger database, than doing so without. For example indexing the [whosonfirst-data](https://github.com/whosonfirst-data/whosonfirst-data) repository with spatial indexes:
@@ -253,7 +195,7 @@ $> ./bin/wof-sqlite-index-features \
253195
-driver spatialite \
254196
-all \
255197
-geometries \
256-
-dsn /usr/local/data/dist/sqlite/whosonfirst-data-latest.db \
198+
-database-uri modernc:///usr/local/data/dist/sqlite/whosonfirst-data-latest.db \
257199
-timings \
258200
/usr/local/data/whosonfirst-data
259201
@@ -275,7 +217,7 @@ And without:
275217
```
276218
$> ./bin/wof-sqlite-index-features \
277219
-all \
278-
-dsn /usr/local/data/dist/sqlite/whosonfirst-data-latest-nospatial.db \
220+
-database-uri modernc:///usr/local/data/dist/sqlite/whosonfirst-data-latest-nospatial.db \
279221
-timings \
280222
/usr/local/data/whosonfirst-data
281223
...time passes...
@@ -295,6 +237,7 @@ As of this writing individual tables are indexed atomically. There may be some i
295237
## See also
296238

297239
* https://github.com/aaronland/go-sqlite
240+
* https://github.com/aaronland/go-sqlite-modernc
298241
* https://github.com/whosonfirst/go-whosonfirst-sqlite-features
299242
* https://github.com/whosonfirst/go-whosonfirst-sqlite-index
300-
* https://github.com/whosonfirst/go-whosonfirst-iterate/v2
243+
* https://github.com/whosonfirst/go-whosonfirst-iterate

0 commit comments

Comments
 (0)