fix: 补全楼宇图层工程坐标系和数据元信息
This commit is contained in:
+11
-1
@@ -62,6 +62,8 @@ def build_gpkg(data_csv, polygon_csv, output_path):
|
||||
if output_path.exists(): output_path.unlink()
|
||||
conn=sqlite3.connect(output_path)
|
||||
try:
|
||||
conn.execute("pragma application_id = 1196444487")
|
||||
conn.execute("pragma user_version = 10400")
|
||||
conn.executescript("""CREATE TABLE gpkg_spatial_ref_sys (srs_name TEXT NOT NULL, srs_id INTEGER PRIMARY KEY, organization TEXT NOT NULL, organization_coordsys_id INTEGER NOT NULL, definition TEXT NOT NULL, description TEXT); CREATE TABLE gpkg_contents (table_name TEXT PRIMARY KEY, data_type TEXT NOT NULL, identifier TEXT UNIQUE, description TEXT DEFAULT '', last_change DATETIME NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')), min_x DOUBLE, min_y DOUBLE, max_x DOUBLE, max_y DOUBLE, srs_id INTEGER); CREATE TABLE gpkg_geometry_columns (table_name TEXT PRIMARY KEY, column_name TEXT NOT NULL, geometry_type_name TEXT NOT NULL, srs_id INTEGER NOT NULL, z TINYINT NOT NULL, m TINYINT NOT NULL);""")
|
||||
crs = CRS84
|
||||
building_info = Path(__file__).resolve().parents[1] / "source" / "BuildingInfo.gpkg"
|
||||
@@ -71,10 +73,18 @@ def build_gpkg(data_csv, polygon_csv, output_path):
|
||||
"select srs_name, srs_id, organization, organization_coordsys_id, definition, description "
|
||||
"from gpkg_spatial_ref_sys where srs_id = ?", (SRS_ID,),
|
||||
).fetchone() or CRS84
|
||||
conn.execute("insert into gpkg_spatial_ref_sys values (?,?,?,?,?,?)", crs)
|
||||
conn.executemany("insert into gpkg_spatial_ref_sys values (?,?,?,?,?,?)", [
|
||||
("Undefined Cartesian SRS", -1, "NONE", -1, "undefined", "undefined Cartesian coordinate reference system"),
|
||||
("Undefined geographic SRS", 0, "NONE", 0, "undefined", "undefined geographic coordinate reference system"),
|
||||
crs,
|
||||
])
|
||||
esc=lambda x:'"'+x.replace('"','""')+'"'
|
||||
conn.execute(f'CREATE TABLE {esc(LAYER_NAME)} (fid INTEGER PRIMARY KEY AUTOINCREMENT, '+', '.join(esc(x)+' TEXT' for x in fields)+f', {esc(GEOM_COLUMN)} BLOB NOT NULL)')
|
||||
conn.execute('CREATE VIRTUAL TABLE rtree_NRBuildingsData_geom USING rtree(id,minx,maxx,miny,maxy)')
|
||||
conn.execute('CREATE TABLE gpkg_ogr_contents (table_name TEXT PRIMARY KEY, feature_count INTEGER)')
|
||||
conn.execute('CREATE TABLE gpkg_extensions (table_name TEXT, column_name TEXT, extension_name TEXT NOT NULL, definition TEXT NOT NULL, scope TEXT NOT NULL, CONSTRAINT ge_tce UNIQUE (table_name, column_name, extension_name))')
|
||||
conn.execute('INSERT INTO gpkg_ogr_contents VALUES (?,?)', (LAYER_NAME, len(rows)))
|
||||
conn.execute('INSERT INTO gpkg_extensions VALUES (?,?,?,?,?)', (LAYER_NAME, GEOM_COLUMN, 'gpkg_rtree_index', 'http://www.geopackage.org/spec120/#extension_rtree', 'write-only'))
|
||||
conn.execute('INSERT INTO gpkg_contents(table_name,data_type,identifier,srs_id) VALUES (?,?,?,?)',(LAYER_NAME,'features',LAYER_NAME,SRS_ID))
|
||||
conn.execute('INSERT INTO gpkg_geometry_columns VALUES (?,?,?,?,?,?)',(LAYER_NAME,GEOM_COLUMN,'MULTIPOLYGON',SRS_ID,0,0))
|
||||
cols=','.join(esc(x) for x in fields)
|
||||
|
||||
Reference in New Issue
Block a user