Skip to content

Commit 4c5399b

Browse files
committed
fix geometry object creation from {wkt, wkb, json}
1 parent e9d814a commit 4c5399b

File tree

7 files changed

+40
-18
lines changed

7 files changed

+40
-18
lines changed

Rakefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
task :geoscript do
1+
$:.unshift File.expand_path('../lib', __FILE__)
2+
require 'geoscript/version'
3+
4+
task :build do
5+
system 'gem build geoscript.gemspec'
6+
end
7+
8+
task :release => :build do
9+
system "gem push geoscript-#{GeoScript::VERSION}.gem"
10+
end
11+
12+
task :console do
213
ARGV.clear
314
require File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'geoscript'))
415
require 'irb'
516
IRB.start
6-
end
17+
end

geoscript.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
33
require 'geoscript/version'
44

55
Gem::Specification.new do |gem|
6-
gem.name = 'geoscript-ruby'
6+
gem.name = 'geoscript'
77
gem.version = GeoScript::VERSION
88
gem.summary = 'GeoScript is a library for making use of GeoTools from JRuby easier and more fun.'
99
gem.description = 'GeoScript for JRuby - makes using GeoTools from JRuby easier and more fun.'
@@ -13,11 +13,11 @@ Gem::Specification.new do |gem|
1313
gem.authors = ['Scooter Wadsworth']
1414
gem.email = ['scooterwadsworth@gmail.com']
1515
gem.homepage = 'https://github.com/scooterw/geoscript-ruby'
16-
16+
1717
gem.files = Dir['README.md', 'lib/**/*', 'spec/support/**/*']
1818
gem.require_paths = ['lib']
1919

2020
gem.add_development_dependency 'rake'
2121
gem.add_development_dependency 'rspec'
2222
gem.add_development_dependency 'guard-rspec'
23-
end
23+
end

lib/geoscript/geom/geom.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,23 @@ def self.get_bounds(geom)
3434
end
3535

3636
def self.enhance(geom)
37-
geom.bounds = Geom.get_bounds geom
37+
geom.bounds = get_bounds(geom)
3838
end
3939

40-
def self.to_wkt(geom)
41-
GeoScript::IO::Geom.write_wkt geom
40+
def self.to_geoscript_geom(geom)
41+
const_get(geom.geometry_type).new(geom)
42+
end
43+
44+
def self.from_json(json)
45+
to_geoscript_geom(GeoScript::IO::Geom.read_json(json))
4246
end
4347

4448
def self.from_wkt(wkt)
45-
GeoScript::IO::Geom.read_wkt wkt
49+
to_geoscript_geom(GeoScript::IO::Geom.read_wkt(wkt))
50+
end
51+
52+
def self.from_wkb(wkb)
53+
to_geoscript_geom(GeoScript::IO::Geom.read_wkb(wkb))
4654
end
4755
end
48-
end
56+
end

lib/geoscript/geom/linestring.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class LineString < JTSLineString
1111
def initialize(*coords)
1212
if coords.size == 1
1313
if coords.first.kind_of? JTSLineString
14+
ls = coords.first
1415
elsif coords.kind_of? Array
1516
if coords.first.kind_of? Array
1617
l = []
@@ -58,4 +59,4 @@ def to_json
5859
end
5960
end
6061
end
61-
end
62+
end

lib/geoscript/geom/multilinestring.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def initialize(*line_strings)
1212

1313
if line_strings.first.kind_of? JTSMultiLineString
1414
multi_line_string_geom = line_strings.first
15-
for i in range(0...multi_line_string_geom.num_geometries)
15+
16+
for i in (0...multi_line_string_geom.num_geometries)
1617
strings << multi_line_string_geom.get_geometry_n(i)
1718
end
1819
else
@@ -45,4 +46,4 @@ def to_json
4546
end
4647
end
4748
end
48-
end
49+
end

lib/geoscript/geom/multipoint.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ def initialize(*points)
1111
feature_points = []
1212

1313
if points.first.kind_of? JTSMultiPoint
14-
multi_point_geom = point.first
15-
for i in (0...multi_point_geom.num_geometries)
16-
feature_points << multi_point_geom.get_geometry_n(i)
14+
mp_geom = points.first
15+
16+
for i in (0...mp_geom.num_geometries)
17+
feature_points << mp_geom.get_geometry_n(i)
1718
end
1819
else
1920
points.each do |point|
@@ -45,4 +46,4 @@ def to_json
4546
end
4647
end
4748
end
48-
end
49+
end

lib/geoscript/io/geom/json.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ def self.read_json(json)
1212
end
1313
end
1414
end
15-
end
15+
end

0 commit comments

Comments
 (0)