Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--spatialite bug: AddGeometryColumn() error: table X does not exist #6

Closed
simonw opened this issue Jan 31, 2020 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Jan 31, 2020

Try this:

curl -s https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_040_00_20m.json \
    | geojson-to-sqlite my.db states - --pk GEO_ID --spatialite

It throws this error:

InitSpatiaMetaData() error:"table spatial_ref_sys already exists"
@simonw simonw added the bug Something isn't working label Jan 31, 2020
@simonw
Copy link
Owner Author

simonw commented Jan 31, 2020

This time it threw this one:

AddGeometryColumn() error: table 'states' does not exist

That's because at the time we attempt to run this code the table may not have been created by a row insertion:

ensure_table_has_geometry(db, table)

simonw added a commit that referenced this issue Jan 31, 2020
@simonw
Copy link
Owner Author

simonw commented Jan 31, 2020

Not sure what to do about the AddGeometryColumn() error. Maybe sqlite-utils needs a mechanism for "after first creating the table, run this additional function"?

@simonw simonw changed the title --spatialite option doesn't work yet --spatialite bug: AddGeometryColumn() error: table X does not exist Jan 31, 2020
@simonw
Copy link
Owner Author

simonw commented Jan 31, 2020

A failing test would be good here.

@simonw
Copy link
Owner Author

simonw commented Jan 31, 2020

Thinking about this further, I don't think that on_create hook is the right fix.

When creating the table we need to avoid creating a "geometry" column, because we're going to instead create that using the AddGeometryColumn function.

As such, sqlite-util's default of creating the table automatically based on the initial dictionary may not be the right thing to do.

Needs more thought.

@simonw
Copy link
Owner Author

simonw commented Jan 31, 2020

I can use this method to detect the column types from the records:

https://github.com/simonw/sqlite-utils/blob/e8b2b7383bd94659d3b7a857a1414328bc48bc19/sqlite_utils/db.py#L823-L845

Then manually create the table minus the "geometry" column, then add that column afterwards.

@simonw
Copy link
Owner Author

simonw commented Jan 31, 2020

Got the command from the first comment to work!

my__select_rowid__GEO_ID__STATE__NAME__LSAD__CENSUSAREA__AsGeoJSON_geometry__from_states_order_by_rowid_limit_101

@simonw simonw closed this as completed in aad086d Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant