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

--load-extension=spatialite shortcut option #136

Closed
simonw opened this issue Aug 21, 2020 · 3 comments
Closed

--load-extension=spatialite shortcut option #136

simonw opened this issue Aug 21, 2020 · 3 comments
Labels

Comments

@simonw
Copy link
Owner

simonw commented Aug 21, 2020

In conjunction with #135 - this would do the same thing as --load-extension=path-to-spatialite (see #134)

@simonw simonw added the enhancement New feature or request label Aug 21, 2020
@simonw
Copy link
Owner Author

simonw commented Aug 21, 2020

I think this should initialize SpatiaLite against the current database if it has not been initialized already.

Relevant code: https://github.com/simonw/shapefile-to-sqlite/blob/e754d0747ca2facf9a7433e2d5d15a6a37a9cf6e/shapefile_to_sqlite/utils.py#L112-L126

def init_spatialite(db, lib):
    db.conn.enable_load_extension(True)
    db.conn.load_extension(lib)
    # Initialize SpatiaLite if not yet initialized
    if "spatial_ref_sys" in db.table_names():
        return
    db.conn.execute("select InitSpatialMetadata(1)")


def ensure_table_has_geometry(db, table, table_srid):
    if "geometry" not in db[table].columns_dict:
        db.conn.execute(
            "SELECT AddGeometryColumn(?, 'geometry', ?, 'GEOMETRY', 2);",
            [table, table_srid],
        )

Not sure if I should add a utility function or CLI command for that ensure_table_has_geometry bit.

@simonw
Copy link
Owner Author

simonw commented Aug 21, 2020

The --spatialite option should be available for other useful commands too, refs #137.

@simonw
Copy link
Owner Author

simonw commented Oct 16, 2020

To keep the code cleaner, I'm tempted to support this instead:

--load-extension=spatialite

Where spatialite is a special shortcut value that triggers a search for that module in known locations.

Users could still load a module in a file called spatialite in the current directory using:

--load-extension=./spatialite

In fact, --load-extension=spatialite could handle that case too by always checking for a file called spatialite before attempting to search for it in known locations.

@simonw simonw changed the title --spatialite option for sqlite-utils query --load-extension=spatialite shortcut option Oct 16, 2020
@simonw simonw closed this as completed in 21ff60e Oct 16, 2020
simonw added a commit that referenced this issue Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant