Truncate option for import points script.

This commit is contained in:
Lev Dragunov 2015-11-09 12:10:46 +03:00
parent 1a8e92d24d
commit a2d358ed41

View file

@ -8,21 +8,22 @@ def parse_double_points(line):
words = line.split()
lat = words[9].split("(")[1][:-1]
lon = words[10].split(")")[0]
return float(lat), float(lon), 1
return float(lon), float(lat), 1
def parse_unknown_outgoing(line):
if "Unknowing" in line:
words = line.split()
lat = words[9]
lon = words[10]
return float(lat), float(lon), 2
return float(lon), float(lat), 2
filters = (parse_double_points, parse_unknown_outgoing)
parser = argparse.ArgumentParser(description='Extract borders warning points from generator log files to databse.')
parser.add_argument('-s', '--source', help='Generator log file path.')
parser.add_argument('-c', '--connection', help='Database connection string.')
parser.add_argument('-v', dest='verbose', action='store_true', help='Print status messages')
parser.add_argument('-t', '--truncate', action='store_true', help='Truncate old data. WARINIG old data will be lost!')
parser.add_argument('-v', dest='verbose', action='store_true', help='Print status messages.')
options = parser.parse_args()
# Check log file for existance.
@ -49,6 +50,11 @@ print "There are {} points with no external mwm, and {} points if features that
# Commit to the database
conn = psycopg2.connect(options.connection)
cursor = conn.cursor()
if options.truncate:
print "Truncating old data..."
cursor.execute("TRUNCATE TABLE points")
cursor.execute("INSERT into points (geom, type) VALUES {}".format(",".
join(["(ST_GeomFromText('POINT({} {})', 4326), {})".format(*p) for p in points])))
conn.commit()