44java_import org . geotools . feature . simple . SimpleFeatureTypeBuilder
55
66module GeoScript
7- module Feature
8- class Schema
9- include GeoScript ::Feature
7+ class Schema
8+ attr_accessor :feature_type
109
11- attr_accessor :feature_type
12-
13- def initialize ( name = nil , fields = [ ] , type = nil , uri = 'http://geoscript.org/feature' )
14- if name && !fields . empty?
15- type_builder = SimpleFeatureTypeBuilder . new
16- type_builder . set_name NameImpl . new ( name )
17- type_builder . setNamespaceURI uri
18- fields . each do |field |
19- if field . instance_of? GeoScript ::Feature ::Field
20- name , type , proj = field . name , field . type , field . proj
21- elsif field . instance_of? Hash
22- if field [ :name ] && field [ :type ]
23- name , type = field [ :name ] , field [ :type ]
24- else
25- name , type = field . keys . first , field . values . first
26- end
10+ def initialize ( name = nil , fields = [ ] , type = nil , uri = 'http://geoscript.org/feature' )
11+ if name && !fields . empty?
12+ type_builder = SimpleFeatureTypeBuilder . new
13+ type_builder . set_name NameImpl . new ( name )
14+ type_builder . setNamespaceURI uri
15+ fields . each do |field |
16+ if field . instance_of? GeoScript ::Field
17+ name , type , proj = field . name , field . type , field . proj
18+ elsif field . instance_of? Hash
19+ if field [ :name ] && field [ :type ]
20+ name , type = field [ :name ] , field [ :type ]
21+ else
22+ name , type = field . keys . first , field . values . first
23+ end
2724
28- if type . name . match /GeoScript::Geom/
29- proj = GeoScript ::Projection . new ( field [ :proj ] ) if field [ :proj ]
30- end
31- elsif field . instance_of? Array
32- name , type = field [ 0 ] , field [ 1 ]
25+ if type . name . match /GeoScript::Geom/
26+ proj = GeoScript ::Projection . new ( field [ :proj ] ) if field [ :proj ]
27+ end
28+ elsif field . instance_of? Array
29+ name , type = field [ 0 ] , field [ 1 ]
3330
34- if type . name . match /GeoScript::Geom/
35- proj = GeoScript ::Projection . new ( field [ 2 ] ) if field [ 2 ]
36- end
31+ if type . name . match /GeoScript::Geom/
32+ proj = GeoScript ::Projection . new ( field [ 2 ] ) if field [ 2 ]
3733 end
38- type_builder . crs proj if proj
39- type_builder . add name , type . to_java . java_class
40- p type_builder . attributes
41- end
42- @feature_type = type_builder . build_feature_type
43- else
44- if !name && fields . empty?
45- raise "No name specified & No fields specified for type: #{ type } "
46- elsif fields . empty?
47- raise "No fields specified for type: #{ type } " if fields . empty?
48- elsif !name
49- raise 'No name specified'
5034 end
35+ type_builder . crs proj if proj
36+ type_builder . add name , type . to_java . java_class
37+ end
38+ @feature_type = type_builder . build_feature_type
39+ else
40+ if !name && fields . empty?
41+ raise "No name specified & No fields specified for type: #{ type } "
42+ elsif fields . empty?
43+ raise "No fields specified for type: #{ type } " if fields . empty?
44+ elsif !name
45+ raise 'No name specified'
5146 end
5247 end
48+ end
5349
54- def name
55- @feature_type . name . local_part
56- end
57-
58- def uri
59- @feature_type . name . namespaceURI
60- end
50+ def name
51+ @feature_type . name . local_part
52+ end
6153
62- def proj
63- crs = @feature_type . coordinate_reference_system
64- GeoScript ::Projection . new crs if crs
65- end
54+ def uri
55+ @feature_type . name . namespaceURI
56+ end
6657
67- def fields
68- fields = [ ]
58+ def proj
59+ crs = @feature_type . coordinate_reference_system
60+ GeoScript ::Projection . new crs if crs
61+ end
6962
70- @feature_type . attribute_descriptors . each do |ad |
71- fields << self . get ( ad . local_name )
72- end
63+ def fields
64+ fields = [ ]
7365
74- fields
66+ @feature_type . attribute_descriptors . each do |ad |
67+ fields << self . get ( ad . local_name )
7568 end
7669
77- def get ( name )
78- @feature_type . get_descriptor name
79- end
70+ fields
71+ end
72+
73+ def get ( name )
74+ @feature_type . get_descriptor name
8075 end
8176 end
8277end
0 commit comments