-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathregiongridder.py
87 lines (66 loc) · 3.23 KB
/
regiongridder.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import sys
import argparse
from loghelper import *
from grid.grid_inventory import GridInventory
from configuration.pathregistry import PathRegistry
from configuration.subregionconfig import SubRegionConfig
from configuration.preprocessorconfig import PreprocessorConfig
from preprocess_tools import postgis_manage
def main():
create_script_log(sys.argv[0])
try:
parser = argparse.ArgumentParser(description="region preprocessor")
parser.add_argument("--pathRegistry", help="path to file registry data")
parser.add_argument("--preprocessorConfig", help=(
"path to preprocessor configuration"))
parser.add_argument("--subRegionConfig", help="path to sub region data")
parser.add_argument("--subRegionNames", help=(
"optional comma delimited string of sub region names (as defined in "
"subRegionConfig) to process, if unspecified all regions will be "
"processed"))
args = parser.parse_args()
pathRegistry = PathRegistry(os.path.abspath(args.pathRegistry))
preprocessorConfig = PreprocessorConfig(os.path.abspath(args.preprocessorConfig),pathRegistry)
subRegionConfig = SubRegionConfig(
os.path.abspath(args.subRegionConfig),
args.subRegionNames.split(",") if args.subRegionNames else None)
logging.info("Run region gridder at resolution {}".format(preprocessorConfig.GetResolution()))
# note that looping through regions will not currently work, table names
# in the postgres db are equivalent for each region.
for r in subRegionConfig.GetRegions():
region_path = r["PathName"]
region_inventory_workspace_filter = r["Inventory_Workspace_Filter"] if "Inventory_Workspace_Filter" in r else None
logging.info(region_path)
root_postgis_var_path = pathRegistry.GetPath(
"PostGIS_Connection_Vars")
region_postgis_var_path = pathRegistry.GetPath(
"PostGIS_Region_Connection_Vars",
region_path=region_path)
db_url = postgis_manage.set_up_working_db(
root_postgis_var_path,
region_postgis_var_path,
[
# load some external postgis functions
pathRegistry.GetPath("ST_Safe_Intersection"),
pathRegistry.GetPath("ST_Safe_Repair")
])
gdal_con = postgis_manage.get_gdal_conn_string(
region_postgis_var_path)
workspace = preprocessorConfig.GetInventoryWorkspace(region_path)
workspaceFilter = preprocessorConfig.GetInventoryFilter(
inventory_workspace_filter=region_inventory_workspace_filter)
gridInventory = GridInventory(preprocessorConfig, db_url)
gridInventory.load_to_postgres(
gdal_con,
workspace,
workspaceFilter)
gridInventory.create_blocks()
gridInventory.create_grid()
gridInventory.grid_inventory()
except Exception as ex:
logging.exception("error")
sys.exit(1)
logging.info("all gridder tasks finished")
if __name__ == "__main__":
main()