Sha256: 56b0e70dbb94c05e4149919f0f5dd234e6cc3e694a1f4ca6165814bde79c118f

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

require 'neo4j/spatial/database'

java_import org.neo4j.gis.spatial.Constants
java_import org.neo4j.gis.spatial.SpatialDatabaseService

module Neo4j
  module Spatial
    
    # 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 
    class Layer
      TYPES = [:unknown, :point, :linestring, :polygon, :multipoint, :multilinestring, :multipolygon]
      include Database
      attr_reader :layer_name, :layer
      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
      def respond_to?(symbol)
        symbol == :empty? || @layer.respond_to?(symbol)
      end
      def method_missing(symbol,*args,&block)
        @layer.send symbol, *args, &block
      end
      def empty?
        @layer.index.is_empty
      end
      def to_s
        @layer.name
      end
      def type_name
        @layer.class.to_s.downcase.gsub(/.*[\.\:](\w+)layer.*/){|m| $1}
      end
      def self.names
        Neo4j.started_db.spatial.layer_names
      end
      def self.list
        Neo4j.started_db.spatial.layer_names.map do |name|
          Layer.new(name)
        end
      end
      def self.exist? name
        self.names.grep(name).length > 0
      end
      def self.find name
        exist?(name) && Layer.new(name)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
neo4j-spatial-0.0.2-java lib/neo4j/spatial/layer.rb
neo4j-spatial-0.0.1-java lib/neo4j/spatial/layer.rb