Skip to content

Commit

Permalink
Updated to 0.0.2 with some fixes to the gem, included library and add…
Browse files Browse the repository at this point in the history
…itional support for OSM model exploration. Requires the 0.3-SNAPSHOT of neo4j-spatial from 13th January 2010 (included in this gem as binary).
  • Loading branch information
Craig Taverner committed Jan 12, 2011
1 parent a4f2025 commit 9deab48
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 2 deletions.
59 changes: 59 additions & 0 deletions examples/osm_random_trace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env jruby

# useful if being run inside a source code checkout
$: << 'lib'
$: << '../lib'

require 'rubygems'
require 'neo4j/spatial'

require 'neo4j/spatial/cmd'

$args = Neo4j::Spatial::Cmd.args

if $list === 'layers'
layers = Neo4j::Spatial::Layer.list
puts "Have #{layers.length} existing layers in the database:"
layers.each {|l| puts "\t#{l} (#{l.type_name})"}
puts
exit 0
end

if $help || $args.length < 1
puts <<-eos
usage: ./osm_random_trace.rb <-D storage_path> <-E dir> <-M #> <-l> <-h> layer <layers>
-D Use specified database location
-E Use specified export directory path (default '.')
-M Number of points to include in trace (default 1000)
-l List existing database layers
-h Display this help and exit
The layer should be a pre-existing OSM layer in the database created with OSM import.
Each layer specified will have a random point selected, and then all trace a route
from that point through the graph of connected ways. The entire route is then output
as an SHP and PNG export.
eos
exit
end

$shp_exporter = Neo4j::Spatial::ShapefileExporter.new :dir => $export
$png_exporter = Neo4j::Spatial::ImageExporter.new :dir => $export

puts "Finding random routes from #{$args.length} layers"

$args.each do |layer|
l = Neo4j::Spatial::Layer.find layer
if l.type_name === 'osm'
osm = l.dataset
puts "Have dataset: #{osm}"
osm.ways[0..1].each do |w|
puts "Have way: #{w}"
puts "Have way points: #{w.points}"
end
#puts "Exporting #{l} (#{l.type_name}) - #{l.index.layer_bounding_box}"
#$exporter.export l.name
else
puts "Layer #{l} does not appear to be an OSM layer"
end
end
2 changes: 2 additions & 0 deletions lib/neo4j/spatial/cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def self.args
end
elsif arg =~ /\-E/
$export = ARGV.shift
elsif arg =~ /\-M/
$limit = Math.max(ARGV.shift.to_i, 10)
elsif arg =~ /\-F/
$format = ARGV.shift
elsif arg =~ /\-L/
Expand Down
Binary file modified lib/neo4j/spatial/jars/neo4j-spatial-0.3-SNAPSHOT.jar
Binary file not shown.
58 changes: 58 additions & 0 deletions lib/neo4j/spatial/osm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,65 @@
java_import org.neo4j.gis.spatial.SpatialDatabaseService
java_import org.neo4j.gis.spatial.osm.OSMGeometryEncoder

module Java
module OrgNeo4jGisSpatialOsm
class OSMDataset
def to_s
layers.map{|l| l.name}.join(', ')
end
def way_nodes
all_way_nodes
end
def ways
#all_way_nodes.map{|w| Neo4j::Spatial::OSMWay.new w}
Neo4j::Spatial::OSMWays.new(all_way_nodes)
end
end
end
end
module Neo4j
module Spatial
class OSMWay
def initialize(node)
@node = node
end
def first_point
first_point_proxy.outgoing(:NODE).first
end
def last_point
last_point_proxy.outgoing(:NODE).first
end
def first_point_proxy
@node.outgoing(:FIRST_NODE).first
end
def last_point_proxy
@node.outgoing(:LAST_NODE).first
end
def points
@node.methods.grep(/traver/).join(', ')
first_point_proxy.outgoing(:NEXT).depth(100000).map{|n| n.outgoing(:NODE).first}
end
def to_s
@node['name'] || @node.to_s
end
end
class OSMWays
attr_reader :nodes
def initialize(nodes)
@nodes = nodes
end
def each
@nodes.each{|n| yield OSMWay.new(n)}
end
def first
OSMWay.new @nodes.first
end
def [](index)
index.is_a?(Range) ?
@nodes.to_a[index].map{|n| OSMWay.new(n)} :
OSMWay.new(@nodes.to_a[index])
end
end
class OSMLayer < Layer
def initialize(layer_name,options={})
super(layer_name, options.merge({
Expand All @@ -26,6 +83,7 @@ def add_dynamic_layer(options={})
layer.add_dynamic_layer_on_way_tags(name.to_s, gtype, java.util.HashMap.new(options))
end
end
# List dynamic layers associated with this layer
def list
@layer.layer_names
end
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j/spatial/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Neo4j
module Spatial
VERSION = "0.0.1"
VERSION = "0.0.2"
end
end
2 changes: 1 addition & 1 deletion neo4j-spatial.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ EOF
s.extra_rdoc_files = %w( README.rdoc )
s.rdoc_options = ["--quiet", "--title", "Neo4j-Spatial.rb", "--opname", "index.html", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
s.required_ruby_version = ">= 1.8.7"
s.add_dependency('neo4j',">= 1.0.0")
s.add_dependency('neo4j',">= 1.0.0.beta.23")
s.add_dependency('amanzi-sld',">= 0.0.1")
end

0 comments on commit 9deab48

Please sign in to comment.