Skip to content

Commit 6c75a99

Browse files
author
Scooter Wadsworth
committed
start work with schema -> field -> feature
1 parent 4c5399b commit 6c75a99

File tree

7 files changed

+69
-21
lines changed

7 files changed

+69
-21
lines changed

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
source :rubygems
1+
source 'https://rubygems.org'
22

3-
gemspec
3+
gemspec

lib/geoscript.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
java.lang.System.set_property 'org.geotools.referencing.forceXY', 'true'
1717
end
1818

19-
Hints.put_system_default Hints::FORCE_LONGITUDE_FIRST_AXIS_ORDER, java.lang.Boolean.new(true)
19+
Hints.put_system_default Hints::FORCE_LONGITUDE_FIRST_AXIS_ORDER, java.lang.Boolean.new(true)
2020

2121
require 'geoscript/version'
2222
require 'geoscript/util'
@@ -28,4 +28,4 @@
2828
require 'geoscript/workspace'
2929
else
3030
warn "GeoScript requires JRuby (http://jruby.org)"
31-
end
31+
end

lib/geoscript/feature/feature.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
module GeoScript
55
class Feature
6-
def initialize(attrs = nil, id = nil, schema = nil)
6+
def initialize(attrs=nil, id=nil, schema=nil)
77
raise 'No attributes specified for feature' unless attrs
8-
8+
99
unless attrs.kind_of? GeoScript::Feature
1010
unless schema
1111
if attrs.instance_of? Hash
1212
schema_attrs = []
1313
attrs.each do |k, v|
14-
schema_attrs << {name: k, type: v.to_java.java_class}
14+
schema_attrs << {name: k.to_s, type: v.to_java.java_class}
1515
end
1616
@schema = GeoScript::Schema.new('feature', schema_attrs)
1717
elsif attrs.instance_of? Array
@@ -28,7 +28,7 @@ def initialize(attrs = nil, id = nil, schema = nil)
2828
end
2929

3030
sfb = SimpleFeatureBuilder.new @schema.feature_type
31-
attrs.each {|k, v| sfb.set(k, v)}
31+
attrs.each {|k, v| sfb.set(k.to_s, v)}
3232
@feature = sfb.build_feature id
3333
else
3434
@feature = attrs
@@ -40,12 +40,24 @@ def id
4040
@feature.identifier.to_s
4141
end
4242

43-
def geom
43+
def get_geom
4444
@feature.default_geometry
4545
end
46+
alias_method :geom, :get_geom
4647

4748
def set_geom(geom)
4849
@feature.default_geometry = geom
4950
end
51+
52+
def get_attributes
53+
attributes = {}
54+
55+
@schema.fields.each do |field|
56+
attributes[field] = @feature.get_attribute(field)
57+
end
58+
59+
attributes
60+
end
61+
alias_method :attributes, :get_attributes
5062
end
51-
end
63+
end

lib/geoscript/feature/field.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
module GeoScript
2-
Field = Struct.new(:name, :type, :proj)
3-
end
2+
class Field
3+
attr_accessor :name, :type, :proj
4+
5+
def initialize(name, type, proj=nil)
6+
@name = name
7+
@type = type
8+
@proj = proj
9+
end
10+
11+
def to_s
12+
"#{@name}: #{@type}"
13+
end
14+
15+
def ==(other)
16+
other.name == @name && other.type == @type && other.proj == @proj
17+
end
18+
end
19+
end

lib/geoscript/feature/schema.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module GeoScript
77
class Schema
88
attr_accessor :feature_type
99

10-
def initialize(name = nil, fields = [], type = nil, uri = 'http://geoscript.org/feature')
10+
def initialize(name=nil, fields=[], type=nil, uri='http://geoscript.org/feature')
1111
if name && !fields.empty?
1212
type_builder = SimpleFeatureTypeBuilder.new
1313
type_builder.set_name NameImpl.new(name)
@@ -54,20 +54,27 @@ def initialize(name = nil, fields = [], type = nil, uri = 'http://geoscript.org/
5454
end
5555
end
5656

57-
def name
57+
def get_name
5858
@feature_type.name.local_part
5959
end
60+
alias_method :name, :get_name
61+
62+
def get_geom
63+
@feature_type.geometry_descriptor.local_name
64+
end
65+
alias_method :geom, :get_geom
6066

6167
def uri
6268
@feature_type.name.namespaceURI
6369
end
6470

65-
def proj
71+
def get_proj
6672
crs = @feature_type.coordinate_reference_system
6773
GeoScript::Projection.new crs if crs
6874
end
75+
alias_method :proj, :get_proj
6976

70-
def fields
77+
def get_fields
7178
fields = []
7279

7380
@feature_type.attribute_descriptors.each do |ad|
@@ -76,6 +83,7 @@ def fields
7683

7784
fields
7885
end
86+
alias_method :fields, :get_fields
7987

8088
def get(name)
8189
ad = @feature_type.get_descriptor name

lib/geoscript/projection.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def initialize(proj)
1414
@crs = proj.crs
1515
elsif proj.kind_of? String
1616
@crs = CRS.decode proj
17-
17+
1818
if @crs.nil?
1919
@crs = CRS.parseWKT proj
20-
20+
2121
if @crs.nil?
2222
raise "Unable to determine projection from #{proj}"
2323
end
@@ -61,12 +61,24 @@ def transform(obj, dest)
6161
new_geom = geometry_transform.transform obj
6262
geom_type = new_geom.class.to_s.split('::').last
6363
klass = ['GeoScript', 'Geom', geom_type].inject(Module) {|acc, val| acc.const_get(val)}
64-
klass.new(new_geom)
64+
klass.new(new_geom)
6565
end
6666
end
6767

6868
def self.reproject(obj, from_crs, to_crs)
6969
Projection.new(from_crs).transform obj, to_crs
7070
end
71+
72+
def self.projections
73+
CRS.get_supported_codes('epsg').each do |code|
74+
begin
75+
Projection.new "epsg:#{code}"
76+
rescue Java::OrgOpengisReferencing::NoSuchAuthorityCodeException
77+
p "code: #{code} -> no such authority"
78+
rescue Java::OrgOpengisReferencing::FactoryException => e
79+
p "exception: #{e}"
80+
end
81+
end
82+
end
7183
end
72-
end
84+
end

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<version>0.0.1-SNAPSHOT</version>
88

99
<properties>
10-
<gt.version>8.6</gt.version>
10+
<gt.version>9.0</gt.version>
1111
</properties>
1212

1313
<repositories>

0 commit comments

Comments
 (0)