From 94787d0a7dea3505cb00cebba29c6e306b1e0a4d Mon Sep 17 00:00:00 2001 From: Thomas Petazzoni Date: Mon, 21 Dec 2009 11:55:59 +0100 Subject: [PATCH] Switch the OCitySMap API to an integer for the OSM id Signed-off-by: Thomas Petazzoni --- ocitysmap-render | 10 +++++++--- ocitysmap/street_index.py | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ocitysmap-render b/ocitysmap-render index 5804ff3..ee944eb 100755 --- a/ocitysmap-render +++ b/ocitysmap-render @@ -120,16 +120,20 @@ def main(): sys.stderr.write('ERROR: Invalid city bounding box!\n') return 1 - - if options.city_name: city_name = unicode(options.city_name.decode('utf-8')) else: city_name = None + try: + osmid = int(options.osmid) + except ValueError: + sys.stderr.write('ERROR: Invalid polygon OSM id!\n') + return 1 + try: renderer = OCitySMap(options.config_file, city_name, boundingbox, - options.osmid, options.language) + osmid, options.language) except BaseOCitySMapError, e: sys.stderr.write('ERROR: %s\n' % e) return 1 diff --git a/ocitysmap/street_index.py b/ocitysmap/street_index.py index 7b51697..4235adb 100644 --- a/ocitysmap/street_index.py +++ b/ocitysmap/street_index.py @@ -342,8 +342,8 @@ class OCitySMap: from planet_osm_polygon where boundary='administrative' and admin_level='8' and - osm_id='%s';""" % \ - pgdb.escape_string(osmid)) + osm_id=%d;""" % \ + osmid) records = cursor.fetchall() if not records: raise UnsufficientDataError, "Wrong OSM id!" @@ -425,8 +425,8 @@ class OCitySMap: st_buildarea(way)), 4002)) from planet_osm_polygon where boundary='administrative' - and admin_level='8' and osm_id='%s';""" % \ - pgdb.escape_string(osmid)) + and admin_level='8' and osm_id=%d;""" % \ + osmid) contour = cursor.fetchall() return self.parse_city_contour(contour) @@ -606,7 +606,7 @@ class OCitySMap: from planet_osm_line join map_areas on st_intersects(way, st_transform(geom, 900913)) - left join cities_area_by_osmid on cities_area_by_osmid.osm_id='%s' + left join cities_area_by_osmid on cities_area_by_osmid.osm_id=%d where trim(name) != '' and highway is not null and case when cities_area_by_osmid.area is null then @@ -617,7 +617,7 @@ class OCitySMap: as foo group by name order by name;""" % \ - pgdb.escape_string(osmid)) + osmid) sl = cursor.fetchall()