File: new_style.py

package info (click to toggle)
mkgmap 0.0.0%2Bsvn4905-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,032 kB
  • sloc: java: 73,856; xml: 1,695; python: 713; sh: 240; makefile: 149; perl: 31
file content (77 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download | duplicates (8)
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
#
# File: p.py
# 
# Copyright (C) 2006 Steve Ratcliffe
# 
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2 as
#  published by the Free Software Foundation.
# 
#  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.
# 
# 
# Author: Steve Ratcliffe
# Create date: 31 Dec 2006
#

#
# Create the new style files points, lines and polygons from a map-features file.
#

import sys
import csv

MAP_FEATURES = 'map-features.csv'

if len(sys.argv) > 1:
	MAP_FEATURES = sys.argv[1]

points = []
lines = []
polygons = []

features = {
		'polyline': lines,
		'polygon': polygons,
		'point': points,
	}
file_names = {
		'polyline': 'lines',
		'polygon': 'polygons',
		'point': 'points',
	}

def main():

	# Read the garmin feature name to internal number file
	f = open(MAP_FEATURES)
	r = csv.reader(f, delimiter='|')
	for line in r:
		kind = line[0]
		if kind[0] == '#': continue
		key = line[1] + '=' + line[2]
		value = makeval(line[3], line[4])
		res = int(line[5])

		line = "%s [%s resolution %d]" % (key, value, res)
		ft = features[kind]
		ft.append(line)


	# Write out the files
	for name in features.keys():
		f = open(file_names[name], 'w')
		ft = features[name]
		for line in ft:
			f.write(line)
			f.write("\n")

def makeval(a, b):
	if not b: return a
	return a + b[2:]

if __name__ == '__main__':
	main()