Class: GeoRuby::SimpleFeatures::GeometryFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_ruby/simple_features/geometry_factory.rb

Overview

Creates a new geometry according to constructions received from a parser, for example EWKBParser.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeometryFactory

Returns a new instance of GeometryFactory.


9
10
11
12
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 9

def initialize
  @geometry = nil
  @geometry_stack = []
end

Instance Attribute Details

#geometryObject (readonly)

the built geometry


7
8
9
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 7

def geometry
  @geometry
end

Instance Method Details

#abort_geometryObject

abort a geometry


79
80
81
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 79

def abort_geometry
  reset
end

#add_point_x_y(x, y) ⇒ Object

add a 2D point to the current geometry


21
22
23
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 21

def add_point_x_y(x, y)
  @geometry_stack.last.set_x_y(x, y)
end

#add_point_x_y_m(x, y, m) ⇒ Object

add a 2D point with M to the current geometry


41
42
43
44
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 41

def add_point_x_y_m(x, y, m)
  @geometry_stack.last.set_x_y(x, y)
  @geometry_stack.last.m = m
end

#add_point_x_y_z(x, y, z) ⇒ Object

add a 3D point to the current geometry


31
32
33
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 31

def add_point_x_y_z(x, y, z)
  @geometry_stack.last.set_x_y_z(x, y, z)
end

#add_point_x_y_z_m(x, y, z, m) ⇒ Object

add a 3D point with M to the current geometry


52
53
54
55
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 52

def add_point_x_y_z_m(x, y, z, m)
  @geometry_stack.last.set_x_y_z(x, y, z)
  @geometry_stack.last.m = m
end

#add_points_x_y(xy) ⇒ Object

add 2D points to the current geometry


26
27
28
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 26

def add_points_x_y(xy)
  xy.each_slice(2) { |slice| add_point_x_y(*slice) }
end

#add_points_x_y_m(xym) ⇒ Object

add 2D points with M to the current geometry


47
48
49
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 47

def add_points_x_y_m(xym)
  xym.each_slice(3) { |slice| add_point_x_y_m(*slice) }
end

#add_points_x_y_z(xyz) ⇒ Object

add 3D points to the current geometry


36
37
38
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 36

def add_points_x_y_z(xyz)
  xyz.each_slice(3) { |slice| add_point_x_y_z(*slice) }
end

#add_points_x_y_z_m(xyzm) ⇒ Object

add 3D points with M to the current geometry


58
59
60
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 58

def add_points_x_y_z_m(xyzm)
  xyzm.each_slice(4) { |slice| add_point_x_y_z_m(*slice) }
end

#begin_geometry(geometry_type, srid = DEFAULT_SRID) ⇒ Object

begin a geometry of type geometry_type


63
64
65
66
67
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 63

def begin_geometry(geometry_type, srid = DEFAULT_SRID)
  geometry = geometry_type.new(srid)
  @geometry = geometry if @geometry.nil?
  @geometry_stack << geometry
end

#end_geometry(with_z = false, with_m = false) ⇒ Object

terminates the current geometry


70
71
72
73
74
75
76
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 70

def end_geometry(with_z = false, with_m = false)
  @geometry = @geometry_stack.pop
  @geometry.with_z = with_z
  @geometry.with_m = with_m
  # add the newly defined geometry to its parent if there is one
  @geometry_stack.last << geometry unless @geometry_stack.empty?
end

#resetObject

resets the factory


15
16
17
18
# File 'lib/geo_ruby/simple_features/geometry_factory.rb', line 15

def reset
  @geometry = nil
  @geometry_stack = []
end