Module: GeoScript::Geom::IO

Includes:
Util
Defined in:
lib/geoscript/geom/io/wkb.rb,
lib/geoscript/geom/io/wkt.rb,
lib/geoscript/geom/io/json.rb

Class Method Summary collapse

Class Method Details

.read_json(json) ⇒ Object



10
11
12
# File 'lib/geoscript/geom/io/json.rb', line 10

def self.read_json(json)
  GeometryJSON.new.read json.to_java
end

.read_wkb(wkb) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/geoscript/geom/io/wkb.rb', line 14

def self.read_wkb(wkb)
  if wkb.kind_of? String
    wkb = WKBReader.hex_to_bytes wkb
  elsif wkb.kind_of? Array
    # .to_java(java.lang.Byte) does not seem to work
    # this is very hacky
    wkb = WKBWriter.bytes_to_hex wkb
    wkb = WKBReader.hex_to_bytes wkb
  end
  WKBReader.new.read wkb
end

.read_wkt(wkt) ⇒ Object



7
8
9
# File 'lib/geoscript/geom/io/wkt.rb', line 7

def self.read_wkt(wkt)
  WKTReader.new.read wkt
end

.write_json(geom) ⇒ Object



6
7
8
# File 'lib/geoscript/geom/io/json.rb', line 6

def self.write_json(geom)
  GeometryJSON.new.to_string geom
end

.write_wkb(geom) ⇒ Object



9
10
11
12
# File 'lib/geoscript/geom/io/wkb.rb', line 9

def self.write_wkb(geom)
  wkb = WKBWriter.new.write geom
  WKBWriter.bytes_to_hex wkb
end

.write_wkt(geom) ⇒ Object



11
12
13
# File 'lib/geoscript/geom/io/wkt.rb', line 11

def self.write_wkt(geom)
  WKTWriter.new.write geom
end