Class: Neo4j::Spatial::Layer

Inherits:
Object
  • Object
show all
Includes:
Database
Defined in:
lib/neo4j/spatial/layer.rb

Overview

This class wraps the spatial database layer class and provides some utilities for wrapping some layer actions normally taken by the SpatialDatabaseService, liking finding layers

Direct Known Subclasses

OSMLayer

Constant Summary collapse

TYPES =
[:unknown, :point, :linestring, :polygon, :multipoint, :multilinestring, :multipolygon]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Database

#batch_inserter, #database, #list_all, #normal_database, #spatial

Constructor Details

#initialize(layer_name, options = {}) ⇒ Layer

Returns a new instance of Layer.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/neo4j/spatial/layer.rb', line 15

def initialize(layer_name,options={})
  database(options)
  @layer_name = layer_name
  @layer = spatial.getLayer(@layer_name)
  unless @layer
    if options[:encoder] && options[:type]
      @layer = spatial.getOrCreateLayer(@layer_name, options[:encoder], options[:type])
    elsif options[:x] && options[:y]
      @layer = spatial.getOrCreatePointLayer(@layer_name, options[:x].to_s, options[:y].to_s)
    else
      @layer = spatial.getOrCreateDefaultLayer(@layer_name)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object



32
33
34
# File 'lib/neo4j/spatial/layer.rb', line 32

def method_missing(symbol,*args,&block)
  @layer.send symbol, *args, &block
end

Instance Attribute Details

#layerObject (readonly)

Returns the value of attribute layer.



14
15
16
# File 'lib/neo4j/spatial/layer.rb', line 14

def layer
  @layer
end

#layer_nameObject (readonly)

Returns the value of attribute layer_name.



14
15
16
# File 'lib/neo4j/spatial/layer.rb', line 14

def layer_name
  @layer_name
end

Class Method Details

.exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/neo4j/spatial/layer.rb', line 61

def self.exist? name
  self.names.grep(name).length > 0
end

.find(name) ⇒ Object



64
65
66
# File 'lib/neo4j/spatial/layer.rb', line 64

def self.find name
  exist?(name) && Layer.new(name)
end

.listObject



56
57
58
59
60
# File 'lib/neo4j/spatial/layer.rb', line 56

def self.list
  Neo4j.started_db.spatial.layer_names.map do |name|
    Layer.new(name)
  end
end

.namesObject



53
54
55
# File 'lib/neo4j/spatial/layer.rb', line 53

def self.names
  Neo4j.started_db.spatial.layer_names
end

Instance Method Details

#describeObject



41
42
43
# File 'lib/neo4j/spatial/layer.rb', line 41

def describe
  %Q{#{@layer.name} (#{type_name}:#{geometry}#{parent ? " from #{parent.name}" : ''})}
end

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/neo4j/spatial/layer.rb', line 35

def empty?
  @layer.index.is_empty
end

#geometryObject



44
45
46
# File 'lib/neo4j/spatial/layer.rb', line 44

def geometry
  Geometry.id_to_string(@layer.geometry_type)
end

#parentObject



47
48
49
# File 'lib/neo4j/spatial/layer.rb', line 47

def parent
  @parent ||= @layer.respond_to?('parent') ? @layer.parent : nil
end

#respond_to?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/neo4j/spatial/layer.rb', line 29

def respond_to?(symbol)
  symbol == :empty? || @layer.respond_to?(symbol)
end

#to_sObject



38
39
40
# File 'lib/neo4j/spatial/layer.rb', line 38

def to_s
  @layer.name
end

#type_nameObject



50
51
52
# File 'lib/neo4j/spatial/layer.rb', line 50

def type_name
  @layer.class.to_s.downcase.gsub(/.*[\.\:](\w+)layer.*/){|m| $1}
end