Skip to content

Commit 855f54a

Browse files
committed
add feature/field feature/schema
1 parent 8fea688 commit 855f54a

4 files changed

Lines changed: 65 additions & 3 deletions

File tree

lib/geoscript/feature.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
require 'feature/field'
1+
require 'feature/field'
2+
require 'feature/schema'

lib/geoscript/feature/feature.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module GeoScript
22
module Feature
33
class Feature
4+
45
end
56
end
67
end

lib/geoscript/feature/schema.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,61 @@
1+
java_import org.opengis.feature.type.FeatureType
2+
java_import org.opengis.feature.type.GeometryDescriptor
3+
java_import org.geotools.feature.NameImpl
4+
java_import org.geotools.feature.simple.SimpleFeatureTypeBuilder
5+
16
module GeoScript
27
module Feature
38
class Schema
9+
include GeoScript::Feature
10+
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+
else
22+
if field.instance_of? Hash
23+
name, type = field.keys.first, field.values.first
24+
elsif field.instance_of? Array
25+
name, type = field[0], field[1]
26+
27+
if type.kind_of? GeoScript::Geom
28+
proj = GeoScript::Projection.new(field[2]) if field[2]
29+
else
30+
raise 'Invalid type specified. Must be of type GeoScript::Geom::*'
31+
end
32+
end
33+
end
34+
type_builder.crs proj if proj
35+
type_builder.add name, type.java_class
36+
@feature_type = type_builder.build_feature_type
37+
end
38+
else
39+
raise "No fields specified for feature type: #{type}"
40+
end
41+
end
42+
43+
def get_name
44+
@feature_type.name.local_part
45+
end
46+
47+
def get_uri
48+
@feature_type.name.namespaceURI
49+
end
50+
51+
def get_proj
52+
crs = @feature_type.coordinate_reference_system
53+
GeoScript::Projection.new crs if crs
54+
end
55+
56+
def get(name)
57+
ad = @feature_type.get_descriptor name
58+
end
459
end
560
end
661
end

lib/geoscript/geom/point.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ def initialize(*coords)
1212
if coords.first.kind_of? JTSPoint
1313
p = coords.first
1414
else
15-
c = Coordinate.new coords[0], coords[1]
16-
c.z = coords[2] if coords[2]
15+
if coords.empty?
16+
c = Coordinate.new 0, 0
17+
else
18+
c = Coordinate.new coords[0], coords[1]
19+
c.z = coords[2] if coords[2]
20+
end
21+
1722
p = GEOM_FACTORY.create_point c
1823
end
1924
super p.coordinate_sequence, GEOM_FACTORY

0 commit comments

Comments
 (0)