summaryrefslogtreecommitdiff
path: root/tagstats
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2013-01-14 10:43:59 +0100
committerJochen Topf <jochen@topf.org>2013-01-14 10:43:59 +0100
commitff80fc295e1894db534ed59c70d7eb67ff766640 (patch)
treea3c1e2da39c98a6f42a1a1a0d7ebcddc833b8b6d /tagstats
parent71e1327b05eae06a39128b1bd288c4685861ab10 (diff)
downloadtaginfo-ff80fc295e1894db534ed59c70d7eb67ff766640.tar
taginfo-ff80fc295e1894db534ed59c70d7eb67ff766640.tar.gz
Add infrastructure for doing relation type stats
Diffstat (limited to 'tagstats')
-rw-r--r--tagstats/tagstats.cpp48
-rw-r--r--tagstats/tagstats_handler.hpp19
-rw-r--r--tagstats/test_relation_types.txt4
-rw-r--r--tagstats/test_tags.txt (renamed from tagstats/test_tagslist.txt)0
-rwxr-xr-xtagstats/test_tagstats.sh2
5 files changed, 50 insertions, 23 deletions
diff --git a/tagstats/tagstats.cpp b/tagstats/tagstats.cpp
index 9c026fa..aeca840 100644
--- a/tagstats/tagstats.cpp
+++ b/tagstats/tagstats.cpp
@@ -57,39 +57,42 @@ void print_help() {
<< "This program is part of Taginfo. It calculates statistics\n" \
<< "on OSM tags from OSMFILE and puts them into DATABASE (an SQLite database).\n" \
<< "\nOptions:\n" \
- << " -H, --help This help message\n" \
- << " -d, --debug Enable debugging output\n";
+ << " -H, --help This help message\n" \
+ << " -d, --debug Enable debugging output\n";
#ifdef TAGSTATS_COUNT_TAG_COMBINATIONS
- std::cout << " -T, --tags-list File with tags we are especially interested in\n";
+ std::cout << " -T, --tags=FILENAME File with tags we are interested in\n";
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
- std::cout << " -t, --top=NUMBER Top of bounding box for distribution images\n" \
- << " -r, --right=NUMBER Right of bounding box for distribution images\n" \
- << " -b, --bottom=NUMBER Bottom of bounding box for distribution images\n" \
- << " -l, --left=NUMBER Left of bounding box for distribution images\n" \
- << " -w, --width=NUMBER Width of distribution images (default: 360)\n" \
- << " -h, --height=NUMBER Height of distribution images (default: 180)\n" \
+ std::cout << " -R, --relation-types=FILENAME File with relation types we are interested in\n" \
+ << " -t, --top=NUMBER Top of bounding box for distribution images\n" \
+ << " -r, --right=NUMBER Right of bounding box for distribution images\n" \
+ << " -b, --bottom=NUMBER Bottom of bounding box for distribution images\n" \
+ << " -l, --left=NUMBER Left of bounding box for distribution images\n" \
+ << " -w, --width=NUMBER Width of distribution images (default: 360)\n" \
+ << " -h, --height=NUMBER Height of distribution images (default: 180)\n" \
<< "\nDefault for bounding box is: (-180, -90, 180, 90).\n";
}
int main(int argc, char *argv[]) {
static struct option long_options[] = {
- {"debug", no_argument, 0, 'd'},
- {"help", no_argument, 0, 'H'},
+ {"debug", no_argument, 0, 'd'},
+ {"help", no_argument, 0, 'H'},
#ifdef TAGSTATS_COUNT_TAG_COMBINATIONS
- {"tags-list", required_argument, 0, 'T'},
+ {"tags", required_argument, 0, 'T'},
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
- {"top", required_argument, 0, 't'},
- {"right", required_argument, 0, 'r'},
- {"bottom", required_argument, 0, 'b'},
- {"left", required_argument, 0, 'l'},
- {"width", required_argument, 0, 'w'},
- {"height", required_argument, 0, 'h'},
+ {"relation-types", required_argument, 0, 'R'},
+ {"top", required_argument, 0, 't'},
+ {"right", required_argument, 0, 'r'},
+ {"bottom", required_argument, 0, 'b'},
+ {"left", required_argument, 0, 'l'},
+ {"width", required_argument, 0, 'w'},
+ {"height", required_argument, 0, 'h'},
{0, 0, 0, 0}
};
bool debug = false;
std::string tags_list;
+ std::string relation_type_list;
double top = 90;
double right = 180;
@@ -102,9 +105,9 @@ int main(int argc, char *argv[]) {
while (true) {
int c = getopt_long(argc, argv,
#ifdef TAGSTATS_COUNT_TAG_COMBINATIONS
- "dHT:t:r:b:l:w:h:",
+ "dHT:R:t:r:b:l:w:h:",
#else
- "dHt:r:b:l:w:h:",
+ "dHR:t:r:b:l:w:h:",
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
long_options, 0);
if (c == -1) {
@@ -123,6 +126,9 @@ int main(int argc, char *argv[]) {
tags_list = optarg;
break;
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
+ case 'R':
+ relation_type_list = optarg;
+ break;
case 't':
top = atof(optarg);
break;
@@ -155,7 +161,7 @@ int main(int argc, char *argv[]) {
Osmium::OSMFile infile(argv[optind]);
Sqlite::Database db(argv[optind+1]);
MapToInt<rough_position_t> map_to_int(left, bottom, right, top, width, height);
- TagStatsHandler handler(db, tags_list, map_to_int);
+ TagStatsHandler handler(db, tags_list, relation_type_list, map_to_int);
Osmium::Input::read(infile, handler);
}
diff --git a/tagstats/tagstats_handler.hpp b/tagstats/tagstats_handler.hpp
index b2f4416..2955d53 100644
--- a/tagstats/tagstats_handler.hpp
+++ b/tagstats/tagstats_handler.hpp
@@ -25,6 +25,7 @@
#include <string>
#include <fstream>
#include <iostream>
+#include <map>
#include <google/sparse_hash_map>
#include <boost/algorithm/string/split.hpp>
@@ -181,6 +182,15 @@ public:
typedef google::sparse_hash_map<const char *, KeyValueStats *, djb2_hash, eqstr> key_value_hash_map_t;
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
+class RelationTypeStats {
+
+public:
+
+ RelationTypeStats() {
+ }
+
+}; // class RelationTypeStats
+
/**
* Osmium handler that creates statistics for Taginfo.
*/
@@ -200,6 +210,8 @@ class TagStatsHandler : public Osmium::Handler::Base {
key_value_hash_map_t m_key_value_stats;
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
+ std::map<std::string, RelationTypeStats> m_relation_type_stats;
+
time_t m_max_timestamp;
// this must be much bigger than the largest string we want to store
@@ -392,7 +404,7 @@ class TagStatsHandler : public Osmium::Handler::Base {
public:
- TagStatsHandler(Sqlite::Database& database, const std::string& tags_list, MapToInt<rough_position_t>& map_to_int) :
+ TagStatsHandler(Sqlite::Database& database, const std::string& tags_list, const std::string& relation_type_list, MapToInt<rough_position_t>& map_to_int) :
Base(),
m_max_timestamp(0),
m_string_store(string_store_size),
@@ -410,6 +422,11 @@ public:
m_key_value_stats[m_string_store.add(key_value.c_str())] = new KeyValueStats();
}
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
+ std::ifstream relation_type_list_file(relation_type_list.c_str(), std::ifstream::in);
+ std::string type;
+ while (relation_type_list_file >> type) {
+ m_relation_type_stats[type] = RelationTypeStats();
+ }
}
void node(const shared_ptr<Osmium::OSM::Node const>& node) {
diff --git a/tagstats/test_relation_types.txt b/tagstats/test_relation_types.txt
new file mode 100644
index 0000000..ffd5691
--- /dev/null
+++ b/tagstats/test_relation_types.txt
@@ -0,0 +1,4 @@
+multipolygon
+site
+route
+associatedStreet
diff --git a/tagstats/test_tagslist.txt b/tagstats/test_tags.txt
index e53cd59..e53cd59 100644
--- a/tagstats/test_tagslist.txt
+++ b/tagstats/test_tags.txt
diff --git a/tagstats/test_tagstats.sh b/tagstats/test_tagstats.sh
index ec08b91..d07b5b7 100755
--- a/tagstats/test_tagstats.sh
+++ b/tagstats/test_tagstats.sh
@@ -21,5 +21,5 @@ ulimit -c 1000000000
rm -f core
#./tagstats --left=5.5 --bottom=47 --right=15 --top=55 --width=200 --height=320 $OSMFILE $DATABASE
-./tagstats -T test_tagslist.txt $OSMFILE $DATABASE
+./tagstats --tags test_tags.txt --relation-types test_relation_types.txt $OSMFILE $DATABASE