Sha256: 08d6fc0c7d8262e3e7a8e211cf2167e23dea42626155b71e118e5aad5aacbc7e

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

require 'neo4j/spatial/listener'
require 'neo4j/spatial/database'

# Utilities for importing and exporting ESRI Shapefile data

module Neo4j
  module Spatial
    
    # This class facilitates importing datasets in the ESRI Shapefile format
    class ShapefileImporter
      include Listener
      include Database
      def initialize(options={})
        database(options)
        @importer = org.neo4j.gis.spatial.ShapefileImporter.new(@db.graph, self, @commit)
      end
      def import(shp_path,layer_name=nil)
        @shp_path = shp_path
        layer_name ||= shp_path.split(/[\\\/]+/)[-1].gsub(/\.\w+$/,'')
        @importer.import_file @shp_path, layer_name
      end
      def to_s
        @shp_path.to_s
      end
    end

    # This class facilitates importing datasets in the ESRI Shapefile format
    class ShapefileExporter
      include Database
      def initialize(options={})
        options[:dir] ||= "target/export"
        database(options)
        @exporter = org.neo4j.gis.spatial.ShapefileExporter.new(@db.graph)
        @exporter.setExportDir(options[:dir])
      end
      def export(layer_name,options={})
        @layer_name = layer_name
        options[:path] ||= layer_name+'.shp'
        puts "Exporting #{layer_name} to #{options[:path]}"
        @exporter.exportLayer(layer_name, options[:path])
      end
      def format
        "ESRI Shapefile"
      end
      def to_s
        @layer_name || format
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
neo4j-spatial-0.0.6-java lib/neo4j/spatial/shapefile.rb
neo4j-spatial-0.0.5-java lib/neo4j/spatial/shapefile.rb
neo4j-spatial-0.0.4-java lib/neo4j/spatial/shapefile.rb
neo4j-spatial-0.0.2-java lib/neo4j/spatial/shapefile.rb
neo4j-spatial-0.0.1-java lib/neo4j/spatial/shapefile.rb