neo4j-spatial 0.0.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/CONTRIBUTORS +5 -0
- data/Gemfile +15 -0
- data/README.rdoc +55 -0
- data/examples/export_layer.rb +54 -0
- data/examples/map.osm +6470 -0
- data/examples/map2.osm +131867 -0
- data/examples/osm_import.rb +29 -0
- data/examples/osm_layer.rb +55 -0
- data/examples/test.rb +92 -0
- data/lib/neo4j/spatial/cmd.rb +37 -0
- data/lib/neo4j/spatial/database.rb +85 -0
- data/lib/neo4j/spatial/image.rb +54 -0
- data/lib/neo4j/spatial/jars/gt-main/gt-api-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-main/gt-main-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-main/jdom-1.0.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-main/jts-1.11.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-main/xercesImpl-2.4.0.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-render/gt-coverage-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-render/gt-cql-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-render/gt-render-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-render/imageio-ext-tiff-1.0.7.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-render/imageio-ext-utilities-1.0.7.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-render/jai_codec-1.1.3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-render/jai_core-1.1.3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-render/jai_imageio-1.1.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/commons-pool-1.5.4.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/geoapi-2.3-M1.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/geoapi-pending-2.3-M1.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/gt-data-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/gt-metadata-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/gt-referencing-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/gt-shapefile-2.7-M3.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/jsr-275-1.0-beta-2.jar +0 -0
- data/lib/neo4j/spatial/jars/gt-shapefile/vecmath-1.3.2.jar +0 -0
- data/lib/neo4j/spatial/jars/json-simple-1.1.jar +0 -0
- data/lib/neo4j/spatial/jars/log4j-1.2.14.jar +0 -0
- data/lib/neo4j/spatial/jars/neo4j-spatial-0.3-SNAPSHOT.jar +0 -0
- data/lib/neo4j/spatial/layer.rb +60 -0
- data/lib/neo4j/spatial/listener.rb +29 -0
- data/lib/neo4j/spatial/osm.rb +52 -0
- data/lib/neo4j/spatial/shapefile.rb +50 -0
- data/lib/neo4j/spatial/version.rb +5 -0
- data/lib/neo4j/spatial.rb +56 -0
- data/neo4j-spatial.gemspec +31 -0
- metadata +158 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
|
3
|
+
# useful if being run inside a source code checkout
|
4
|
+
$: << 'lib'
|
5
|
+
$: << '../lib'
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'neo4j/spatial'
|
9
|
+
require 'neo4j/spatial/cmd'
|
10
|
+
require 'fileutils'
|
11
|
+
|
12
|
+
$files = Neo4j::Spatial::Cmd.args
|
13
|
+
|
14
|
+
if $help || $files.length < 1
|
15
|
+
puts "usage: osm_import.rb <-d> <-D storage_path> file.osm"
|
16
|
+
puts "\t-d\tDelete database first"
|
17
|
+
puts "\t-D\tUse specified database location"
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
if $delete
|
22
|
+
puts "Deleting previous database #{Neo4j::Config[:storage_path]}"
|
23
|
+
FileUtils.rm_rf Neo4j::Config[:storage_path]
|
24
|
+
end
|
25
|
+
|
26
|
+
$files.each do |file|
|
27
|
+
osm_importer = Neo4j::Spatial::OSMImporter.new
|
28
|
+
osm_importer.import file
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
|
3
|
+
# useful if being run inside a source code checkout
|
4
|
+
$: << 'lib'
|
5
|
+
$: << '../lib'
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'neo4j/spatial'
|
9
|
+
require 'neo4j/spatial/cmd'
|
10
|
+
|
11
|
+
$args = Neo4j::Spatial::Cmd.args
|
12
|
+
|
13
|
+
if $list === 'layers'
|
14
|
+
layers = Neo4j::Spatial::Layer.list
|
15
|
+
puts "Have #{layers.length} existing layers in the database:"
|
16
|
+
layers.each {|l| puts "\t#{l} (#{l.type_name})"}
|
17
|
+
puts
|
18
|
+
exit 0
|
19
|
+
end
|
20
|
+
|
21
|
+
if $help || $args.length < 2
|
22
|
+
puts <<-eos
|
23
|
+
|
24
|
+
usage: ./osm_layer.rb <-D storage_path> <-l> <-h> layer layerspec <layerspecs>
|
25
|
+
-D Use specified database location
|
26
|
+
-l List existing database layers
|
27
|
+
-h Display this help and exit
|
28
|
+
The layer should be a pre-existing OSM layer in the database created with OSM import.
|
29
|
+
The layerspec(s) are strings that are composed of multiple '-' or '.' separators.
|
30
|
+
Each pair in order is treated as a property-value pair to match when searching the
|
31
|
+
original layer for the new dynamic layer geometries.
|
32
|
+
|
33
|
+
For example:
|
34
|
+
./osm_layer.rb -D db croatia.osm highway highway-residential natural-water
|
35
|
+
|
36
|
+
This will define three dynamic layers in the croation.osm dataset:
|
37
|
+
highway all ways that have a 'highway' property
|
38
|
+
highway-residential all ways that have 'highway'='residential'
|
39
|
+
natural-waterway all ways that have 'natural'='waterway'
|
40
|
+
|
41
|
+
eos
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
|
45
|
+
$layer = Neo4j::Spatial::OSMLayer.new $args.shift
|
46
|
+
|
47
|
+
if $layer.empty?
|
48
|
+
puts "No such layer: #{$layer}"
|
49
|
+
end
|
50
|
+
|
51
|
+
$args.each do |layerspec|
|
52
|
+
x = layerspec.split(/[\.-]/) << nil
|
53
|
+
x = x[0...(2*(x.length/2))] # allow only even number of entries
|
54
|
+
$layer.add_dynamic_layer Hash[*x]
|
55
|
+
end
|
data/examples/test.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
|
3
|
+
$: << 'lib'
|
4
|
+
$: << '../lib'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'neo4j/spatial'
|
8
|
+
require 'fileutils'
|
9
|
+
require 'amanzi/sld'
|
10
|
+
|
11
|
+
#shp_importer.import '../neo4j-spatial/target/shp/sweden_coastline.shp'
|
12
|
+
#png_exporter.export 'sweden_coastline'
|
13
|
+
|
14
|
+
if false
|
15
|
+
FileUtils.rm_rf 'tmp'
|
16
|
+
|
17
|
+
osm_importer = Neo4j::Spatial::OSMImporter.new
|
18
|
+
osm_importer.import '../neo4j-spatial/map2.osm'
|
19
|
+
osm = Neo4j::Spatial::OSMLayer.new "map2.osm"
|
20
|
+
|
21
|
+
osm.add_dynamic_layer
|
22
|
+
osm.add_dynamic_layer(:layer_name => 'test')
|
23
|
+
osm.add_dynamic_layer(:highway => nil)
|
24
|
+
osm.add_dynamic_layer(:highway => 'residential')
|
25
|
+
osm.add_dynamic_layer(:highway => :unclassified)
|
26
|
+
|
27
|
+
else
|
28
|
+
osm = Neo4j::Spatial::OSMLayer.new "map2.osm"
|
29
|
+
end
|
30
|
+
|
31
|
+
puts "OSM Layer index should not be null: #{osm.index}"
|
32
|
+
puts "OSM Layer index envelope should not be null: #{osm.index.layer_bounding_box}"
|
33
|
+
#osm.index.debug_index_tree
|
34
|
+
|
35
|
+
osm.layers.each do |l|
|
36
|
+
puts "Have layer: #{l.name}"
|
37
|
+
if l.respond_to? :query
|
38
|
+
puts "\t#{l.query}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
png_exporter = Neo4j::Spatial::ImageExporter.new
|
43
|
+
#shp_importer = Neo4j::Spatial::ShapefileImporter.new
|
44
|
+
|
45
|
+
# Define some common filtering rules
|
46
|
+
major_highways = Proc.new do |f|
|
47
|
+
f.op(:or) do |f|
|
48
|
+
f.property[:highway] = 'primary'
|
49
|
+
f.property[:highway] = 'motorway'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
highways = Proc.new do |f|
|
54
|
+
f.op(:or) do |f|
|
55
|
+
f.property[:highway] = 'primary'
|
56
|
+
f.property[:highway] = 'secondary'
|
57
|
+
f.property[:highway] = 'motorway'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
main_roads = Proc.new do |f|
|
62
|
+
f.op(:or) do |f|
|
63
|
+
f.property[:highway] = 'primary'
|
64
|
+
f.property[:highway] = 'secondary'
|
65
|
+
f.property[:highway] = 'tertiary'
|
66
|
+
f.property[:highway] = 'motorway'
|
67
|
+
f.property[:highway] = 'residential'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
#png_exporter.export 'map2.osm', :sld => '../neo4j-spatial/neo.sld.xml'
|
72
|
+
|
73
|
+
png_exporter.export 'highway' do |sld|
|
74
|
+
sld.add_line_symbolizer :stroke => '#909090', :stroke_width => 3
|
75
|
+
sld.add_line_symbolizer :stroke => '#f0f0f0', :stroke_width => 2
|
76
|
+
sld.add_line_symbolizer :stroke => '#909090', :stroke_width => 5 do |f|
|
77
|
+
main_roads.call f
|
78
|
+
end
|
79
|
+
sld.add_line_symbolizer :stroke => '#909090', :stroke_width => 7 do |f|
|
80
|
+
highways.call f
|
81
|
+
end
|
82
|
+
sld.add_line_symbolizer :stroke => '#e0e0e0', :stroke_width => 3 do |f|
|
83
|
+
main_roads.call f
|
84
|
+
end
|
85
|
+
sld.add_line_symbolizer :stroke => '#f0f0a0', :stroke_width => 5 do |f|
|
86
|
+
highways.call f
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#png_exporter.export 'highway-residential'
|
91
|
+
#png_exporter.export 'highway-unclassified'
|
92
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'neo4j'
|
2
|
+
|
3
|
+
# Simple utility for parsing common command-line arguments specific to some command-line utilities
|
4
|
+
module Neo4j
|
5
|
+
module Spatial
|
6
|
+
class Cmd
|
7
|
+
def self.args
|
8
|
+
@args=[]
|
9
|
+
while( arg = ARGV.shift ) do
|
10
|
+
if arg =~ /\-d/
|
11
|
+
$delete = true
|
12
|
+
elsif arg =~ /\-D/
|
13
|
+
path = ARGV.shift
|
14
|
+
if path && path.length > 0
|
15
|
+
Neo4j::Config[:storage_path] = path
|
16
|
+
else
|
17
|
+
puts "Invalid database location: #{path}"
|
18
|
+
end
|
19
|
+
elsif arg =~ /\-E/
|
20
|
+
$export = ARGV.shift
|
21
|
+
elsif arg =~ /\-F/
|
22
|
+
$format = ARGV.shift
|
23
|
+
elsif arg =~ /\-L/
|
24
|
+
$list = ARGV.shift
|
25
|
+
elsif arg =~ /\-l/
|
26
|
+
$list = 'layers'
|
27
|
+
elsif arg =~ /\-h/
|
28
|
+
$help = true
|
29
|
+
else
|
30
|
+
@args << arg
|
31
|
+
end
|
32
|
+
end
|
33
|
+
@args
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# This file includes two modules for working with the database in a spatial way:
|
2
|
+
# - an extension to the Neo4j::Database module allowing re-opening the database with the BatchInserter API
|
3
|
+
# - a Neo4::Spatial::Database module to be including in classes that need access to sptail extensions on the database
|
4
|
+
|
5
|
+
module Neo4j
|
6
|
+
|
7
|
+
# We extend the normal Neo4j::Database module with the ability to switch between normal and batch-inserter modes
|
8
|
+
class Database
|
9
|
+
def shutdown
|
10
|
+
if @running
|
11
|
+
#puts "Shutting down database"
|
12
|
+
if @batch.nil?
|
13
|
+
#puts "Unregistering event handler"
|
14
|
+
@graph.unregister_transaction_event_handler(@event_handler) unless read_only?
|
15
|
+
@event_handler.neo4j_shutdown(self)
|
16
|
+
end
|
17
|
+
@graph.shutdown
|
18
|
+
@graph = nil
|
19
|
+
@batch = nil
|
20
|
+
@lucene = nil
|
21
|
+
@spatial = nil
|
22
|
+
@running = false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
def restart_batch_inserter
|
26
|
+
shutdown
|
27
|
+
@running = true
|
28
|
+
@batch = org.neo4j.kernel.impl.batchinsert.BatchInserterImpl.new(Config[:storage_path])
|
29
|
+
@graph = @batch.graph_db_service
|
30
|
+
@batch
|
31
|
+
end
|
32
|
+
def restart_normal_database
|
33
|
+
shutdown
|
34
|
+
start
|
35
|
+
end
|
36
|
+
def is_batch?
|
37
|
+
@batch
|
38
|
+
end
|
39
|
+
def spatial
|
40
|
+
@spatial ||= org.neo4j.gis.spatial.SpatialDatabaseService.new(@graph)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module Spatial
|
45
|
+
|
46
|
+
# This module is to be included in classes that wish to have instance level access to the database and spatial database extensions
|
47
|
+
module Database
|
48
|
+
def database(options={})
|
49
|
+
options[:dbpath] ||= Neo4j::Config[:storage_path]
|
50
|
+
if Neo4j.running? && Neo4j::Config[:storage_path] != options[:dbpath]
|
51
|
+
raise "Database already running at different location: #{Neo4j::Config[:storage_path]} != #{options[:dbpath]}"
|
52
|
+
end
|
53
|
+
Neo4j::Config[:storage_path] = options[:dbpath]
|
54
|
+
@commit = options[:commit] || 1000
|
55
|
+
normal_database
|
56
|
+
end
|
57
|
+
def spatial
|
58
|
+
@spatial ||= @db.spatial
|
59
|
+
end
|
60
|
+
def list_all
|
61
|
+
spatial.layer_names
|
62
|
+
end
|
63
|
+
def batch_inserter
|
64
|
+
unless @bi
|
65
|
+
puts "Getting batch inserter database API access"
|
66
|
+
@spatial = nil
|
67
|
+
@bi = @db.restart_batch_inserter
|
68
|
+
end
|
69
|
+
@bi
|
70
|
+
end
|
71
|
+
def normal_database
|
72
|
+
if @db && @db.is_batch?
|
73
|
+
puts "Switch off BatchInserter access"
|
74
|
+
@db.restart_normal_database
|
75
|
+
@spatial = nil
|
76
|
+
@bi = nil
|
77
|
+
end
|
78
|
+
@db ||= Neo4j.started_db
|
79
|
+
@db.graph
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'neo4j/spatial/listener'
|
2
|
+
require 'neo4j/spatial/database'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
module Neo4j
|
6
|
+
module Spatial
|
7
|
+
class ImageExporter
|
8
|
+
include Database
|
9
|
+
def initialize(options={})
|
10
|
+
default(options)
|
11
|
+
database(options)
|
12
|
+
@exporter = org.neo4j.gis.spatial.geotools.data.StyledImageExporter.new(@db.graph)
|
13
|
+
@exporter.setExportDir(options[:dir])
|
14
|
+
@exporter.setZoom(options[:zoom])
|
15
|
+
@exporter.setOffset((options[:offset_x] || options[:offset]).to_f, (options[:offset_y] || options[:offset]).to_f)
|
16
|
+
@exporter.setSize(options[:width], options[:height])
|
17
|
+
end
|
18
|
+
def default(options)
|
19
|
+
options[:dir] ||= "target/export"
|
20
|
+
options[:zoom] ||= 3.0
|
21
|
+
options[:offset] ||= 0.0
|
22
|
+
options[:width] ||= 600
|
23
|
+
options[:height] ||= 400
|
24
|
+
end
|
25
|
+
def export(layer_name,options={})
|
26
|
+
@layer_name = layer_name
|
27
|
+
options[:path] ||= layer_name+'.png'
|
28
|
+
if block_given?
|
29
|
+
puts "block is given"
|
30
|
+
end
|
31
|
+
if options[:sld].nil?
|
32
|
+
puts "SLD nil"
|
33
|
+
end
|
34
|
+
if options[:sld].nil? && block_given?
|
35
|
+
Tempfile.open 'neo4j-spatial-sld' do |out|
|
36
|
+
options[:sld] = out.path
|
37
|
+
sld = Amanzi::SLD::Document.new layer_name
|
38
|
+
yield sld
|
39
|
+
out.puts sld.to_xml :tab => ' '
|
40
|
+
end
|
41
|
+
end
|
42
|
+
options[:sld] ||= 'neo.sld.xml'
|
43
|
+
puts "Exporting #{layer_name} to #{options[:path]} using style #{options[:sld]}"
|
44
|
+
@exporter.saveLayerImage(layer_name, options[:sld], options[:path])
|
45
|
+
end
|
46
|
+
def format
|
47
|
+
"PNG"
|
48
|
+
end
|
49
|
+
def to_s
|
50
|
+
@layer_name || format
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'neo4j/spatial/database'
|
2
|
+
|
3
|
+
java_import org.neo4j.gis.spatial.Constants
|
4
|
+
java_import org.neo4j.gis.spatial.SpatialDatabaseService
|
5
|
+
|
6
|
+
module Neo4j
|
7
|
+
module Spatial
|
8
|
+
|
9
|
+
# This class wraps the spatial database layer class and provides some utilities for
|
10
|
+
# wrapping some layer actions normally taken by the SpatialDatabaseService, liking finding layers
|
11
|
+
class Layer
|
12
|
+
TYPES = [:unknown, :point, :linestring, :polygon, :multipoint, :multilinestring, :multipolygon]
|
13
|
+
include Database
|
14
|
+
attr_reader :layer_name, :layer
|
15
|
+
def initialize(layer_name,options={})
|
16
|
+
database(options)
|
17
|
+
@layer_name = layer_name
|
18
|
+
@layer = spatial.getLayer(@layer_name)
|
19
|
+
unless @layer
|
20
|
+
if options[:encoder] && options[:type]
|
21
|
+
@layer = spatial.getOrCreateLayer(@layer_name, options[:encoder], options[:type])
|
22
|
+
elsif options[:x] && options[:y]
|
23
|
+
@layer = spatial.getOrCreatePointLayer(@layer_name, options[:x].to_s, options[:y].to_s)
|
24
|
+
else
|
25
|
+
@layer = spatial.getOrCreateDefaultLayer(@layer_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
def respond_to?(symbol)
|
30
|
+
symbol == :empty? || @layer.respond_to?(symbol)
|
31
|
+
end
|
32
|
+
def method_missing(symbol,*args,&block)
|
33
|
+
@layer.send symbol, *args, &block
|
34
|
+
end
|
35
|
+
def empty?
|
36
|
+
@layer.index.is_empty
|
37
|
+
end
|
38
|
+
def to_s
|
39
|
+
@layer.name
|
40
|
+
end
|
41
|
+
def type_name
|
42
|
+
@layer.class.to_s.downcase.gsub(/.*[\.\:](\w+)layer.*/){|m| $1}
|
43
|
+
end
|
44
|
+
def self.names
|
45
|
+
Neo4j.started_db.spatial.layer_names
|
46
|
+
end
|
47
|
+
def self.list
|
48
|
+
Neo4j.started_db.spatial.layer_names.map do |name|
|
49
|
+
Layer.new(name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
def self.exist? name
|
53
|
+
self.names.grep(name).length > 0
|
54
|
+
end
|
55
|
+
def self.find name
|
56
|
+
exist?(name) && Layer.new(name)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file defines a mixin to be used by classes that want to act as listners implementing the org.neo4j.gis.spatial.Listener interface
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Spatial
|
5
|
+
module Listener
|
6
|
+
include org.neo4j.gis.spatial.Listener
|
7
|
+
def initialize(dbpath=nil)
|
8
|
+
@work = 100
|
9
|
+
@worked = 0
|
10
|
+
end
|
11
|
+
def begin(units_of_work)
|
12
|
+
@work = units_of_work
|
13
|
+
@work = 100 if(@work<1)
|
14
|
+
@worked = 0
|
15
|
+
end
|
16
|
+
def worked(worked_since_last_notification)
|
17
|
+
@worked += worked_since_last_notification
|
18
|
+
progress
|
19
|
+
end
|
20
|
+
def done
|
21
|
+
@worked = @work
|
22
|
+
progress
|
23
|
+
end
|
24
|
+
def progress
|
25
|
+
puts "#{100*@worked/@work}% #{self}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'neo4j/spatial/listener'
|
2
|
+
require 'neo4j/spatial/database'
|
3
|
+
|
4
|
+
java_import org.neo4j.gis.spatial.Constants
|
5
|
+
java_import org.neo4j.gis.spatial.SpatialDatabaseService
|
6
|
+
java_import org.neo4j.gis.spatial.osm.OSMGeometryEncoder
|
7
|
+
|
8
|
+
module Neo4j
|
9
|
+
module Spatial
|
10
|
+
class OSMLayer < Layer
|
11
|
+
def initialize(layer_name,options={})
|
12
|
+
super(layer_name, options.merge({
|
13
|
+
:type => org.neo4j.gis.spatial.osm.OSMLayer,
|
14
|
+
:encoder => OSMGeometryEncoder
|
15
|
+
}))
|
16
|
+
end
|
17
|
+
def add_dynamic_layer(options={})
|
18
|
+
gtype = (options.delete(:gtype) || Constants.GTYPE_LINESTRING).to_i
|
19
|
+
name ||= options.delete(:layer_name) ||
|
20
|
+
!options.empty? && options.to_a.flatten.compact.join('-') ||
|
21
|
+
SpatialDatabaseService.convertGeometryTypeToName(gtype)
|
22
|
+
if list.grep(name).length > 0
|
23
|
+
puts "We already have a dynamic layer called '#{name}'"
|
24
|
+
else
|
25
|
+
puts "Creating new dynamic layer '#{name}'[GType:#{TYPES[gtype]}]: #{options.inspect}"
|
26
|
+
layer.add_dynamic_layer_on_way_tags(name.to_s, gtype, java.util.HashMap.new(options))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
def list
|
30
|
+
@layer.layer_names
|
31
|
+
end
|
32
|
+
end
|
33
|
+
class OSMImporter
|
34
|
+
include Listener
|
35
|
+
include Database
|
36
|
+
def initialize(options={})
|
37
|
+
database(options)
|
38
|
+
end
|
39
|
+
def import(osm_path,layer_name=nil)
|
40
|
+
@osm_path = osm_path
|
41
|
+
layer_name ||= osm_path.split(/[\\\/]+/)[-1]
|
42
|
+
puts "\n=== Loading layer #{layer_name} from #{osm_path} ==="
|
43
|
+
@importer = org.neo4j.gis.spatial.osm.OSMImporter.new(layer_name)
|
44
|
+
@importer.import_file batch_inserter, @osm_path
|
45
|
+
@importer.re_index normal_database, @commit
|
46
|
+
end
|
47
|
+
def to_s
|
48
|
+
@osm_path.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'neo4j/spatial/listener'
|
2
|
+
require 'neo4j/spatial/database'
|
3
|
+
|
4
|
+
# Utilities for importing and exporting ESRI Shapefile data
|
5
|
+
|
6
|
+
module Neo4j
|
7
|
+
module Spatial
|
8
|
+
|
9
|
+
# This class facilitates importing datasets in the ESRI Shapefile format
|
10
|
+
class ShapefileImporter
|
11
|
+
include Listener
|
12
|
+
include Database
|
13
|
+
def initialize(options={})
|
14
|
+
database(options)
|
15
|
+
@importer = org.neo4j.gis.spatial.ShapefileImporter.new(@db.graph, self, @commit)
|
16
|
+
end
|
17
|
+
def import(shp_path,layer_name=nil)
|
18
|
+
@shp_path = shp_path
|
19
|
+
layer_name ||= shp_path.split(/[\\\/]+/)[-1].gsub(/\.\w+$/,'')
|
20
|
+
@importer.import_file @shp_path, layer_name
|
21
|
+
end
|
22
|
+
def to_s
|
23
|
+
@shp_path.to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# This class facilitates importing datasets in the ESRI Shapefile format
|
28
|
+
class ShapefileExporter
|
29
|
+
include Database
|
30
|
+
def initialize(options={})
|
31
|
+
options[:dir] ||= "target/export"
|
32
|
+
database(options)
|
33
|
+
@exporter = org.neo4j.gis.spatial.ShapefileExporter.new(@db.graph)
|
34
|
+
@exporter.setExportDir(options[:dir])
|
35
|
+
end
|
36
|
+
def export(layer_name,options={})
|
37
|
+
@layer_name = layer_name
|
38
|
+
options[:path] ||= layer_name+'.shp'
|
39
|
+
puts "Exporting #{layer_name} to #{options[:path]}"
|
40
|
+
@exporter.exportLayer(layer_name, options[:path])
|
41
|
+
end
|
42
|
+
def format
|
43
|
+
"ESRI Shapefile"
|
44
|
+
end
|
45
|
+
def to_s
|
46
|
+
@layer_name || format
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
include Java
|
2
|
+
|
3
|
+
# Some paths useful in development environment
|
4
|
+
$LOAD_PATH << '../amanzi-sld/lib'
|
5
|
+
$LOAD_PATH << '../../amanzi-sld/lib'
|
6
|
+
$CLASSPATH << '../neo4j-spatial/target/classes'
|
7
|
+
$CLASSPATH << '../../neo4j-spatial/target/classes'
|
8
|
+
|
9
|
+
require 'neo4j'
|
10
|
+
begin
|
11
|
+
require 'amanzi/sld'
|
12
|
+
rescue LoadError
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'neo4j/spatial/jars/neo4j-spatial-0.3-SNAPSHOT.jar'
|
16
|
+
require 'neo4j/spatial/jars/json-simple-1.1.jar'
|
17
|
+
require 'neo4j/spatial/jars/log4j-1.2.14.jar'
|
18
|
+
|
19
|
+
# Geotools main API and Geometry support
|
20
|
+
require 'neo4j/spatial/jars/gt-main/xercesImpl-2.4.0.jar'
|
21
|
+
require 'neo4j/spatial/jars/gt-main/gt-api-2.7-M3.jar'
|
22
|
+
require 'neo4j/spatial/jars/gt-main/jdom-1.0.jar'
|
23
|
+
require 'neo4j/spatial/jars/gt-main/jts-1.11.jar'
|
24
|
+
require 'neo4j/spatial/jars/gt-main/gt-main-2.7-M3.jar'
|
25
|
+
|
26
|
+
# Geotools support for rendering, used in examples for writing maps to PNG
|
27
|
+
require 'neo4j/spatial/jars/gt-render/jai_codec-1.1.3.jar'
|
28
|
+
require 'neo4j/spatial/jars/gt-render/imageio-ext-tiff-1.0.7.jar'
|
29
|
+
require 'neo4j/spatial/jars/gt-render/gt-render-2.7-M3.jar'
|
30
|
+
require 'neo4j/spatial/jars/gt-render/gt-coverage-2.7-M3.jar'
|
31
|
+
require 'neo4j/spatial/jars/gt-render/gt-cql-2.7-M3.jar'
|
32
|
+
require 'neo4j/spatial/jars/gt-render/imageio-ext-utilities-1.0.7.jar'
|
33
|
+
require 'neo4j/spatial/jars/gt-render/jai_core-1.1.3.jar'
|
34
|
+
require 'neo4j/spatial/jars/gt-render/jai_imageio-1.1.jar'
|
35
|
+
|
36
|
+
# Geotools Shapefile support for some utilties for reading/writing shapefiles
|
37
|
+
require 'neo4j/spatial/jars/gt-shapefile/jsr-275-1.0-beta-2.jar'
|
38
|
+
require 'neo4j/spatial/jars/gt-shapefile/geoapi-2.3-M1.jar'
|
39
|
+
require 'neo4j/spatial/jars/gt-shapefile/gt-data-2.7-M3.jar'
|
40
|
+
require 'neo4j/spatial/jars/gt-shapefile/vecmath-1.3.2.jar'
|
41
|
+
require 'neo4j/spatial/jars/gt-shapefile/gt-shapefile-2.7-M3.jar'
|
42
|
+
require 'neo4j/spatial/jars/gt-shapefile/commons-pool-1.5.4.jar'
|
43
|
+
require 'neo4j/spatial/jars/gt-shapefile/gt-metadata-2.7-M3.jar'
|
44
|
+
require 'neo4j/spatial/jars/gt-shapefile/gt-referencing-2.7-M3.jar'
|
45
|
+
require 'neo4j/spatial/jars/gt-shapefile/geoapi-pending-2.3-M1.jar'
|
46
|
+
|
47
|
+
# Some other possibile dependencies found in the java project
|
48
|
+
#require 'neo4j/spatial/jars/not-needed/commons-logging-1.1.1.jar'
|
49
|
+
#require 'neo4j/spatial/jars/not-needed/junit-4.4.jar'
|
50
|
+
#require 'neo4j/spatial/jars/not-needed/xml-apis-1.0.b2.jar'
|
51
|
+
|
52
|
+
require 'neo4j/spatial/database.rb'
|
53
|
+
require 'neo4j/spatial/layer.rb'
|
54
|
+
require 'neo4j/spatial/shapefile.rb'
|
55
|
+
require 'neo4j/spatial/osm.rb'
|
56
|
+
require 'neo4j/spatial/image.rb'
|