def spatialite_connection(conn: Connection) -> Connection:
    conn.enable_load_extension(True)
    par = Parameters()
    spatialite_path = par.parameters["system"]["spatialite_path"]
    if spatialite_path not in os.environ['PATH']:
        os.environ['PATH'] = spatialite_path + ';' + os.environ['PATH']
    try:
        conn.load_extension("mod_spatialite")
    except Exception as e:
        logger.warning(
            f"AequilibraE might not work as intended without spatialite. {e.args}"
        )
    return conn
Esempio n. 2
0
def create_spatialite_db(
        connection: sqlite3.Connection,
        spatialite_binary: Optional[str] = None) -> sqlite3.Connection:

    from string import Template

    connection.enable_load_extension(True)

    platform = {'nt': 'stgeometry_sqlite.dll', 'linux': 'stgeometry_sqlite.so'}
    load_ext = "SELECT load_extension('$platform','SDE_SQL_funcs_init');"

    if os.name == 'nt':
        load_ext_sql = Template(load_ext).substitute(platform=platform['nt'])
        connection.execute(load_ext_sql)
    else:
        load_ext_sql = Template(load_ext).substitute(
            platform=platform['linux'])
        connection.execute(load_ext_sql)
    connection.execute("select CreateOGCTables()")
    return connection
Esempio n. 3
0
def load_extensions(dbapi_connection: sqlite3.Connection, connection_record):
    dbapi_connection.enable_load_extension(True)
    for i in SQLITE_EXTS_PATH.iterdir():
        if i.is_file():
            dbapi_connection.load_extension(str(i.resolve()))
    dbapi_connection.enable_load_extension(False)