-
Notifications
You must be signed in to change notification settings - Fork 0
/
shp2map.py
executable file
·95 lines (80 loc) · 2.61 KB
/
shp2map.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
#!/usr/bin/python3
#
# Copyright (C) 2017, 2018, 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
#
# To change the SRID to something more standard
# ogr2ogr -f "ESRI Shapefile" RoadCenterlines-new.shp RoadCenterlines.shp -t_srs "EPSG:4326"
import os
import sys
import logging
from sys import argv
sys.path.append(os.path.dirname(argv[0]) + '/osmpylib')
import osm
import shp
import config
import string
dd = config.config(argv)
dd.dump()
# The logfile contains multiple runs, so add a useful delimiter
logging.info("-----------------------\nStarting: %r " % argv)
# 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)
# Enable to make it easy to set breakpoints in pdb when debugging
# import pdb; pdb.set_trace()
# Read Shape (ERSI) file
shp = shp.shpfile(dd)
if dd.get('infile') == "":
usage()
quit()
else:
infile = dd.get('infile')
shp.open(infile)
if dd.get('dump') is True:
shp.dump()
quit()
# Write KML file
# if dd.get('format') == 'kml':
# if dd.get('outfile') == "":
# kmlfile = '/tmp/tmp.kml'
# else:
# kmlfile = dd.get('outfile')
# kml = kml.kmlfile()
# kml.open(kmlfile)
# shp.makeKML(osm)
# Write OSM file
elif dd.get('format') == "osm":
outdir = dd.get('outdir')
osmfile = dd.get('outfile')
osm = osm.osmfile(dd, osmfile)
shp.makeOSM(osm)
print("Output file: %r" % osmfile)
# Write CSV file
elif dd.get('format') == "csv":
if dd.get('outfile') == "":
csvfile = "/tmp/tmp.csv"
else:
csvfile = dd.get('outfile')
csv = csv.osmfile(dd)
csv.open(csvfile, shp)
shp.makeCSV(csv)
print("Output file: %r" % csvfile)