-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmimport.py
executable file
·140 lines (117 loc) · 4.06 KB
/
tmimport.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/python3
#
# Copyright (C) 2019, 2020 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
## \file tiledb.py manage of collection of map tiles.
# ogr2ogr -t_srs EPSG:4326 Roads-new.shp hwy_road_aerial.shp
import os
import sys
import logging
import psycopg2
from sys import argv
sys.path.append(os.path.dirname(argv[0]) + '/osmpylib')
from poly import Poly
from tm import TM,Project,Info,Task
import getopt
from osgeo import gdal,ogr,osr
class myconfig(object):
def __init__(self, argv=list()):
# Read the config file to get our OSM credentials, if we have any
file = os.getenv('HOME') + "/.gosmrc"
try:
gosmfile = open(file, 'r')
except Exception as inst:
logging.warning("Couldn't open %s for writing! not using OSM credentials" % file)
return
# Default values for user options
self.options = dict()
self.options['logging'] = True
self.options['verbose'] = False
self.options['poly'] = ""
try:
(opts, val) = getopt.getopt(argv[1:], "h,p:,v",
["help", "poly", "verbose"])
except getopt.GetoptError as e:
logging.error('%r' % e)
self.usage(argv)
quit()
for (opt, val) in opts:
if opt == '--help' or opt == '-h':
self.usage(argv)
elif opt == "--poly" or opt == '-p':
self.options['poly'] = val
elif opt == "--verbose" or opt == '-v':
self.options['verbose'] = True
logging.basicConfig(filename='tiler.log',level=logging.DEBUG)
def checkOptions(self):
# make this a nop for now
pass
def get(self, opt):
try:
return self.options[opt]
except Exception as inst:
return False
def dump(self):
logging.info("Dumping config")
for i, j in self.options.items():
print("\t%s: %s" % (i, j))
# Basic help message
def usage(self, argv=["tmimport.py"]):
print("This program reads an OSM poly file, and imports it into the HOT Tasking Manager")
print(argv[0] + ": options:")
print("""\t--help(-h) Help
\t--poly(-p) Input OSM polyfile
\t--verbose(-v) Enable verbosity
""")
quit()
dd = myconfig(argv)
dd.checkOptions()
# dd.dump()
if len(argv) <= 2:
dd.usage(argv)
# The logfile contains multiple runs, so add a useful delimiter
try:
logging.info("-----------------------\nStarting: %r " % argv)
except:
pass
# if verbose, dump to the terminal as well as the logfile.
if dd.get('verbose') == 1:
root = logging.getLogger()
root.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)
tm = TM()
tm.dump()
poly = Poly(dd.get('poly'))
poly.dump()
project = Project()
query = project.create(id=tm.getNextProjectID(), comment="#tm-senecass", polygon=poly)
#project.dump()
print(query)
tm.query(query)
info = Info()
query = info.create("Testy", tm.getNextProjectID())
#info.dump()
print(query)
tm.query(query)
task = Task()
query = task.create(zoom=11, x=419, y=1271, project_id=tm.getNextProjectID(), id=tm.getNextTaskID())
#task.dump()
print(query)
tm.query(query)