Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIlya Zverev <zverik@textual.ru>2016-06-04 14:35:01 +0300
committerIlya Zverev <zverik@textual.ru>2016-06-04 14:35:01 +0300
commit114ae064698c5f4c76b0c2df7fe6402b7584c93f (patch)
treeb6a2cfad785b78bb9dc463e451546f3c15af9362 /tools
parentb86735478487d7f9e1784e8a25ee6d259bb6b576 (diff)
[mwm.py] Universal feature finder
Diffstat (limited to 'tools')
-rwxr-xr-xtools/python/mwm/find_feature.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/python/mwm/find_feature.py b/tools/python/mwm/find_feature.py
new file mode 100755
index 0000000000..4071e7dc08
--- /dev/null
+++ b/tools/python/mwm/find_feature.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+import sys, os.path, json
+from mwm import MWM
+
+if len(sys.argv) < 4:
+ print 'Finds features in an mwm file'
+ print 'Usage: {0} <country.mwm> <type> <string>'.format(sys.argv[0])
+ print 'Type: t for inside types, et for exact type, n for names'
+ sys.exit(1)
+
+typ = sys.argv[2].lower()
+find = sys.argv[3]
+
+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)