]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - lines2kml
3fc3d784d4f60ff70fbd83e0391a806004af318b
4 Export line (road) geometries from the database to Keyhole Markup
5 Language (KML). The exported roads should have both a human-readable
6 name and a globally-unique identifier (gid).
14 # Basically, add '../src' to our path.
15 # Needed for the imports that follow.
16 site
.addsitedir(os
.path
.dirname(os
.path
.abspath(sys
.argv
[0])) + '/../src')
19 import Configuration
.Defaults
25 Parse the command line options. All of these are optional; defaults
26 are provided for the database information and the output is written
30 parser
= CLI
.default_option_parser()
32 # Use this module's docstring as the description.
33 parser
.description
= __doc__
.strip()
35 parser
.add_option('-s',
37 help='The FIPS id of the State whose roads you would like.')
39 (options
, args
) = parser
.parse_args()
42 conn
= pgdb
.connect(host
=options
.host
,
43 database
=options
.database
,
44 user
=options
.username
)
47 # We'll use this cursor for all of our queries.
48 cursor
= conn
.cursor()
50 # If no state is passed on the command line, we want to select the
51 # roads for all states. "... WHERE statefp=statefp ..." will
54 if (options
.state
!= None):
55 # The statefp column is a string, so we need to add single quotes
56 # if we're going to specify it.
57 statefp
= "'%s'" % options
.state
60 SELECT gid, tlid, fullname, ST_AsKml(the_geom)
65 cursor
.execute(lines_query
)
66 rows
= cursor
.fetchall()
70 placemark
= KML
.Placemark()
72 # Name = "Street name (tlid)"
75 if (fullname
== None):
76 # Some streets don't have a fullname.
79 name
= KML
.Name(fullname
+ ' (' + str(row
[1]) + ')')
81 placemark
.children
.append(name
)
82 geometry
= KML
.RawText(row
[3])
83 placemark
.children
.append(geometry
)
84 doc
.children
.append(placemark
)