This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Feature Classification functionality
- Loading branch information
Showing
7 changed files
with
202 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
=== 0.0.1 / 2012-06-26 | ||
|
||
* 1 major enhancement | ||
* Birthday! | ||
* 2 published gem | ||
* 3 added command line app | ||
* 4 added filter osm map features | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require_relative 'mongohandler' | ||
|
||
# Classifying OSM Features | ||
# | ||
# Purpose: | ||
# Assuming you have already imported data into nodes, ways and rels collections. | ||
# | ||
# This class implements: | ||
# - Dbhandler interface. | ||
# | ||
module DB | ||
class Classifier < DB::Dbhandler | ||
|
||
attr_accessor :connection | ||
|
||
COLL_WAYS = "ways" | ||
|
||
# | ||
# Constructor. | ||
# ==== Attributes | ||
# * +database_name+ database name | ||
# * +collection_name+ collection name | ||
# * +bulk_limit+ Array limit for bulk insert. | ||
# * +host+ host name (default: localhost) | ||
# * +port+ port number (default: 27017) | ||
def initialize(database_name, bulk_limit, host, port) | ||
@host = host | ||
@port = port | ||
@dbname = database_name | ||
@bulk_limit = bulk_limit | ||
@data_array = Array.new | ||
connect() | ||
end | ||
|
||
# | ||
# Connecting to database | ||
# | ||
# Connecting to database with given: | ||
# ==== Attributes | ||
# * +host+ Host name | ||
# * +port+ Port number | ||
# * +pool_size+ optional | ||
# | ||
def connect | ||
@connection = Mongo::Connection.new(@host, @port, :pool_size => 5) | ||
@collection = (@connection[@dbname])[COLL_WAYS] | ||
end | ||
|
||
# | ||
# Load all features into feature_name collection. | ||
# ==== Attributes | ||
# * +feature_name+ OSM Map Feature Name | ||
# | ||
def classify_all(feature_name) | ||
feature_con = DB::Mongohandler.new(@dbname, feature_name, @bulk_limit, @host, @port) | ||
feature_con.use_connection(@connection) | ||
|
||
@collection.find("tags." << feature_name => {"$exists" => true}).each do |doc| | ||
feature_con.bulk_insert(doc) | ||
end | ||
return feature_con.collection.size | ||
end | ||
|
||
# | ||
# Load all features into feature_name collection with subfeature filtering. | ||
# ==== Attributes | ||
# * +feature_name+ OSM Map Feature name | ||
# * +sub_feature+ OSM Map Sub feature name | ||
# | ||
|
||
def classify_subtype(main_feature, sub_feature) | ||
# First argument identifies Main Feature, the rest sub-features | ||
feature_con = DB::Mongohandler.new(@dbname, main_feature, @bulk_limit, @host, @port) | ||
feature_con.use_connection(@connection) | ||
|
||
@collection.find({"tags." << main_feature => sub_feature}).each do |doc| | ||
feature_con.bulk_insert(doc) | ||
end | ||
return feature_con.collection.size | ||
end | ||
|
||
# | ||
# Abstract method | ||
# | ||
# Insert data: | ||
# ==== Attributes | ||
# * +data+ Hash or Array | ||
# | ||
def insert(*args) | ||
|
||
end | ||
|
||
# | ||
# Abstract method | ||
# | ||
# Insert many data at once. | ||
# ==== Attributes | ||
# * +data+ Array of Hashes | ||
# | ||
def bulk_insert(*args) | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
$LOAD_PATH << '../lib/db' | ||
require 'classifier.rb' | ||
|
||
|
||
describe DB::Classifier, "#connect" do | ||
it "should returns connection status active" do | ||
mongo = DB::Classifier.new("osm", 100, 'localhost', '27017') | ||
(mongo.connection.connected?).should be(true) | ||
end | ||
end | ||
|
||
|
||
describe DB::Classifier do | ||
before do | ||
@handler = DB::Classifier.new("osm", 100, 'localhost', '27017') | ||
end | ||
|
||
it "should insert documents by given feature type" do | ||
result = @handler.classify_all("highway") | ||
result.should be > 0 | ||
end | ||
|
||
it "should insert documents by given feature-sub-feature type" do | ||
result = @handler.classify_subtype("waterway", "riverbank") | ||
result.should be > 0 | ||
end | ||
|
||
|
||
after do | ||
#@handler.collection.drop() | ||
end | ||
end |