def count_feature(mwm_path, feature_name):
    mwm = MWM(open(mwm_path, 'rb'))
    mwm.read_header()
    mwm.read_types(os.path.join(OMIM_ROOT, 'data', 'types.txt'))
    counter = 0
    for feature in mwm.iter_features():
        if feature_name in feature['header']['types']:
            counter += 1
    return counter
Example #2
0
def count_feature(mwm_path, feature_name):
    mwm = MWM(open(mwm_path, 'rb'))
    mwm.read_header()
    mwm.read_types(os.path.join(OMIM_ROOT, 'data', 'types.txt'))
    counter = 0
    for feature in mwm.iter_features():
        if feature_name in feature['header']['types']:
            counter += 1
    return counter
Example #3
0
    print("Usage: {0} <country.mwm>".format(sys.argv[0]))
    sys.exit(1)

mwm = MWM(open(sys.argv[1], "rb"))
mwm.read_types(os.path.join(os.path.dirname(sys.argv[0]), "..", "..", "..", "data", "types.txt"))
print("Tags:")
tvv = sorted([(k, v[0], v[1]) for k, v in mwm.tags.items()], key=lambda x: x[1])
for tv in tvv:
    print("  {0:<8}: offs {1:9} len {2:8}".format(tv[0], tv[1], tv[2]))
v = mwm.read_version()
print("Format: {0}, version: {1}".format(v["fmt"], v["version"].strftime("%Y-%m-%d %H:%M")))
print("Header: {0}".format(mwm.read_header()))
print("Metadata count: {0}".format(len(mwm.read_metadata())))

cross = mwm.read_crossmwm()
if cross:
    print("Outgoing points: {0}, incoming: {1}".format(len(cross["out"]), len(cross["in"])))
    print("Outgoing regions: {0}".format(set(cross["neighbours"])))

print("Sample features:")
# Print some random features using reservoir sampling
count = 5
sample = []
for i, feature in enumerate(mwm.iter_features()):
    if i < count:
        sample.append(feature)
    elif random.randint(0, i) < count:
        sample[random.randint(0, count - 1)] = feature
for feature in sample:
    print(json.dumps(feature, ensure_ascii=False))
Example #4
0
    print('  t for inside types ("t hwtag" will find all hwtags-*)')
    print('  et for exact type ("et shop" won\'t find shop-chemist)')
    print('  n for names, case-sensitive ("n Starbucks" for all starbucks)')
    print('  m for metadata keys ("m flats" for features with flats)')
    print('  id for feature id ("id 1234" for feature #1234)')
    sys.exit(1)

typ = sys.argv[2].lower()
find = sys.argv[3].decode('utf-8')

mwm = MWM(open(sys.argv[1], 'rb'))
mwm.read_header()
mwm.read_types(
    os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', 'data',
                 'types.txt'))
for i, feature in enumerate(mwm.iter_features(metadata=True)):
    found = False
    if typ == 'n' and 'name' in feature['header']:
        for value in feature['header']['name'].values():
            if find in value:
                found = True
    elif typ in ('t', 'et'):
        for t in feature['header']['types']:
            if t == find:
                found = True
            elif typ == 't' and find in t:
                found = True
    elif typ == 'm' and 'metadata' in feature:
        if find in feature['metadata']:
            found = True
    elif typ == 'id' and i == int(find):
Example #5
0
tvv = sorted([(k, v[0], v[1]) for k, v in mwm.tags.items()],
             key=lambda x: x[1])
for tv in tvv:
    print('  {0:<8}: offs {1:9} len {2:8}'.format(tv[0], tv[1], tv[2]))
v = mwm.read_version()
print('Format: {0}, version: {1}'.format(v['fmt'],
                                         v['date'].strftime('%Y-%m-%d %H:%M')))
print('Header: {0}'.format(mwm.read_header()))
print('Region Info: {0}'.format(mwm.read_region_info()))
print('Metadata count: {0}'.format(len(mwm.read_metadata())))

cross = mwm.read_crossmwm()
if cross:
    print('Outgoing points: {0}, incoming: {1}'.format(len(cross['out']),
                                                       len(cross['in'])))
    print('Outgoing regions: {0}'.format(set(cross['neighbours'])))

# Print some random features using reservoir sampling
count = 5
sample = []
for i, feature in enumerate(mwm.iter_features()):
    if i < count:
        sample.append(feature)
    elif random.randint(0, i) < count:
        sample[random.randint(0, count - 1)] = feature

print('Feature count: {0}'.format(i))
print('Sample features:')
for feature in sample:
    print(json.dumps(feature, ensure_ascii=False))
Example #6
0
    print('Usage: {0} <country.mwm> <type> <string>'.format(sys.argv[0]))
    print('')
    print('Type:')
    print('  t for inside types ("t hwtag" will find all hwtags-*)')
    print('  et for exact type ("et shop" won\'t find shop-chemist)')
    print('  n for names, case-sensitive ("n Starbucks" for all starbucks)')
    sys.exit(1)

typ = sys.argv[2].lower()
find = sys.argv[3].decode('utf-8')

mwm = MWM(open(sys.argv[1], 'rb'))
mwm.read_header()
mwm.read_types(
    os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', 'data',
                 'types.txt'))
for feature in mwm.iter_features():
    found = False
    if typ == 'n' and 'name' in feature['header']:
        for value in feature['header']['name'].values():
            if find in value:
                found = True
    elif typ in ('t', 'et'):
        for t in feature['header']['types']:
            if t == find:
                found = True
            elif typ == 't' and find in t:
                found = True
    if found:
        print(json.dumps(feature, ensure_ascii=False))
Example #7
0
    print('Usage: {0} <country.mwm> <type> <string>'.format(sys.argv[0]))
    print('')
    print('Type:')
    print('  t for inside types ("t hwtag" will find all hwtags-*)')
    print('  et for exact type ("et shop" won\'t find shop-chemist)')
    print('  n for names, case-sensitive ("n Starbucks" for all starbucks)')
    print('  m for metadata keys ("m flats" for features with flats)')
    sys.exit(1)

typ = sys.argv[2].lower()
find = sys.argv[3].decode('utf-8')

mwm = MWM(open(sys.argv[1], 'rb'))
mwm.read_header()
mwm.read_types(os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', 'data', 'types.txt'))
for feature in mwm.iter_features(metadata=True):
    found = False
    if typ == 'n' and 'name' in feature['header']:
        for value in feature['header']['name'].values():
            if find in value:
                found = True
    elif typ in ('t', 'et'):
        for t in feature['header']['types']:
            if t == find:
                found = True
            elif typ == 't' and find in t:
                found = True
    elif typ == 'm' and 'metadata' in feature:
        if find in feature['metadata']:
            found = True
    if found:
Example #8
0
    print('')
    print('Type:')
    print('  t for inside types ("t hwtag" will find all hwtags-*)')
    print('  et for exact type ("et shop" won\'t find shop-chemist)')
    print('  n for names, case-sensitive ("n Starbucks" for all starbucks)')
    print('  m for metadata keys ("m flats" for features with flats)')
    print('  id for feature id ("id 1234" for feature #1234)')
    sys.exit(1)

typ = sys.argv[2].lower()
find = sys.argv[3].decode('utf-8')

mwm = MWM(open(sys.argv[1], 'rb'))
mwm.read_header()
mwm.read_types(os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', 'data', 'types.txt'))
for i, feature in enumerate(mwm.iter_features(metadata=True)):
    found = False
    if typ == 'n' and 'name' in feature['header']:
        for value in feature['header']['name'].values():
            if find in value:
                found = True
    elif typ in ('t', 'et'):
        for t in feature['header']['types']:
            if t == find:
                found = True
            elif typ == 't' and find in t:
                found = True
    elif typ == 'm' and 'metadata' in feature:
        if find in feature['metadata']:
            found = True
    elif typ == 'id' and i == int(find):