rgeo 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +9 -7
- data/README.rdoc +7 -5
- data/Version +1 -1
- data/ext/geos_c_impl/factory.c +12 -19
- data/ext/geos_c_impl/factory.h +15 -21
- data/ext/geos_c_impl/geometry.c +19 -36
- data/ext/geos_c_impl/geometry.h +2 -12
- data/ext/geos_c_impl/geometry_collection.c +38 -157
- data/ext/geos_c_impl/geometry_collection.h +2 -12
- data/ext/geos_c_impl/line_string.c +83 -80
- data/ext/geos_c_impl/line_string.h +2 -12
- data/ext/geos_c_impl/main.c +5 -0
- data/ext/geos_c_impl/point.c +2 -12
- data/ext/geos_c_impl/point.h +2 -12
- data/ext/geos_c_impl/polygon.c +5 -14
- data/ext/geos_c_impl/polygon.h +2 -12
- data/ext/geos_c_impl/preface.h +8 -0
- data/lib/rgeo.rb +34 -16
- data/lib/rgeo/{geography/simple_spherical/geometry_collection_impl.rb → cartesian.rb} +19 -26
- data/lib/rgeo/cartesian/calculations.rb +129 -0
- data/lib/rgeo/cartesian/interface.rb +85 -0
- data/lib/rgeo/cartesian/simple_factory.rb +159 -0
- data/lib/rgeo/cartesian/simple_feature_classes.rb +187 -0
- data/lib/rgeo/cartesian/simple_feature_methods.rb +97 -0
- data/lib/rgeo/features.rb +1 -0
- data/lib/rgeo/features/curve.rb +3 -2
- data/lib/rgeo/features/factory.rb +62 -37
- data/lib/rgeo/features/geometry.rb +10 -32
- data/lib/rgeo/features/geometry_collection.rb +3 -2
- data/lib/rgeo/features/line.rb +3 -2
- data/lib/rgeo/features/line_string.rb +3 -2
- data/lib/rgeo/features/linear_ring.rb +3 -2
- data/lib/rgeo/features/multi_curve.rb +3 -2
- data/lib/rgeo/features/multi_line_string.rb +3 -2
- data/lib/rgeo/features/multi_point.rb +3 -2
- data/lib/rgeo/features/multi_polygon.rb +3 -2
- data/lib/rgeo/features/multi_surface.rb +3 -2
- data/lib/rgeo/features/point.rb +3 -2
- data/lib/rgeo/features/polygon.rb +3 -2
- data/lib/rgeo/features/surface.rb +3 -2
- data/lib/rgeo/features/types.rb +198 -0
- data/lib/rgeo/geography.rb +4 -14
- data/lib/rgeo/geography/factory.rb +7 -64
- data/lib/rgeo/geography/{simple_spherical/geometry_methods.rb → helper.rb} +4 -13
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +35 -89
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +22 -31
- data/lib/rgeo/geography/simple_mercator/projector.rb +4 -8
- data/lib/rgeo/geography/simple_spherical/calculations.rb +11 -9
- data/lib/rgeo/geography/simple_spherical/feature_classes.rb +189 -0
- data/lib/rgeo/geography/simple_spherical/{line_string_impl.rb → feature_methods.rb} +16 -64
- data/lib/rgeo/geos/factory.rb +26 -40
- data/lib/rgeo/geos/impl_additions.rb +3 -5
- data/lib/rgeo/{geography/simple_spherical/polygon_impl.rb → impl_helpers.rb} +16 -26
- data/lib/rgeo/impl_helpers/basic_geometry_collection_methods.rb +186 -0
- data/lib/rgeo/impl_helpers/basic_geometry_methods.rb +90 -0
- data/lib/rgeo/impl_helpers/basic_line_string_methods.rb +188 -0
- data/lib/rgeo/impl_helpers/basic_point_methods.rb +149 -0
- data/lib/rgeo/{geography/common/helper.rb → impl_helpers/basic_polygon_methods.rb} +62 -53
- data/lib/rgeo/{geography/common/polygon_methods.rb → impl_helpers/serialization.rb} +50 -42
- data/tests/common/geometry_collection_tests.rb +9 -7
- data/tests/common/multi_line_string_tests.rb +16 -13
- data/tests/common/multi_point_tests.rb +16 -13
- data/tests/common/multi_polygon_tests.rb +8 -6
- data/tests/common/point_tests.rb +1 -2
- data/tests/common/polygon_tests.rb +9 -9
- data/tests/geos/tc_multi_line_string.rb +2 -2
- data/tests/simple_cartesian/tc_calculations.rb +138 -0
- data/tests/simple_cartesian/tc_geometry_collection.rb +68 -0
- data/tests/simple_cartesian/tc_line_string.rb +70 -0
- data/{lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb → tests/simple_cartesian/tc_multi_line_string.rb} +19 -19
- data/{lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb → tests/simple_cartesian/tc_multi_point.rb} +19 -19
- data/{lib/rgeo/geography/common/geometry_methods.rb → tests/simple_cartesian/tc_multi_polygon.rb} +19 -41
- data/{lib/rgeo/geography/simple_spherical/point_impl.rb → tests/simple_cartesian/tc_point.rb} +33 -35
- data/tests/simple_cartesian/tc_polygon.rb +67 -0
- data/tests/simple_spherical/tc_geometry_collection.rb +68 -0
- data/tests/simple_spherical/tc_line_string.rb +10 -171
- data/tests/simple_spherical/tc_multi_line_string.rb +67 -0
- data/{lib/rgeo/geography/simple_spherical/multi_point_impl.rb → tests/simple_spherical/tc_multi_point.rb} +19 -19
- data/tests/simple_spherical/tc_multi_polygon.rb +70 -0
- data/tests/simple_spherical/tc_point.rb +17 -115
- data/tests/simple_spherical/tc_polygon.rb +67 -0
- metadata +46 -18
- data/ext/geos_c_impl/globals.h +0 -58
- data/lib/rgeo/geography/common/geometry_collection_methods.rb +0 -217
- data/lib/rgeo/geography/common/line_string_methods.rb +0 -201
- data/lib/rgeo/geography/common/point_methods.rb +0 -153
data/ext/geos_c_impl/preface.h
CHANGED
data/lib/rgeo.rb
CHANGED
@@ -34,27 +34,20 @@
|
|
34
34
|
;
|
35
35
|
|
36
36
|
|
37
|
-
# The source files that should be required by default.
|
38
|
-
paths_ = [
|
39
|
-
'version',
|
40
|
-
'errors',
|
41
|
-
'features',
|
42
|
-
'geos',
|
43
|
-
'geography',
|
44
|
-
'geo_json',
|
45
|
-
]
|
46
|
-
paths_.each{ |path_| require "rgeo/#{path_}" }
|
47
|
-
|
48
|
-
|
49
37
|
# RGeo is a spatial data library for Ruby.
|
50
38
|
#
|
51
39
|
# The RGeo::Features module contains interface specifications for spatial
|
52
40
|
# objects implemented by RGeo. These interfaces closely follow the OGC
|
53
|
-
# Simple Features Specifiation.
|
41
|
+
# Simple Features Specifiation (SFS).
|
42
|
+
#
|
43
|
+
# The RGeo::Cartesian module provides basic implementations of spatial
|
44
|
+
# objects in a Cartesian (flat) coordinate system. There is a pure ruby
|
45
|
+
# implementation that provides basic services, and there are bridges to
|
46
|
+
# external implementations that support all the SFS operations.
|
54
47
|
#
|
55
|
-
#
|
56
|
-
# the GEOS library
|
57
|
-
#
|
48
|
+
# One of these external bridges is provided by the RGeo::Geos module,
|
49
|
+
# which wraps the GEOS library to provide a full, high-performance
|
50
|
+
# Cartesian geometry implementation.
|
58
51
|
#
|
59
52
|
# The RGeo::Geography module contains spatial implementations that
|
60
53
|
# operate in latitude-longitude coordinates. Several different
|
@@ -63,6 +56,31 @@ paths_.each{ |path_| require "rgeo/#{path_}" }
|
|
63
56
|
#
|
64
57
|
# The RGeo::GeoJSON module contains tools for GeoJSON serialization of
|
65
58
|
# spatial objects.
|
59
|
+
#
|
60
|
+
# Future modules in development include:
|
61
|
+
#
|
62
|
+
# * RGeo::Shapefile, which provides tools for reading and writing
|
63
|
+
# spatial objects in the ESRI shapefile format.
|
64
|
+
# * RGeo::Rails, which provides close integration with Ruby On Rails
|
65
|
+
# for developing location-based web applications.
|
66
|
+
# * RGeo::JTS, which provides a Cartesian SFS implementation backed by
|
67
|
+
# the JTS library (which can run natively in JRuby.)
|
68
|
+
# * RGeo::Geography extensions to provide highly accurate ellipsoidal
|
69
|
+
# geometric calculations, and support arbitrary map projections.
|
66
70
|
|
67
71
|
module RGeo
|
68
72
|
end
|
73
|
+
|
74
|
+
|
75
|
+
# The source files that should be required by default.
|
76
|
+
paths_ = [
|
77
|
+
'version',
|
78
|
+
'errors',
|
79
|
+
'features',
|
80
|
+
'impl_helpers',
|
81
|
+
'geos',
|
82
|
+
'cartesian',
|
83
|
+
'geography',
|
84
|
+
'geo_json',
|
85
|
+
]
|
86
|
+
paths_.each{ |path_| require "rgeo/#{path_}" }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# Cartesian features for RGeo
|
4
4
|
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
# Copyright 2010 Daniel Azuma
|
@@ -36,31 +36,24 @@
|
|
36
36
|
|
37
37
|
module RGeo
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
class GeometryCollectionImpl
|
45
|
-
|
46
|
-
|
47
|
-
include Features::GeometryCollection
|
48
|
-
include Common::GeometryMethods
|
49
|
-
include GeometryMethods
|
50
|
-
include Common::GeometryCollectionMethods
|
51
|
-
|
52
|
-
|
53
|
-
def initialize(factory_, elements_)
|
54
|
-
_set_factory(factory_)
|
55
|
-
_setup(elements_)
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
39
|
+
|
40
|
+
# The cartesian features module
|
41
|
+
|
42
|
+
module Cartesian
|
64
43
|
end
|
65
44
|
|
45
|
+
|
66
46
|
end
|
47
|
+
|
48
|
+
|
49
|
+
# Dependency source files.
|
50
|
+
paths_ = [
|
51
|
+
'features',
|
52
|
+
'geos',
|
53
|
+
'cartesian/calculations',
|
54
|
+
'cartesian/simple_feature_methods',
|
55
|
+
'cartesian/simple_feature_classes',
|
56
|
+
'cartesian/simple_factory',
|
57
|
+
'cartesian/interface',
|
58
|
+
]
|
59
|
+
paths_.each{ |path_| require "rgeo/#{path_}" }
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Core calculations in the plane
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
module RGeo
|
38
|
+
|
39
|
+
module Cartesian
|
40
|
+
|
41
|
+
|
42
|
+
# Represents a line segment in the plane.
|
43
|
+
|
44
|
+
class Segment # :nodoc:
|
45
|
+
|
46
|
+
def initialize(start_, end_)
|
47
|
+
@s = start_
|
48
|
+
@e = end_
|
49
|
+
@sx = @s.x
|
50
|
+
@sy = @s.y
|
51
|
+
@ex = @e.x
|
52
|
+
@ey = @e.y
|
53
|
+
@dx = @ex - @sx
|
54
|
+
@dy = @ey - @sy
|
55
|
+
@lensq = @dx * @dx + @dy * @dy
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
attr_reader :s
|
60
|
+
attr_reader :e
|
61
|
+
attr_reader :dx
|
62
|
+
attr_reader :dy
|
63
|
+
|
64
|
+
|
65
|
+
def to_s
|
66
|
+
"#{@s} - #{@e}"
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def eql?(rhs_)
|
71
|
+
rhs_.kind_of?(Segment) && @s == rhs_.s && @e == rhs_.e
|
72
|
+
end
|
73
|
+
alias_method :==, :eql?
|
74
|
+
|
75
|
+
|
76
|
+
def degenerate?
|
77
|
+
@lensq == 0
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def side(p_)
|
82
|
+
px_ = p_.x
|
83
|
+
py_ = p_.y
|
84
|
+
(@sx - px_) * (@ey - py_) - (@sy - py_) * (@ex - px_)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def tproj(p_)
|
89
|
+
if @lensq == 0
|
90
|
+
nil
|
91
|
+
else
|
92
|
+
px_ = @sx - p_.x
|
93
|
+
py_ = @sy - p_.y
|
94
|
+
- (@dx * px_ + @dy * py_) / @lensq
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def contains_point?(p_)
|
100
|
+
if side(p_) == 0
|
101
|
+
t_ = tproj(p_)
|
102
|
+
t_ && t_ >= 0.0 && t_ <= 1.0
|
103
|
+
else
|
104
|
+
false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def intersects_segment?(seg_)
|
110
|
+
s2_ = seg_.s
|
111
|
+
sx2_ = s2_.x
|
112
|
+
sy2_ = s2_.y
|
113
|
+
dx2_ = seg_.dx
|
114
|
+
dy2_ = seg_.dy
|
115
|
+
denom_ = @dx*dy2_ - @dy*dx2_
|
116
|
+
return side(s2_) == 0 if denom_ == 0
|
117
|
+
t_ = (dy2_ * (sx2_ - @sx) + dx2_ * (@sy - sy2_)) / denom_
|
118
|
+
return false if t_ < 0.0 || t_ > 1.0
|
119
|
+
t2_ = (@dy * (sx2_ - @sx) + @dx * (@sy - sy2_)) / denom_
|
120
|
+
t2_ >= 0.0 && t2_ <= 1.0
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Cartesian toplevel interface
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
module RGeo
|
38
|
+
|
39
|
+
module Cartesian
|
40
|
+
|
41
|
+
class << self
|
42
|
+
|
43
|
+
|
44
|
+
# Creates and returns a cartesian factory of the preferred
|
45
|
+
# implementation.
|
46
|
+
#
|
47
|
+
# The actual implementation returned depends on which ruby
|
48
|
+
# interpreter is running and what libraries are available.
|
49
|
+
# RGeo will try to provide a fully-functional and performant
|
50
|
+
# implementation if possible. If not, the simple cartesian
|
51
|
+
# implementation will be returned.
|
52
|
+
#
|
53
|
+
# The given options are passed to the factory's constructor.
|
54
|
+
# What options are available depends on the particular
|
55
|
+
# implementation. Unsupported options are ignored.
|
56
|
+
|
57
|
+
def preferred_factory(opts_={})
|
58
|
+
if Geos.supported?
|
59
|
+
Geos.factory(opts_)
|
60
|
+
else
|
61
|
+
simple_factory(opts_)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
alias_method :factory, :preferred_factory
|
65
|
+
|
66
|
+
|
67
|
+
# Returns a factory for the simple cartesian implementation.
|
68
|
+
# This implementation is always available.
|
69
|
+
#
|
70
|
+
# Options include:
|
71
|
+
#
|
72
|
+
# <tt>:srid</tt>::
|
73
|
+
# Set the SRID returned by geometries created by this factory.
|
74
|
+
# Default is 0.
|
75
|
+
|
76
|
+
def simple_factory(opts_={})
|
77
|
+
SimpleFactory.new(opts_)
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Geographic data factory implementation
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
module RGeo
|
38
|
+
|
39
|
+
module Cartesian
|
40
|
+
|
41
|
+
|
42
|
+
# This class implements the factory for the simple cartesian
|
43
|
+
# implementation.
|
44
|
+
|
45
|
+
class SimpleFactory
|
46
|
+
|
47
|
+
include Features::Factory::Instance
|
48
|
+
|
49
|
+
|
50
|
+
# Create a new simple cartesian factory.
|
51
|
+
#
|
52
|
+
# Options supported are:
|
53
|
+
#
|
54
|
+
# <tt>:srid</tt>::
|
55
|
+
# The SRID reported by features created by this factory.
|
56
|
+
# Default is 0.
|
57
|
+
|
58
|
+
def initialize(opts_={})
|
59
|
+
@srid = opts_[:srid].to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
# Equivalence test.
|
64
|
+
|
65
|
+
def eql?(rhs_)
|
66
|
+
rhs_.is_a?(self.class) && @srid == rhs_.srid
|
67
|
+
end
|
68
|
+
alias_method :==, :eql?
|
69
|
+
|
70
|
+
|
71
|
+
# Returns the SRID.
|
72
|
+
|
73
|
+
def srid
|
74
|
+
@srid
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# See ::RGeo::Features::Factory#parse_wkt
|
79
|
+
|
80
|
+
def parse_wkt(str_)
|
81
|
+
ImplHelpers::Serialization.parse_wkt(str_, self)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
# See ::RGeo::Features::Factory#parse_wkb
|
86
|
+
|
87
|
+
def parse_wkb(str_)
|
88
|
+
ImplHelpers::Serialization.parse_wkb(str_, self)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# See ::RGeo::Features::Factory#point
|
93
|
+
|
94
|
+
def point(x_, y_)
|
95
|
+
SimplePointImpl.new(self, x_, y_) rescue nil
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
# See ::RGeo::Features::Factory#line_string
|
100
|
+
|
101
|
+
def line_string(points_)
|
102
|
+
SimpleLineStringImpl.new(self, points_) rescue nil
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
# See ::RGeo::Features::Factory#line
|
107
|
+
|
108
|
+
def line(start_, end_)
|
109
|
+
SimpleLineImpl.new(self, start_, end_) rescue nil
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
# See ::RGeo::Features::Factory#linear_ring
|
114
|
+
|
115
|
+
def linear_ring(points_)
|
116
|
+
SimpleLinearRingImpl.new(self, points_) rescue nil
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# See ::RGeo::Features::Factory#polygon
|
121
|
+
|
122
|
+
def polygon(outer_ring_, inner_rings_=nil)
|
123
|
+
SimplePolygonImpl.new(self, outer_ring_, inner_rings_) rescue nil
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
# See ::RGeo::Features::Factory#collection
|
128
|
+
|
129
|
+
def collection(elems_)
|
130
|
+
SimpleGeometryCollectionImpl.new(self, elems_) rescue nil
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
# See ::RGeo::Features::Factory#multi_point
|
135
|
+
|
136
|
+
def multi_point(elems_)
|
137
|
+
SimpleMultiPointImpl.new(self, elems_) rescue nil
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
# See ::RGeo::Features::Factory#multi_line_string
|
142
|
+
|
143
|
+
def multi_line_string(elems_)
|
144
|
+
SimpleMultiLineStringImpl.new(self, elems_) rescue nil
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
# See ::RGeo::Features::Factory#multi_polygon
|
149
|
+
|
150
|
+
def multi_polygon(elems_)
|
151
|
+
SimpleMultiPolygonImpl.new(self, elems_) rescue nil
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|