File: build_small_spatialite_db.py

package info (click to toggle)
datasette 0.65.2-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 4,260 kB
  • sloc: python: 28,661; javascript: 10,089; sh: 71; makefile: 47; ansic: 26
file content (23 lines) | stat: -rw-r--r-- 796 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sqlite3

# This script generates the spatialite.db file in our tests directory.


def generate_it(filename):
    conn = sqlite3.connect(filename)
    # Lead the spatialite extension:
    conn.enable_load_extension(True)
    conn.load_extension("/usr/local/lib/mod_spatialite.dylib")
    conn.execute("select InitSpatialMetadata(1)")
    conn.executescript("create table museums (name text)")
    conn.execute("SELECT AddGeometryColumn('museums', 'point_geom', 4326, 'POINT', 2);")
    # At this point it is around 5MB - we can shrink it dramatically by doing thisO
    conn.execute("delete from spatial_ref_sys")
    conn.execute("delete from spatial_ref_sys_aux")
    conn.commit()
    conn.execute("vacuum")
    conn.close()


if __name__ == "__main__":
    generate_it("spatialite.db")