Class: Neo4j::Spatial::ImageExporter

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

Instance Method Summary collapse

Methods included from Database

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

Constructor Details

#initialize(options = {}) ⇒ ImageExporter

Returns a new instance of ImageExporter.



9
10
11
12
13
14
15
16
17
# File 'lib/neo4j/spatial/image.rb', line 9

def initialize(options={})
  default(options)
  database(options)
  @exporter = org.neo4j.gis.spatial.geotools.data.StyledImageExporter.new(@db.graph)
  @exporter.setExportDir(options[:dir])
  @exporter.setZoom(options[:zoom].to_f)
  @exporter.setOffset((options[:offset_x].to_f || options[:offset]).to_f, (options[:offset_y].to_f || options[:offset]).to_f)
  @exporter.setSize(options[:width].to_i, options[:height].to_i)
end

Instance Method Details

#default(options) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/neo4j/spatial/image.rb', line 18

def default(options)
  options[:dir] ||= "target/export"
  options[:zoom] ||= 3.0
  options[:offset] ||= 0.0
  options[:width] ||= 600
  options[:height] ||= 400
end

#export(layer_name, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/neo4j/spatial/image.rb', line 25

def export(layer_name,options={})
  @layer_name = layer_name
  options[:path] ||= layer_name+'.png'
  if block_given?
    puts "block is given"
  end
  if options[:sld].nil?
    puts "SLD nil"
  end
  if options[:sld].nil? && block_given?
    Tempfile.open 'neo4j-spatial-sld' do |out|
      options[:sld] = out.path
      sld = Amanzi::SLD::Document.new layer_name
      yield sld
      out.puts sld.to_xml :tab => '  '
    end
  end
  options[:sld] ||= 'neo.sld.xml'
  puts "Exporting #{layer_name} to #{options[:path]} using style #{options[:sld]}"
  @exporter.saveLayerImage(layer_name, options[:sld], options[:path])
end

#formatObject



46
47
48
# File 'lib/neo4j/spatial/image.rb', line 46

def format
  "PNG"
end

#to_sObject



49
50
51
# File 'lib/neo4j/spatial/image.rb', line 49

def to_s
  @layer_name || format
end