diff options
Diffstat (limited to 'sources/potlatch')
-rwxr-xr-x | sources/potlatch/import_potlatch.rb | 74 | ||||
-rw-r--r-- | sources/potlatch/post.sql | 13 | ||||
-rw-r--r-- | sources/potlatch/pre.sql | 68 | ||||
-rwxr-xr-x | sources/potlatch/update.sh | 40 |
4 files changed, 195 insertions, 0 deletions
diff --git a/sources/potlatch/import_potlatch.rb b/sources/potlatch/import_potlatch.rb new file mode 100755 index 0000000..b939cc6 --- /dev/null +++ b/sources/potlatch/import_potlatch.rb @@ -0,0 +1,74 @@ +#!/usr/bin/ruby +#------------------------------------------------------------------------------ +# +# Taginfo source: Potlatch +# +# import_potlatch.rb +# +#------------------------------------------------------------------------------ +# +# Copyright (C) 2010 Jochen Topf <jochen@remote.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +#------------------------------------------------------------------------------ + +require 'pp' +require 'sqlite3' +require 'rexml/document' + +dir = ARGV[0] || '.' + +db = SQLite3::Database.new(dir + '/taginfo-potlatch.db') + +db.execute('BEGIN TRANSACTION'); + +file = File.new(dir + '/resources/map_features.xml') +doc = REXML::Document.new(file) + +doc.elements.each('/mapFeatures/category') do |category_element| + db.execute('INSERT INTO categories (id, name) VALUES (?, ?)', category_element.attributes['id'], category_element.attributes['name']) +end + +doc.elements.each('/mapFeatures/feature') do |feature_element| + feature_name = feature_element.attributes['name'] + + on = { :point => 0, :line => 0, :area => 0, :relation => 0 } + + fields = Hash.new + feature_element.elements.each do |element| + case element.name + when 'tag' + value = element.attributes['v'] == '*' ? nil : element.attributes['v'] + db.execute('INSERT INTO tags (key, value, feature_name) VALUES (?, ?, ?)', element.attributes['k'], value, feature_name) + when /^(point|line|area|relation)$/ + on[$1.to_sym] = 1 + when /^(category|help)$/ + fields[element.name] = element.text.strip + end + end + + if on[:point] + on[:line] + on[:area] + on[:relation] == 0 + on = { :point => 1, :line => 1, :area => 1, :relation => 1 } + end + + db.execute('INSERT INTO features (name, category_id, help, on_point, on_line, on_area, on_relation) VALUES (?, ?, ?, ?, ?, ?, ?)', + feature_name, fields['category'], fields['help'], on[:point], on[:line], on[:area], on[:relation]) +end + +db.execute('COMMIT'); + + +#-- THE END ------------------------------------------------------------------- diff --git a/sources/potlatch/post.sql b/sources/potlatch/post.sql new file mode 100644 index 0000000..3446d08 --- /dev/null +++ b/sources/potlatch/post.sql @@ -0,0 +1,13 @@ +-- +-- Taginfo source: Potlatch +-- +-- post.sql +-- + +.bail ON + +-- pull over category name from categories table so we don't need joins later +UPDATE features SET category_name = (SELECT name FROM categories WHERE id=category_id); + +ANALYZE; + diff --git a/sources/potlatch/pre.sql b/sources/potlatch/pre.sql new file mode 100644 index 0000000..7f3a40b --- /dev/null +++ b/sources/potlatch/pre.sql @@ -0,0 +1,68 @@ +-- +-- Taginfo source: Potlatch +-- +-- pre.sql +-- + +.bail ON + +DROP TABLE IF EXISTS meta; + +CREATE TABLE meta ( + source_id TEXT, + source_name TEXT, + update_start TEXT, + update_end TEXT, + data_until TEXT +); + +INSERT INTO meta (source_id, source_name, update_start, data_until) SELECT 'potlatch', 'Potlatch', datetime('now'), datetime('now'); + +DROP TABLE IF EXISTS stats; + +CREATE TABLE stats ( + key TEXT, + value INT64 +); + +-- +-- categories +-- + +DROP TABLE IF EXISTS categories; + +CREATE TABLE categories ( + id TEXT, + name TEXT +); + + +-- +-- features +-- + +DROP TABLE IF EXISTS features; + +CREATE TABLE features ( + name TEXT, + category_id TEXT REFERENCES categories (id), + category_name TEXT, + help TEXT, + on_point INTEGER, + on_line INTEGER, + on_area INTEGER, + on_relation INTEGER +); + +-- +-- tags +-- + +DROP TABLE IF EXISTS tags; + +CREATE TABLE tags ( + key TEXT, + value TEXT, + feature_name REFERENCES features (name) +); + diff --git a/sources/potlatch/update.sh b/sources/potlatch/update.sh new file mode 100755 index 0000000..004f1db --- /dev/null +++ b/sources/potlatch/update.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# +# Taginfo source: Potlatch +# +# update.sh DIR +# + +set -e + +DIR=$1 + +if [ "x" = "x$DIR" ]; then + echo "Usage: update.sh DIR" + exit 1 +fi + +echo -n "Start potlatch: "; date + +DATABASE=$DIR/taginfo-potlatch.db + +rm -f $DATABASE + +echo "Getting resources..." +#if [ -d $DIR/resources ]; then +# svn update $DIR/resources +#else +# svn checkout http://svn.openstreetmap.org/applications/editors/potlatch2/resources $DIR/resources +#fi + +echo "Running pre.sql..." +sqlite3 $DATABASE <pre.sql + +echo "Running import..." +./import_potlatch.rb $DIR + +echo "Running post.sql..." +sqlite3 $DATABASE <post.sql + +echo -n "Done potlatch: "; date + |