Class: RGeo::Geographic::Factory

Inherits:
Object
  • Object
show all
Includes:
Feature::Factory::Instance
Defined in:
lib/rgeo/geographic/factory.rb

Overview

This class implements the various factories for geography features. See methods of the RGeo::Geographic module for the API for creating geography factories.

Instance Method Summary collapse

Constructor Details

#initialize(impl_prefix_, opts_ = {}) ⇒ Factory

:nodoc:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rgeo/geographic/factory.rb', line 51

def initialize(impl_prefix_, opts_={})  # :nodoc:
  @impl_prefix = impl_prefix_
  @point_class = Geographic.const_get("#{impl_prefix_}PointImpl")
  @line_string_class = Geographic.const_get("#{impl_prefix_}LineStringImpl")
  @linear_ring_class = Geographic.const_get("#{impl_prefix_}LinearRingImpl")
  @line_class = Geographic.const_get("#{impl_prefix_}LineImpl")
  @polygon_class = Geographic.const_get("#{impl_prefix_}PolygonImpl")
  @geometry_collection_class = Geographic.const_get("#{impl_prefix_}GeometryCollectionImpl")
  @multi_point_class = Geographic.const_get("#{impl_prefix_}MultiPointImpl")
  @multi_line_string_class = Geographic.const_get("#{impl_prefix_}MultiLineStringImpl")
  @multi_polygon_class = Geographic.const_get("#{impl_prefix_}MultiPolygonImpl")
  @support_z = opts_[:has_z_coordinate] ? true : false
  @support_m = opts_[:has_m_coordinate] ? true : false
  @srid = opts_[:srid] || 4326
  @proj4 = opts_[:proj4]
  if CoordSys::Proj4.supported?
    if @proj4.kind_of?(::String) || @proj4.kind_of?(::Hash)
      @proj4 = CoordSys::Proj4.create(@proj4)
    end
  else
    @proj4 = nil
  end
  @coord_sys = opts_[:coord_sys]
  if @coord_sys.kind_of?(::String)
    @coord_sys = CoordSys::CS.create_from_wkt(@coord_sys) rescue nil
  end
end

Instance Method Details

#_set_projector(projector_) ⇒ Object

:nodoc:



80
81
82
# File 'lib/rgeo/geographic/factory.rb', line 80

def _set_projector(projector_)  # :nodoc:
  @projector = projector_
end

#collection(elems_) ⇒ Object

See ::RGeo::Feature::Factory#collection



243
244
245
# File 'lib/rgeo/geographic/factory.rb', line 243

def collection(elems_)
  @geometry_collection_class.new(self, elems_) rescue nil
end

#coord_sysObject

See ::RGeo::Feature::Factory#coord_sys



278
279
280
# File 'lib/rgeo/geographic/factory.rb', line 278

def coord_sys
  @coord_sys
end

#eql?(rhs_) ⇒ Boolean Also known as: ==

Equivalence test.

Returns:

  • (Boolean)


87
88
89
90
91
92
93
# File 'lib/rgeo/geographic/factory.rb', line 87

def eql?(rhs_)
  rhs_.is_a?(Geographic::Factory) &&
    @impl_prefix == rhs_.instance_variable_get(:@impl_prefix) &&
    @support_z == rhs_.instance_variable_get(:@support_z) &&
    @support_m == rhs_.instance_variable_get(:@support_m) &&
    @proj4 == rhs_.instance_variable_get(:@proj4)
end

#has_projection?Boolean

Returns true if this factory supports a projection.

Returns:

  • (Boolean)


106
107
108
# File 'lib/rgeo/geographic/factory.rb', line 106

def has_projection?
  !@projector.nil?
end

#line(start_, end_) ⇒ Object

See ::RGeo::Feature::Factory#line



222
223
224
# File 'lib/rgeo/geographic/factory.rb', line 222

def line(start_, end_)
  @line_class.new(self, start_, end_) rescue nil
end

#line_string(points_) ⇒ Object

See ::RGeo::Feature::Factory#line_string



215
216
217
# File 'lib/rgeo/geographic/factory.rb', line 215

def line_string(points_)
  @line_string_class.new(self, points_) rescue nil
end

#linear_ring(points_) ⇒ Object

See ::RGeo::Feature::Factory#linear_ring



229
230
231
# File 'lib/rgeo/geographic/factory.rb', line 229

def linear_ring(points_)
  @linear_ring_class.new(self, points_) rescue nil
end

#multi_line_string(elems_) ⇒ Object

See ::RGeo::Feature::Factory#multi_line_string



257
258
259
# File 'lib/rgeo/geographic/factory.rb', line 257

def multi_line_string(elems_)
  @multi_line_string_class.new(self, elems_) rescue nil
end

#multi_point(elems_) ⇒ Object

See ::RGeo::Feature::Factory#multi_point



250
251
252
# File 'lib/rgeo/geographic/factory.rb', line 250

def multi_point(elems_)
  @multi_point_class.new(self, elems_) rescue nil
end

#multi_polygon(elems_) ⇒ Object

See ::RGeo::Feature::Factory#multi_polygon



264
265
266
# File 'lib/rgeo/geographic/factory.rb', line 264

def multi_polygon(elems_)
  @multi_polygon_class.new(self, elems_) rescue nil
end

#parse_wkb(str_) ⇒ Object

See ::RGeo::Feature::Factory#parse_wkb



201
202
203
# File 'lib/rgeo/geographic/factory.rb', line 201

def parse_wkb(str_)
  WKRep::WKBParser.new(self).parse(str_)
end

#parse_wkt(str_) ⇒ Object

See ::RGeo::Feature::Factory#parse_wkt



194
195
196
# File 'lib/rgeo/geographic/factory.rb', line 194

def parse_wkt(str_)
  WKRep::WKTParser.new(self).parse(str_)
end

#point(x_, y_, *extra_) ⇒ Object

See ::RGeo::Feature::Factory#point



208
209
210
# File 'lib/rgeo/geographic/factory.rb', line 208

def point(x_, y_, *extra_)
  @point_class.new(self, x_, y_, *extra_) rescue nil
end

#polygon(outer_ring_, inner_rings_ = nil) ⇒ Object

See ::RGeo::Feature::Factory#polygon



236
237
238
# File 'lib/rgeo/geographic/factory.rb', line 236

def polygon(outer_ring_, inner_rings_=nil)
  @polygon_class.new(self, outer_ring_, inner_rings_) rescue nil
end

#proj4Object

See ::RGeo::Feature::Factory#proj4



271
272
273
# File 'lib/rgeo/geographic/factory.rb', line 271

def proj4
  @proj4
end

#project(geometry_) ⇒ Object

Projects the given geometry into the projected coordinate space, and returns the projected geometry. Returns nil if this factory does not support a projection. Raises Error::InvalidGeometry if the given geometry is not of this factory.



125
126
127
128
129
130
131
# File 'lib/rgeo/geographic/factory.rb', line 125

def project(geometry_)
  return nil unless @projector
  unless geometry_.factory == self
    raise Error::InvalidGeometry, 'Wrong geometry type'
  end
  @projector.project(geometry_)
end

#projection_factoryObject

Returns the factory for the projected coordinate space, or nil if this factory does not support a projection.



114
115
116
# File 'lib/rgeo/geographic/factory.rb', line 114

def projection_factory
  @projector ? @projector.projection_factory : nil
end

#projection_limits_windowObject

Returns a ProjectedWindow specifying the limits of the domain of the projection space. Returns nil if this factory does not support a projection, or the projection limits are not known.



164
165
166
167
168
169
170
171
172
173
# File 'lib/rgeo/geographic/factory.rb', line 164

def projection_limits_window
  if @projector
    unless defined?(@projection_limits_window)
      @projection_limits_window = @projector.limits_window
    end
    @projection_limits_window
  else
    nil
  end
end

#projection_wraps?Boolean

Returns true if this factory supports a projection and the projection wraps its x (easting) direction. For example, a Mercator projection wraps, but a local projection that is valid only for a small area does not wrap. Returns nil if this factory does not support or a projection, or if it is not known whether or not it wraps.

Returns:

  • (Boolean)


154
155
156
# File 'lib/rgeo/geographic/factory.rb', line 154

def projection_wraps?
  @projector ? @projector.wraps? : nil
end

#property(name_) ⇒ Object

See ::RGeo::Feature::Factory#property



178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/rgeo/geographic/factory.rb', line 178

def property(name_)
  case name_
  when :has_z_coordinate
    @support_z
  when :has_m_coordinate
    @support_m
  when :is_geographic
    true
  else
    nil
  end
end

#sridObject

Returns the srid reported by this factory.



99
100
101
# File 'lib/rgeo/geographic/factory.rb', line 99

def srid
  @srid
end

#unproject(geometry_) ⇒ Object

Reverse-projects the given geometry from the projected coordinate space into lat-long space. Raises Error::InvalidGeometry if the given geometry is not of the projection defined by this factory.



139
140
141
142
143
144
# File 'lib/rgeo/geographic/factory.rb', line 139

def unproject(geometry_)
  unless @projector && @projector.projection_factory == geometry_.factory
    raise Error::InvalidGeometry, 'You can unproject only features that are in the projected coordinate space.'
  end
  @projector.unproject(geometry_)
end