forked from stuporglue/solar_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDatabaseTables.py
executable file
·57 lines (47 loc) · 1.83 KB
/
createDatabaseTables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os,dbconn
from config import *
schema = config.get('postgres','schema')
sqls = []
sqls.append("""
CREATE TABLE """ + schema + "." + config.get('postgres','dem_fishnet_table') + """
(
id serial,
the_geom geometry(Polygon,""" + config.get('projection','srid') + """),
state integer DEFAULT 0,
CONSTRAINT dem_fishnets_pkey PRIMARY KEY (id)
) WITH (OIDS=FALSE)
""")
sqls.append("CREATE INDEX dem_gist ON " + schema + "." + config.get('postgres','dem_fishnet_table') + " USING gist (the_geom)")
sqls.append("CREATE INDEX dem_state_index ON " + schema + "." + config.get('postgres','dem_fishnet_table') + " USING btree (state)")
sqls.append("""
CREATE TABLE """ + schema + "." + config.get('postgres','lidar_bbox_table') + """
(
id serial,
lasfile character varying,
the_geom geometry(Polygon,""" + config.get('projection','srid') + """),
CONSTRAINT lidar_bbox_pkey PRIMARY KEY (id),
CONSTRAINT lidar_bbox_unique_file UNIQUE (lasfile)
) WITH (OIDS=FALSE)
""")
sqls.append("CREATE INDEX bbox_gist ON " + schema + "." + config.get('postgres','lidar_bbox_table') + " USING gist (the_geom)")
sqls.append("""
CREATE TABLE """ + schema + "." + config.get('postgres','sa_fishnet_table') + """
(
id serial,
the_geom geometry(Polygon,""" + config.get('projection','srid') + """),
state integer DEFAULT 0,
"time" double precision,
CONSTRAINT sa_fish2_pkey PRIMARY KEY (id)
) WITH (OIDS=FALSE)
""")
sqls.append("CREATE INDEX sa_fish2_geom_gist ON " + schema + "." + config.get('postgres','sa_fishnet_table') + " USING gist (the_geom)")
sqls.append("CREATE INDEX sa_fishnet_state ON " + schema + "." + config.get('postgres','sa_fishnet_table') + " USING btree (state)")
for sql in sqls:
print sql
print ""
if not dbconn.run_query(sql):
print "ERROR!"
exit()
print "Done!"