+ assert_in(key, ('class', 'type', 'street', 'addr_place',
+ 'isin', 'postcode'))
+ self.columns[key] = value
+
+ def set_key_name(self, value):
+ self.add_hstore('name', 'name', value)
+
+ def set_key_osm(self, value):
+ assert_in(value[0], 'NRW')
+ ok_(value[1:].isdigit())
+
+ self.columns['osm_type'] = value[0]
+ self.columns['osm_id'] = int(value[1:])
+
+ def set_key_admin(self, value):
+ self.columns['admin_level'] = int(value)
+
+ def set_key_housenr(self, value):
+ self.columns['housenumber'] = value
+
+ def set_key_cc(self, value):
+ ok_(len(value) == 2)
+ self.columns['country_code'] = value
+
+ def set_key_geometry(self, value):
+ geom, precision = self.context.osm.parse_geometry(value, self.context.scene)
+ assert_is_not_none(geom)
+ self.geometry = "ST_SetSRID('%s'::geometry, 4326)" % geom
+
+ def add_hstore(self, column, key, value):
+ if column in self.columns:
+ self.columns[column][key] = value
+ else:
+ self.columns[column] = { key : value }
+
+ def db_insert(self, cursor):
+ assert_in('osm_type', self.columns)
+ if self.force_name and 'name' not in self.columns:
+ self.add_hstore('name', 'name', ''.join(random.choice(string.printable)
+ for _ in range(int(random.random()*30))))
+
+ if self.columns['osm_type'] == 'N' and self.geometry is None:
+ self.geometry = "ST_SetSRID(ST_Point(%f, %f), 4326)" % (
+ random.random()*360 - 180, random.random()*180 - 90)