def test_geokeys(): "Test geo hash keys returned for various coordinates." init_geohash(_GHKEYLENGTH, _SCALEFACTOR) expected = [ (0.0, 0.0, 's0000'), (89, 0.0, 'upb42'), (89.999999999999992, 0.0, 'upbpb'), # Max lat supported. (-90, 0.0, 'h0000'), (-90, -180, '00000'), (-90, +180, '00000'), (-90, +90, 'n0000'), (-90, -90, '40000'), (-45, -45, '70000'), (-45, 45, 'm0000'), (45, 45, 'v0000'), (45, -45, 'g0000') ] for (lat, lon, ghkey) in expected: elem = new_osm_element(C.NODE, '0') elem[C.LAT] = lat * _SCALEFACTOR elem[C.LON] = lon * _SCALEFACTOR res = geohash_key_for_element(elem) assert res == ghkey
try: module = __import__('datastore.ds_' + backend, fromlist=['Datastore']) except ImportError, x: parser.exit("Error: Could not initialize backend of type \"%s\": %s" % (backend, str(x))) db = module.Datastore(cfg, not options.nothreading, True) if options.doinit: db.initialize() ops = DBOps(cfg, options, db) # Initialize the geohash module. init_geohash(cfg.getint(C.DATASTORE, C.GEOHASH_LENGTH), cfg.getint(C.DATASTORE, C.SCALE_FACTOR)) # Initialize the OSM element factory and related modules. init_slabutil(cfg) init_osm_factory(cfg) # Turn file names into iterators that deliver an element at a time. try: iterlist = map(lambda fn: makesource(cfg, options, fn), args) inputelements = itertools.chain(*iterlist) except Exception, x: parser.exit("Error: " + str(x)) for elem in inputelements: # Add basic elements if elem.namespace in [C.CHANGESET, C.NODE, C.RELATION, C.WAY]:
try: module = __import__('datastore.ds_' + backend, fromlist=['Datastore']) except ImportError, x: parser.exit("Error: Could not initialize backend of type \"%s\": %s" % (backend, str(x))) db = module.Datastore(cfg, not options.nothreading, True) if options.doinit: db.initialize() return ops = DBOps(cfg, options, db) # Initialize the geohash module. init_geohash(cfg.getint(C.DATASTORE, C.GEOHASH_LENGTH), cfg.getint(C.DATASTORE, C.SCALE_FACTOR)) # Initialize the OSM element factory. init_osm_factory(cfg) # Turn file names into iterators that deliver an element at a time. try: iterlist = map(lambda fn: makesource(cfg, options, fn), args) inputelements = itertools.chain(*iterlist) except Exception, x: parser.exit("Error: " + str(x)) for elem in inputelements: # Add basic elements if elem.namespace in [C.CHANGESET, C.NODE, C.RELATION, C.WAY]: ops.add_element(elem)