schleyfox-rgeo 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/History.rdoc +199 -0
  2. data/README.rdoc +172 -0
  3. data/Spatial_Programming_With_RGeo.rdoc +440 -0
  4. data/Version +1 -0
  5. data/ext/geos_c_impl/extconf.rb +84 -0
  6. data/ext/geos_c_impl/factory.c +468 -0
  7. data/ext/geos_c_impl/factory.h +224 -0
  8. data/ext/geos_c_impl/geometry.c +705 -0
  9. data/ext/geos_c_impl/geometry.h +55 -0
  10. data/ext/geos_c_impl/geometry_collection.c +482 -0
  11. data/ext/geos_c_impl/geometry_collection.h +69 -0
  12. data/ext/geos_c_impl/line_string.c +509 -0
  13. data/ext/geos_c_impl/line_string.h +64 -0
  14. data/ext/geos_c_impl/main.c +70 -0
  15. data/ext/geos_c_impl/point.c +193 -0
  16. data/ext/geos_c_impl/point.h +62 -0
  17. data/ext/geos_c_impl/polygon.c +265 -0
  18. data/ext/geos_c_impl/polygon.h +66 -0
  19. data/ext/geos_c_impl/preface.h +50 -0
  20. data/ext/proj4_c_impl/extconf.rb +88 -0
  21. data/ext/proj4_c_impl/main.c +271 -0
  22. data/lib/rgeo.rb +124 -0
  23. data/lib/rgeo/cartesian.rb +60 -0
  24. data/lib/rgeo/cartesian/analysis.rb +118 -0
  25. data/lib/rgeo/cartesian/bounding_box.rb +337 -0
  26. data/lib/rgeo/cartesian/calculations.rb +161 -0
  27. data/lib/rgeo/cartesian/factory.rb +209 -0
  28. data/lib/rgeo/cartesian/feature_classes.rb +173 -0
  29. data/lib/rgeo/cartesian/feature_methods.rb +106 -0
  30. data/lib/rgeo/cartesian/interface.rb +150 -0
  31. data/lib/rgeo/coord_sys.rb +79 -0
  32. data/lib/rgeo/coord_sys/cs/entities.rb +1524 -0
  33. data/lib/rgeo/coord_sys/cs/factories.rb +208 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +308 -0
  35. data/lib/rgeo/coord_sys/proj4.rb +312 -0
  36. data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +194 -0
  37. data/lib/rgeo/coord_sys/srs_database/interface.rb +165 -0
  38. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +188 -0
  39. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +108 -0
  40. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +108 -0
  41. data/lib/rgeo/error.rb +63 -0
  42. data/lib/rgeo/feature.rb +88 -0
  43. data/lib/rgeo/feature/curve.rb +156 -0
  44. data/lib/rgeo/feature/factory.rb +332 -0
  45. data/lib/rgeo/feature/factory_generator.rb +138 -0
  46. data/lib/rgeo/feature/geometry.rb +614 -0
  47. data/lib/rgeo/feature/geometry_collection.rb +129 -0
  48. data/lib/rgeo/feature/line.rb +66 -0
  49. data/lib/rgeo/feature/line_string.rb +102 -0
  50. data/lib/rgeo/feature/linear_ring.rb +66 -0
  51. data/lib/rgeo/feature/multi_curve.rb +113 -0
  52. data/lib/rgeo/feature/multi_line_string.rb +66 -0
  53. data/lib/rgeo/feature/multi_point.rb +73 -0
  54. data/lib/rgeo/feature/multi_polygon.rb +97 -0
  55. data/lib/rgeo/feature/multi_surface.rb +116 -0
  56. data/lib/rgeo/feature/point.rb +120 -0
  57. data/lib/rgeo/feature/polygon.rb +141 -0
  58. data/lib/rgeo/feature/surface.rb +122 -0
  59. data/lib/rgeo/feature/types.rb +305 -0
  60. data/lib/rgeo/geographic.rb +75 -0
  61. data/lib/rgeo/geographic/factory.rb +287 -0
  62. data/lib/rgeo/geographic/interface.rb +410 -0
  63. data/lib/rgeo/geographic/proj4_projector.rb +98 -0
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +213 -0
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +228 -0
  66. data/lib/rgeo/geographic/projected_window.rb +467 -0
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +157 -0
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +212 -0
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +97 -0
  70. data/lib/rgeo/geographic/spherical_math.rb +206 -0
  71. data/lib/rgeo/geos.rb +72 -0
  72. data/lib/rgeo/geos/factory.rb +301 -0
  73. data/lib/rgeo/geos/impl_additions.rb +76 -0
  74. data/lib/rgeo/geos/interface.rb +139 -0
  75. data/lib/rgeo/geos/zm_factory.rb +275 -0
  76. data/lib/rgeo/geos/zm_impl.rb +432 -0
  77. data/lib/rgeo/impl_helper.rb +53 -0
  78. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +235 -0
  79. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +85 -0
  80. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +197 -0
  81. data/lib/rgeo/impl_helper/basic_point_methods.rb +138 -0
  82. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +121 -0
  83. data/lib/rgeo/impl_helper/math.rb +50 -0
  84. data/lib/rgeo/version.rb +52 -0
  85. data/lib/rgeo/wkrep.rb +72 -0
  86. data/lib/rgeo/wkrep/wkb_generator.rb +267 -0
  87. data/lib/rgeo/wkrep/wkb_parser.rb +315 -0
  88. data/lib/rgeo/wkrep/wkt_generator.rb +275 -0
  89. data/lib/rgeo/wkrep/wkt_parser.rb +496 -0
  90. data/test/common/geometry_collection_tests.rb +238 -0
  91. data/test/common/line_string_tests.rb +324 -0
  92. data/test/common/multi_line_string_tests.rb +209 -0
  93. data/test/common/multi_point_tests.rb +201 -0
  94. data/test/common/multi_polygon_tests.rb +208 -0
  95. data/test/common/point_tests.rb +331 -0
  96. data/test/common/polygon_tests.rb +232 -0
  97. data/test/coord_sys/tc_active_record_table.rb +102 -0
  98. data/test/coord_sys/tc_ogc_cs.rb +356 -0
  99. data/test/coord_sys/tc_proj4.rb +138 -0
  100. data/test/coord_sys/tc_proj4_srs_data.rb +76 -0
  101. data/test/coord_sys/tc_sr_org.rb +70 -0
  102. data/test/coord_sys/tc_url_reader.rb +82 -0
  103. data/test/geos/tc_factory.rb +91 -0
  104. data/test/geos/tc_geometry_collection.rb +62 -0
  105. data/test/geos/tc_line_string.rb +62 -0
  106. data/test/geos/tc_misc.rb +72 -0
  107. data/test/geos/tc_multi_line_string.rb +62 -0
  108. data/test/geos/tc_multi_point.rb +62 -0
  109. data/test/geos/tc_multi_polygon.rb +63 -0
  110. data/test/geos/tc_point.rb +86 -0
  111. data/test/geos/tc_polygon.rb +86 -0
  112. data/test/geos/tc_zmfactory.rb +85 -0
  113. data/test/projected_geographic/tc_geometry_collection.rb +62 -0
  114. data/test/projected_geographic/tc_line_string.rb +62 -0
  115. data/test/projected_geographic/tc_multi_line_string.rb +62 -0
  116. data/test/projected_geographic/tc_multi_point.rb +62 -0
  117. data/test/projected_geographic/tc_multi_polygon.rb +63 -0
  118. data/test/projected_geographic/tc_point.rb +93 -0
  119. data/test/projected_geographic/tc_polygon.rb +62 -0
  120. data/test/simple_cartesian/tc_calculations.rb +145 -0
  121. data/test/simple_cartesian/tc_geometry_collection.rb +69 -0
  122. data/test/simple_cartesian/tc_line_string.rb +70 -0
  123. data/test/simple_cartesian/tc_multi_line_string.rb +67 -0
  124. data/test/simple_cartesian/tc_multi_point.rb +67 -0
  125. data/test/simple_cartesian/tc_multi_polygon.rb +70 -0
  126. data/test/simple_cartesian/tc_point.rb +91 -0
  127. data/test/simple_cartesian/tc_polygon.rb +67 -0
  128. data/test/simple_mercator/tc_geometry_collection.rb +62 -0
  129. data/test/simple_mercator/tc_line_string.rb +62 -0
  130. data/test/simple_mercator/tc_multi_line_string.rb +62 -0
  131. data/test/simple_mercator/tc_multi_point.rb +62 -0
  132. data/test/simple_mercator/tc_multi_polygon.rb +63 -0
  133. data/test/simple_mercator/tc_point.rb +93 -0
  134. data/test/simple_mercator/tc_polygon.rb +62 -0
  135. data/test/simple_mercator/tc_window.rb +219 -0
  136. data/test/spherical_geographic/tc_calculations.rb +203 -0
  137. data/test/spherical_geographic/tc_geometry_collection.rb +70 -0
  138. data/test/spherical_geographic/tc_line_string.rb +70 -0
  139. data/test/spherical_geographic/tc_multi_line_string.rb +67 -0
  140. data/test/spherical_geographic/tc_multi_point.rb +67 -0
  141. data/test/spherical_geographic/tc_multi_polygon.rb +70 -0
  142. data/test/spherical_geographic/tc_point.rb +100 -0
  143. data/test/spherical_geographic/tc_polygon.rb +67 -0
  144. data/test/tc_cartesian_analysis.rb +107 -0
  145. data/test/tc_oneoff.rb +63 -0
  146. data/test/wkrep/tc_wkb_generator.rb +249 -0
  147. data/test/wkrep/tc_wkb_parser.rb +353 -0
  148. data/test/wkrep/tc_wkt_generator.rb +362 -0
  149. data/test/wkrep/tc_wkt_parser.rb +480 -0
  150. metadata +267 -0
@@ -0,0 +1,108 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # SRS database 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
+ require 'net/http'
38
+
39
+
40
+ module RGeo
41
+
42
+ module CoordSys
43
+
44
+ module SRSDatabase
45
+
46
+
47
+ # A spatial reference database implementation that fetches data from
48
+ # internet URLs.
49
+
50
+ class UrlReader
51
+
52
+
53
+ # Create a URL-based spatial reference database.
54
+ #
55
+ # Options:
56
+ #
57
+ # [<tt>:cache</tt>]
58
+ # If set to true, lookup results are cached so if the same URL
59
+ # is requested again, the result is served from cache rather
60
+ # than issuing another HTTP request. Default is false.
61
+
62
+ def initialize(opts_={})
63
+ @cache = opts_[:cache] ? {} : nil
64
+ end
65
+
66
+
67
+ # Retrieve the given URL and return an Entry.
68
+ # Returns nil if the URL cannot be read as an OGC WKT or Proj4
69
+ # coordinate system
70
+
71
+ def get(ident_)
72
+ ident_ = ident_.to_s
73
+ return @cache[ident_] if @cache && @cache.include?(ident_)
74
+ uri_ = ::URI.parse(ident_)
75
+ result_ = nil
76
+ ::Net::HTTP.start(uri_.host, uri_.port) do |http_|
77
+ request_ = uri_.path
78
+ request_ = "#{request_}?#{uri_.query}" if uri_.query
79
+ response_ = http_.request_get(request_)
80
+ if response_.kind_of?(::Net::HTTPSuccess)
81
+ response_ = response_.body.strip
82
+ if response_[0,1] == '+'
83
+ result_ = Entry.new(ident_, :proj4 => response_)
84
+ else
85
+ result_ = Entry.new(ident_, :coord_sys => response_)
86
+ end
87
+ end
88
+ end
89
+ @cache[ident_] = result_ if @cache
90
+ result_
91
+ end
92
+
93
+
94
+ # Clear the cache if one is present.
95
+
96
+ def clear_cache
97
+ @cache.clear if @cache
98
+ end
99
+
100
+
101
+ end
102
+
103
+
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,63 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Error classes for RGeo
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
+
40
+ # All RGeo errors are members of this namespace.
41
+
42
+ module Error
43
+
44
+ # Base class for all RGeo-related exceptions
45
+ class RGeoError < ::RuntimeError
46
+ end
47
+
48
+ # The specified geometry is invalid
49
+ class InvalidGeometry < RGeoError
50
+ end
51
+
52
+ # The specified operation is not supported or not implemented
53
+ class UnsupportedOperation < RGeoError
54
+ end
55
+
56
+ # Parsing failed
57
+ class ParseError < RGeoError
58
+ end
59
+
60
+ end
61
+
62
+
63
+ end
@@ -0,0 +1,88 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Features namespace for RGeo
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
+
40
+ # The Feature namespace contains interfaces and general tools for
41
+ # implementations of the Open Geospatial Consortium Simple Features
42
+ # Specification (SFS), version 1.1.0.
43
+ #
44
+ # Each interface is defined as a module, and is provided primarily for
45
+ # the sake of documentation. Implementations do not necessarily include
46
+ # the modules themselves. Therefore, you should not depend on the
47
+ # kind_of? method to check type. Instead, each interface module will
48
+ # provide a check_type class method (and a corresponding === operator
49
+ # to support case-when constructs).
50
+ #
51
+ # In addition, a Factory interface is defined here. A factory is an
52
+ # object that knows how to construct geometry instances for a given
53
+ # implementation. Each implementation's front-end consists of a way to
54
+ # create factories. Those factories, in turn, provide the api for
55
+ # building the features themselves. Note that, like the geometry
56
+ # modules, the Factory module itself may not actually be included in a
57
+ # factory implementation.
58
+ #
59
+ # Any particular implementation may extend these interfaces to provide
60
+ # implementation-specific features beyond what is stated in the SFS
61
+ # itself. The implementation should separately document any such
62
+ # extensions that it may provide.
63
+
64
+ module Feature
65
+ end
66
+
67
+
68
+ end
69
+
70
+
71
+ # Implementation files
72
+ require 'rgeo/feature/factory'
73
+ require 'rgeo/feature/types'
74
+ require 'rgeo/feature/geometry'
75
+ require 'rgeo/feature/point'
76
+ require 'rgeo/feature/curve'
77
+ require 'rgeo/feature/line_string'
78
+ require 'rgeo/feature/linear_ring'
79
+ require 'rgeo/feature/line'
80
+ require 'rgeo/feature/surface'
81
+ require 'rgeo/feature/polygon'
82
+ require 'rgeo/feature/geometry_collection'
83
+ require 'rgeo/feature/multi_point'
84
+ require 'rgeo/feature/multi_curve'
85
+ require 'rgeo/feature/multi_line_string'
86
+ require 'rgeo/feature/multi_surface'
87
+ require 'rgeo/feature/multi_polygon'
88
+ require 'rgeo/feature/factory_generator'
@@ -0,0 +1,156 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Curve feature 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 Feature
40
+
41
+
42
+ # == SFS 1.1 Description
43
+ #
44
+ # A Curve is a 1-dimensional geometric object usually stored as a
45
+ # sequence of Points, with the subtype of Curve specifying the form of
46
+ # the interpolation between Points. This part of ISO 19125 defines only
47
+ # one subclass of Curve, LineString, which uses linear interpolation
48
+ # between Points.
49
+ #
50
+ # A Curve is a 1-dimensional geometric object that is the homeomorphic
51
+ # image of a real, closed interval D=[a,b] under a mapping f:[a,b]->R2.
52
+ #
53
+ # A Curve is simple if it does not pass through the same Point twice.
54
+ #
55
+ # A Curve is closed if its start Point is equal to its end Point.
56
+ #
57
+ # The boundary of a closed Curve is empty.
58
+ #
59
+ # A Curve that is simple and closed is a Ring.
60
+ #
61
+ # The boundary of a non-closed Curve consists of its two end Points.
62
+ #
63
+ # A Curve is defined as topologically closed.
64
+ #
65
+ # == Notes
66
+ #
67
+ # Curve is defined as a module and is provided primarily
68
+ # for the sake of documentation. Implementations need not necessarily
69
+ # include this module itself. Therefore, you should not depend on the
70
+ # kind_of? method to check type. Instead, use the provided check_type
71
+ # class method (or === operator) defined in the Type module.
72
+ #
73
+ # Some implementations may support higher dimensional points.
74
+
75
+ module Curve
76
+
77
+ extend Type
78
+
79
+ include Geometry
80
+
81
+
82
+ # === SFS 1.1 Description
83
+ #
84
+ # The length of this Curve in its associated spatial reference.
85
+ #
86
+ # === Notes
87
+ #
88
+ # Returns a floating-point scalar value.
89
+
90
+ def length
91
+ raise Error::UnsupportedOperation, "Method Curve#length not defined."
92
+ end
93
+
94
+
95
+ # === SFS 1.1 Description
96
+ #
97
+ # The start Point of this Curve.
98
+ #
99
+ # === Notes
100
+ #
101
+ # Returns an object that supports the Point interface.
102
+
103
+ def start_point
104
+ raise Error::UnsupportedOperation, "Method Curve#start_point not defined."
105
+ end
106
+
107
+
108
+ # === SFS 1.1 Description
109
+ #
110
+ # The end Point of this Curve.
111
+ #
112
+ # === Notes
113
+ #
114
+ # Returns an object that supports the Point interface.
115
+
116
+ def end_point
117
+ raise Error::UnsupportedOperation, "Method Curve#end_point not defined."
118
+ end
119
+
120
+
121
+ # === SFS 1.1 Description
122
+ #
123
+ # Returns true if this Curve is closed [StartPoint() = EndPoint()].
124
+ #
125
+ # === Notes
126
+ #
127
+ # Returns a boolean value. Note that this is different from the SFS
128
+ # specification, which stipulates an integer return value.
129
+
130
+ def is_closed?
131
+ raise Error::UnsupportedOperation, "Method Curve#is_closed? not defined."
132
+ end
133
+
134
+
135
+ # === SFS 1.1 Description
136
+ #
137
+ # Returns true if this Curve is closed [StartPoint() = EndPoint()]
138
+ # and this Curve is simple (does not pass through the same Point
139
+ # more than once).
140
+ #
141
+ # === Notes
142
+ #
143
+ # Returns a boolean value. Note that this is different from the SFS
144
+ # specification, which stipulates an integer return value.
145
+
146
+ def is_ring?
147
+ raise Error::UnsupportedOperation, "Method Curve#is_ring? not defined."
148
+ end
149
+
150
+
151
+ end
152
+
153
+
154
+ end
155
+
156
+ end
@@ -0,0 +1,332 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Feature factory 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 Feature
40
+
41
+
42
+ # This is a standard interface for factories of features.
43
+ # Generally, each Feature implementation will implement these
44
+ # methods as a standard way to create features.
45
+ #
46
+ # If the implementation is unable to create the given feature,
47
+ # it should generally return nil. Implementations may also choose to
48
+ # raise an exception on failure.
49
+ #
50
+ # Some implementations may extend this interface to provide facilities
51
+ # for creating additional objects according to the capabilities
52
+ # provided by that implementation. Examples might include
53
+ # higher-dimensional coordinates or additional subclasses not
54
+ # explicitly required by the Simple Features Specification.
55
+ #
56
+ # Factory is defined as a module and is provided primarily for the
57
+ # sake of documentation. Implementations need not necessarily include
58
+ # this module itself. Therefore, you should not depend on the
59
+ # kind_of? method to check type. However, to support testing for
60
+ # factory-ness, the Factory::Instance submodule is provided. All
61
+ # factory implementation classes MUST include Factory::Instance, and
62
+ # you may use it in kind_of?, ===, and case-when constructs.
63
+
64
+ module Factory
65
+
66
+
67
+ # All factory implementations MUST include this submodule.
68
+ # This serves as a marker that may be used to test an object for
69
+ # factory-ness.
70
+
71
+ module Instance
72
+ end
73
+
74
+
75
+ # Returns meta-information about this factory, by key. This
76
+ # information may involve support for optional functionality,
77
+ # properties of the coordinate system, or other characteristics.
78
+ #
79
+ # Each property has a symbolic name. Names that have no periods are
80
+ # considered well-known names and are reserved for use by RGeo. If
81
+ # you want to define your own properties, use a name that is
82
+ # namespaced with periods, such as <tt>:'mycompany.myprop'</tt>.
83
+ #
84
+ # Property values are dependent on the individual property.
85
+ # Generally, properties that involve testing for functionality
86
+ # should return true if the functionality is support, or false or
87
+ # nil if not. A property value could also invlove different values
88
+ # indicating different levels of support. In any case, the factory
89
+ # should return nil for property names it does not recognize. This
90
+ # value is considered the "default" or "no value" value.
91
+ #
92
+ # Currently defined well-known properties are:
93
+ #
94
+ # [<tt>:has_z_coordinate</tt>]
95
+ # Set to true if geometries created by this factory include a Z
96
+ # coordinate, and the Point#z method is available.
97
+ # [<tt>:has_m_coordinate</tt>]
98
+ # Set to true if geometries created by this factory include a M
99
+ # coordinate, and the Point#z method is available.
100
+ # [<tt>:is_cartesian</tt>]
101
+ # Set to true if this Factory guarantees that it operates in
102
+ # Cartesian geometry. If false or nil, no such guarantee is made,
103
+ # though it is possible the geometries may still be Cartesian.
104
+ # [<tt>:is_geographic</tt>]
105
+ # Set to true if this Factory's coordinate system is meant to be
106
+ # interpreted as x=longitude and y=latitude. If false or nil, no
107
+ # information is present about whether the coordinate system is
108
+ # meant to be so interpreted.
109
+
110
+ def property(name_)
111
+ nil
112
+ end
113
+
114
+
115
+ # Parse the given string in well-known-text format and return the
116
+ # resulting feature. Returns nil if the string couldn't be parsed.
117
+
118
+ def parse_wkt(str_)
119
+ nil
120
+ end
121
+
122
+
123
+ # Parse the given string in well-known-binary format and return the
124
+ # resulting feature. Returns nil if the string couldn't be parsed.
125
+
126
+ def parse_wkb(str_)
127
+ nil
128
+ end
129
+
130
+
131
+ # Create a feature of type Point.
132
+ # The x and y parameters should be Float values.
133
+ #
134
+ # The extra parameters should be the Z and/or M coordinates, if
135
+ # supported. If both Z and M coordinates are supported, Z should
136
+ # be passed first.
137
+
138
+ def point(x_, y_, *extra_)
139
+ nil
140
+ end
141
+
142
+
143
+ # Create a feature of type LineString.
144
+ # The given points argument should be an Enumerable of Point
145
+ # objects, or objects that can be cast to Point.
146
+ #
147
+ # Although implementations are free to attempt to handle input
148
+ # objects that are not of this factory, strictly speaking, the
149
+ # result of building geometries from objects of the wrong factory
150
+ # is undefined.
151
+
152
+ def line_string(points_)
153
+ nil
154
+ end
155
+
156
+
157
+ # Create a feature of type Line.
158
+ # The given point arguments should be Point objects, or objects
159
+ # that can be cast to Point.
160
+ #
161
+ # Although implementations are free to attempt to handle input
162
+ # objects that are not of this factory, strictly speaking, the
163
+ # result of building geometries from objects of the wrong factory
164
+ # is undefined.
165
+
166
+ def line(start_, end_)
167
+ nil
168
+ end
169
+
170
+
171
+ # Create a feature of type LinearRing.
172
+ # The given points argument should be an Enumerable of Point
173
+ # objects, or objects that can be cast to Point.
174
+ # If the first and last points are not equal, the ring is
175
+ # automatically closed by appending the first point to the end of the
176
+ # string.
177
+ #
178
+ # Although implementations are free to attempt to handle input
179
+ # objects that are not of this factory, strictly speaking, the
180
+ # result of building geometries from objects of the wrong factory
181
+ # is undefined.
182
+
183
+ def linear_ring(points_)
184
+ nil
185
+ end
186
+
187
+
188
+ # Create a feature of type Polygon.
189
+ # The outer_ring should be a LinearRing, or an object that can be
190
+ # cast to LinearRing.
191
+ # The inner_rings should be a possibly empty Enumerable of
192
+ # LinearRing (or objects that can be casted to LinearRing).
193
+ # You may also pass nil to indicate no inner rings.
194
+ #
195
+ # Although implementations are free to attempt to handle input
196
+ # objects that are not of this factory, strictly speaking, the
197
+ # result of building geometries from objects of the wrong factory
198
+ # is undefined.
199
+
200
+ def polygon(outer_ring_, inner_rings_=nil)
201
+ nil
202
+ end
203
+
204
+
205
+ # Create a feature of type GeometryCollection.
206
+ # The elems should be an Enumerable of Geometry objects.
207
+ #
208
+ # Although implementations are free to attempt to handle input
209
+ # objects that are not of this factory, strictly speaking, the
210
+ # result of building geometries from objects of the wrong factory
211
+ # is undefined.
212
+
213
+ def collection(elems_)
214
+ nil
215
+ end
216
+
217
+
218
+ # Create a feature of type MultiPoint.
219
+ # The elems should be an Enumerable of Point objects, or objects
220
+ # that can be cast to Point.
221
+ # Returns nil if any of the contained geometries is not a Point,
222
+ # which would break the MultiPoint contract.
223
+ #
224
+ # Although implementations are free to attempt to handle input
225
+ # objects that are not of this factory, strictly speaking, the
226
+ # result of building geometries from objects of the wrong factory
227
+ # is undefined.
228
+
229
+ def multi_point(elems_)
230
+ nil
231
+ end
232
+
233
+
234
+ # Create a feature of type MultiLineString.
235
+ # The elems should be an Enumerable of objects that are or can be
236
+ # cast to LineString or any of its subclasses.
237
+ # Returns nil if any of the contained geometries is not a
238
+ # LineString, which would break the MultiLineString contract.
239
+ #
240
+ # Although implementations are free to attempt to handle input
241
+ # objects that are not of this factory, strictly speaking, the
242
+ # result of building geometries from objects of the wrong factory
243
+ # is undefined.
244
+
245
+ def multi_line_string(elems_)
246
+ nil
247
+ end
248
+
249
+
250
+ # Create a feature of type MultiPolygon.
251
+ # The elems should be an Enumerable of objects that are or can be
252
+ # cast to Polygon or any of its subclasses.
253
+ # Returns nil if any of the contained geometries is not a Polygon,
254
+ # which would break the MultiPolygon contract.
255
+ # Also returns nil if any of the other assertions for MultiPolygon
256
+ # are not met, e.g. if any of the polygons overlap.
257
+ #
258
+ # Although implementations are free to attempt to handle input
259
+ # objects that are not of this factory, strictly speaking, the
260
+ # result of building geometries from objects of the wrong factory
261
+ # is undefined.
262
+
263
+ def multi_polygon(elems_)
264
+ nil
265
+ end
266
+
267
+
268
+ # Returns a RGeo::CoordSys::Proj4 representing the projection for
269
+ # the coordinate system of features created by this factory, or nil
270
+ # if there is no such proj4 projection.
271
+
272
+ def proj4
273
+ nil
274
+ end
275
+
276
+
277
+ # Returns the coordinate system specification for the features
278
+ # created by this factory, or nil if there is no such coordinate
279
+ # system.
280
+ #
281
+ # NOTE: This is a required method of the factory interface, but the
282
+ # coordinate system classes themselves are not yet available, so
283
+ # implementations should just return nil for now.
284
+
285
+ def coord_sys
286
+ nil
287
+ end
288
+
289
+
290
+ # This is an optional method that may be implemented to customize
291
+ # casting for this factory. Basically, RGeo defines standard ways
292
+ # to cast certain types of objects from one factory to another and
293
+ # one SFS type to another. However, a factory may choose to
294
+ # override how things are casted TO its implementation using this
295
+ # method. It can do this to optimize certain casting cases, or
296
+ # implement special cases particular to this factory.
297
+ #
298
+ # This method will be called (if defined) on the destination
299
+ # factory, and will be passed the original object (which may or may
300
+ # not already be created by this factory), the SFS feature type
301
+ # (which again may or may not already be the type of the original
302
+ # object), and a hash of additional flags. These flags are:
303
+ #
304
+ # [<tt>:keep_subtype</tt>]
305
+ # indicates whether to keep the subtype if casting to a supertype
306
+ # of the current type
307
+ # [<tt>:force_new</tt>]
308
+ # indicates whether to force the creation of a new object even if
309
+ # the original is already of the desired factory and type
310
+ # [<tt>:project</tt>]
311
+ # indicates whether to project the coordinates from the source to
312
+ # the destination proj4 coordinate system, if available
313
+ #
314
+ # It should return either a casted result object, false, or nil.
315
+ # A nil return value indicates that casting should be forced to
316
+ # fail (and RGeo::Feature::cast will return nil).
317
+ # A false return value indicates that this method declines to
318
+ # override the casting algorithm, and RGeo should use its default
319
+ # algorithm to cast the object. Therefore, by default, you should
320
+ # return false.
321
+
322
+ def override_cast(original_, type_, flags_)
323
+ false
324
+ end
325
+
326
+
327
+ end
328
+
329
+
330
+ end
331
+
332
+ end