Open simonw opened 2 years ago
Here's why:
Since geometry
is added later the call to db[table].create(column_types, pk=pk)
has an empty column_types
dictionary.
Really hard to know what to do about this one - the GeoJSON object here really is just a geometry with nothing else. There's not even an ID that can be used as a primary key.
So we really want to create a SQLite table with just a rowid
. Is that even possible?
https://stackoverflow.com/a/36926664/6083 suggests using this:
CREATE TABLE tablename (rowid INTEGER PRIMARY KEY) WITHOUT ROWID;
That makes me a little bit nervous, see https://www.sqlite.org/withoutrowid.html - it's not clear to me if this kind of "fake" rowid table will cause weird problems in the future, especially if I start using tricks like this one: https://til.simonwillison.net/sqlite/track-timestamped-changes-to-a-table
I'm tempted to create a id
column that is primary key integer and hence will auto-increment.
I think the safest thing to do here would be to create the table with a _temp
column, add the geometry column and then drop that _temp
column.
Fixed it! Here's that GeoJSON imported and rendered using https://datasette.io/plugins/datasette-geojson-map
I think I spotted a bug: https://github.com/simonw/geojson-to-sqlite/blob/23bdb74f857b067fbddbc924fd27b64d3441a46c/geojson_to_sqlite/utils.py#L70-L77
remove_tmp_column
is never switched to True
.
https://raw.githubusercontent.com/datanews/amtrak-geojson/master/amtrak-combined.geojson
Has a feature like this:
This fails with an error if you use the
--spatialite
option: