Ejemplo n.º 1
0
def test_encode_coordinate(config):
    "Test encoding of a coordinate string."

    O.init_osm_factory(config)

    # The following tests assume that the scale factor in use is 10^7.
    _sf = config.getint(C.DATASTORE, C.SCALE_FACTOR)
    assert _sf == 10000000

    #
    # Test encoding of strings.
    #
    inputlist = [
        ('0', 0),  # Zero.
        ('0.00123456', 12345),  # Tiny
        ('0.12345678', 1234567),  # Fraction only
        ('1.23456789', 12345678),  # Normal, small
        ('12.3456789', 123456789),  # Normal
        ('123.456789', 1234567890),  # Normal, large
        ('1', 10000000),  # Integral, small
        ('12', 120000000),  # Integral
        ('123', 1230000000)  # Integral, large
    ]
    for (strval, refval) in inputlist:
        v = O.encode_coordinate(strval)
        assert refval == v

    #
    # Test encoding of floating point values.
    #
    inputlist = [(0.0, 0), (0.123456, 1234560), (0.1234567, 1234567),
                 (1.0, 10000000), (1.23456, 12345600), (12.3455899, 123455899)]
    for (flval, refval) in inputlist:
        v = O.encode_coordinate(flval)
        assert v == refval
Ejemplo n.º 2
0
def test_new_relation(config):
    "Test creation of a <relation> element."

    O.init_osm_factory(config)
    relid = '42'
    r = O.new_osm_element(C.RELATION, relid)

    # Check the "id", MEMBER and REFERENCES attributes.
    assert r.id == str(relid)
    assert r[C.REFERENCES] == set()
    assert r[C.MEMBERS] == []
Ejemplo n.º 3
0
def test_new_way(config):
    "Test creation of a <way> element."

    O.init_osm_factory(config)
    wayid = '42'
    w = O.new_osm_element(C.WAY, wayid)

    # Check the "id", NODES and REFERENCES attributes.
    assert w.id == str(wayid)
    assert w[C.REFERENCES] == set()
    assert w[C.NODES] == set()
def test_new_relation(config):
    "Test creation of a <relation> element."

    O.init_osm_factory(config)
    relid = '42'
    r = O.new_osm_element(C.RELATION, relid)
    
    # Check the "id", MEMBER and REFERENCES attributes. 
    assert r.id == str(relid)
    assert r[C.REFERENCES] == set()
    assert r[C.MEMBERS] == []
def test_new_way(config):
    "Test creation of a <way> element."
    
    O.init_osm_factory(config)
    wayid = '42'
    w = O.new_osm_element(C.WAY, wayid)

    # Check the "id", NODES and REFERENCES attributes.
    assert w.id == str(wayid)
    assert w[C.REFERENCES] == set()
    assert w[C.NODES] == set()
Ejemplo n.º 6
0
def test_new_node(config):
    "Test the creation a <node> element."

    O.init_osm_factory(config)

    nodeid = '42'
    n = O.new_osm_element(C.NODE, nodeid)

    # Check the 'id' field.
    assert n.id == str(nodeid)
    # Check that C.REFERENCES field exists, and is an empty set.
    assert n[C.REFERENCES] == set()
def test_new_node(config):
    "Test the creation a <node> element."

    O.init_osm_factory(config)

    nodeid = '42'
    n = O.new_osm_element(C.NODE, nodeid)

    # Check the 'id' field.
    assert n.id == str(nodeid)
    # Check that C.REFERENCES field exists, and is an empty set.
    assert n[C.REFERENCES] == set()
Ejemplo n.º 8
0
def test_new_geodoc(config):
    "Test the creation of a geodoc element."

    O.init_osm_factory(config)
    georegion = 'szmyg'  # lat, long == 42, 42
    g = O.new_osm_element(C.GEODOC, georegion)

    # Check the "id" field.

    assert g.id == georegion
    assert g[C.NODES] == set()

    bbox = g[C.BBOX]
    assert set(bbox.keys()) == set(['n', 's', 'e', 'w'])
def test_new_geodoc(config):
    "Test the creation of a geodoc element."

    O.init_osm_factory(config)
    georegion = 'szmyg'         # lat, long == 42, 42
    g = O.new_osm_element(C.GEODOC, georegion)

    # Check the "id" field.

    assert g.id == georegion
    assert g[C.NODES] == set()

    bbox = g[C.BBOX]
    assert set(bbox.keys()) == set(['n', 's', 'e', 'w'])
Ejemplo n.º 10
0
def test_encode_coordinate(config):
    "Test encoding of a coordinate string."

    O.init_osm_factory(config)

    # The following tests assume that the scale factor in use is 10^7.
    _sf = config.getint(C.DATASTORE, C.SCALE_FACTOR)
    assert _sf == 10000000

    #
    # Test encoding of strings.
    #
    inputlist = [ ('0', 0),                  # Zero.
                  ('0.00123456',      12345), # Tiny
                  ('0.12345678',    1234567), # Fraction only
                  ('1.23456789',   12345678), # Normal, small
                  ('12.3456789',  123456789), # Normal
                  ('123.456789', 1234567890), # Normal, large
                  ('1',            10000000), # Integral, small
                  ('12',          120000000), # Integral
                  ('123',        1230000000)  # Integral, large
                ]
    for (strval, refval) in inputlist:
        v = O.encode_coordinate(strval)
        assert refval == v


    #
    # Test encoding of floating point values.
    #
    inputlist = [ (0.0, 0),
                  (0.123456,    1234560),
                  (0.1234567,   1234567),
                  (1.0,        10000000),
                  (1.23456,    12345600),
                 (12.3455899, 123455899)
                ]
    for (flval, refval) in inputlist:
        v = O.encode_coordinate(flval)
        assert v == refval
Ejemplo n.º 11
0
    if options.backend:
        cfg.set(C.DATASTORE, C.DATASTORE_BACKEND, options.backend)
    if options.encoding:
        cfg.set(C.DATASTORE, C.DATASTORE_ENCODING, options.encoding)

    # Load the desired interface to the datastore.
    backend = cfg.get(C.DATASTORE, C.DATASTORE_BACKEND)
    try:
        module = __import__('datastore.ds_' + backend, fromlist=['Datastore'])
        datastore = module.Datastore(cfg)
    except ImportError, x:
        error("Could not initialize datastore of type \"%s\": %s" %
              (backend, str(x)))

    # Initialize the OSM element factory.
    init_osm_factory(cfg)

    # Create an instance of the front-end server.
    port = cfg.getint(C.FRONT_END, C.PORT)
    feserver = OSMFrontEndServer(cfg, options, datastore)
    http_server = tornado.httpserver.HTTPServer(feserver.application)
    http_server.listen(port)

    # Start the server.
    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        if options.verbose:
            pass  # Print statistics etc.

Ejemplo n.º 12
0
                     (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]:
            ops.add_element(elem)
        else:
            raise NotImplementedError, "Element type: %s" % elem.kind