rgeo 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +22 -0
- data/README.rdoc +124 -0
- data/Version +1 -0
- data/ext/geos_c_impl/extconf.rb +72 -0
- data/ext/geos_c_impl/factory.c +468 -0
- data/ext/geos_c_impl/factory.h +217 -0
- data/ext/geos_c_impl/geometry.c +644 -0
- data/ext/geos_c_impl/geometry.h +65 -0
- data/ext/geos_c_impl/geometry_collection.c +580 -0
- data/ext/geos_c_impl/geometry_collection.h +79 -0
- data/ext/geos_c_impl/globals.h +58 -0
- data/ext/geos_c_impl/line_string.c +468 -0
- data/ext/geos_c_impl/line_string.h +74 -0
- data/ext/geos_c_impl/main.c +65 -0
- data/ext/geos_c_impl/point.c +201 -0
- data/ext/geos_c_impl/point.h +77 -0
- data/ext/geos_c_impl/polygon.c +259 -0
- data/ext/geos_c_impl/polygon.h +76 -0
- data/ext/geos_c_impl/preface.h +42 -0
- data/lib/rgeo.rb +68 -0
- data/lib/rgeo/errors.rb +59 -0
- data/lib/rgeo/features.rb +89 -0
- data/lib/rgeo/features/curve.rb +155 -0
- data/lib/rgeo/features/factory.rb +191 -0
- data/lib/rgeo/features/geometry.rb +560 -0
- data/lib/rgeo/features/geometry_collection.rb +118 -0
- data/lib/rgeo/features/line.rb +65 -0
- data/lib/rgeo/features/line_string.rb +101 -0
- data/lib/rgeo/features/linear_ring.rb +65 -0
- data/lib/rgeo/features/multi_curve.rb +112 -0
- data/lib/rgeo/features/multi_line_string.rb +65 -0
- data/lib/rgeo/features/multi_point.rb +72 -0
- data/lib/rgeo/features/multi_polygon.rb +96 -0
- data/lib/rgeo/features/multi_surface.rb +115 -0
- data/lib/rgeo/features/point.rb +97 -0
- data/lib/rgeo/features/polygon.rb +141 -0
- data/lib/rgeo/features/surface.rb +121 -0
- data/lib/rgeo/geo_json.rb +58 -0
- data/lib/rgeo/geo_json/coder.rb +305 -0
- data/lib/rgeo/geo_json/entities.rb +284 -0
- data/lib/rgeo/geo_json/interface.rb +95 -0
- data/lib/rgeo/geography.rb +75 -0
- data/lib/rgeo/geography/common/geometry_collection_methods.rb +206 -0
- data/lib/rgeo/geography/common/geometry_methods.rb +92 -0
- data/lib/rgeo/geography/common/helper.rb +102 -0
- data/lib/rgeo/geography/common/line_string_methods.rb +187 -0
- data/lib/rgeo/geography/common/point_methods.rb +149 -0
- data/lib/rgeo/geography/common/polygon_methods.rb +122 -0
- data/lib/rgeo/geography/factories.rb +136 -0
- data/lib/rgeo/geography/factory.rb +246 -0
- data/lib/rgeo/geography/projected_window.rb +467 -0
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +320 -0
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +291 -0
- data/lib/rgeo/geography/simple_mercator/projector.rb +116 -0
- data/lib/rgeo/geography/simple_spherical/calculations.rb +70 -0
- data/lib/rgeo/geography/simple_spherical/geometry_collection_impl.rb +66 -0
- data/lib/rgeo/geography/simple_spherical/geometry_methods.rb +59 -0
- data/lib/rgeo/geography/simple_spherical/line_string_impl.rb +104 -0
- data/lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/multi_point_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/point_impl.rb +85 -0
- data/lib/rgeo/geography/simple_spherical/polygon_impl.rb +66 -0
- data/lib/rgeo/geos.rb +72 -0
- data/lib/rgeo/geos/factory.rb +260 -0
- data/lib/rgeo/geos/impl_additions.rb +57 -0
- data/lib/rgeo/geos/interface.rb +74 -0
- data/lib/rgeo/version.rb +52 -0
- data/tests/geos/tc_factory.rb +91 -0
- data/tests/geos/tc_geometry_collection.rb +226 -0
- data/tests/geos/tc_line_string.rb +310 -0
- data/tests/geos/tc_misc.rb +72 -0
- data/tests/geos/tc_multi_line_string.rb +211 -0
- data/tests/geos/tc_multi_point.rb +202 -0
- data/tests/geos/tc_multi_polygon.rb +210 -0
- data/tests/geos/tc_point.rb +305 -0
- data/tests/geos/tc_polygon.rb +240 -0
- data/tests/simple_mercator/tc_point.rb +303 -0
- data/tests/simple_mercator/tc_window.rb +219 -0
- data/tests/tc_geojson.rb +230 -0
- data/tests/tc_oneoff.rb +61 -0
- metadata +162 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Spherical MultiPoint 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 Geography
|
40
|
+
|
41
|
+
module SimpleSpherical
|
42
|
+
|
43
|
+
|
44
|
+
class MultiPointImpl
|
45
|
+
|
46
|
+
|
47
|
+
include Features::GeometryCollection
|
48
|
+
include Common::GeometryMethods
|
49
|
+
include GeometryMethods
|
50
|
+
include Common::GeometryCollectionMethods
|
51
|
+
include Common::MultiPointMethods
|
52
|
+
|
53
|
+
|
54
|
+
def initialize(factory_, elements_)
|
55
|
+
_set_factory(factory_)
|
56
|
+
_setup(elements_)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Spherical MultiPolygon 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 Geography
|
40
|
+
|
41
|
+
module SimpleSpherical
|
42
|
+
|
43
|
+
|
44
|
+
class MultiPolygonImpl
|
45
|
+
|
46
|
+
|
47
|
+
include Features::GeometryCollection
|
48
|
+
include Common::GeometryMethods
|
49
|
+
include GeometryMethods
|
50
|
+
include Common::GeometryCollectionMethods
|
51
|
+
include Common::MultiPolygonMethods
|
52
|
+
|
53
|
+
|
54
|
+
def initialize(factory_, elements_)
|
55
|
+
_set_factory(factory_)
|
56
|
+
_setup(elements_)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Spherical Point 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 Geography
|
40
|
+
|
41
|
+
module SimpleSpherical
|
42
|
+
|
43
|
+
|
44
|
+
class PointImpl
|
45
|
+
|
46
|
+
|
47
|
+
include Features::Point
|
48
|
+
include Common::GeometryMethods
|
49
|
+
include GeometryMethods
|
50
|
+
include Common::PointMethods
|
51
|
+
|
52
|
+
|
53
|
+
def initialize(factory_, x_, y_)
|
54
|
+
_set_factory(factory_)
|
55
|
+
_setup(x_, y_)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def _validate_geometry
|
60
|
+
@x = @x % 360.0
|
61
|
+
@x -= 360.0 if @x >= 180.0
|
62
|
+
@y = 90.0 if @y > 90.0
|
63
|
+
@y = -90.0 if @y < -90.0
|
64
|
+
super
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def distance(rhs_)
|
69
|
+
case rhs_
|
70
|
+
when Features::Point
|
71
|
+
Calculator.point_distance(self, rhs_)
|
72
|
+
else
|
73
|
+
super
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Spherical Polygon 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 Geography
|
40
|
+
|
41
|
+
module SimpleSpherical
|
42
|
+
|
43
|
+
|
44
|
+
class PolygonImpl
|
45
|
+
|
46
|
+
|
47
|
+
include Features::Polygon
|
48
|
+
include Common::GeometryMethods
|
49
|
+
include GeometryMethods
|
50
|
+
include Common::PolygonMethods
|
51
|
+
|
52
|
+
|
53
|
+
def initialize(factory_, exterior_ring_, interior_rings_)
|
54
|
+
_set_factory(factory_)
|
55
|
+
_setup(exterior_ring_, interior_rings_)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/lib/rgeo/geos.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# GEOS wrapper 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 Geos module provides general tools for creating and manipulating
|
41
|
+
# a GEOS-backed implementation of the SFS. This is a full implementation
|
42
|
+
# of the SFS using a Cartesian coordinate system. It uses the GEOS C++
|
43
|
+
# library to perform most operations, and hence is available only if
|
44
|
+
# GEOS version 3.2 or later is installed and accessible when the rgeo
|
45
|
+
# gem is installed. RGeo feature calls are translated into appropriate
|
46
|
+
# GEOS calls and directed to the library's C api. RGeo also corrects a
|
47
|
+
# few cases of missing or non-standard behavior in GEOS.
|
48
|
+
#
|
49
|
+
# This module also provides a namespace for the implementation classes
|
50
|
+
# themselves; however, those classes are meant to be opaque and are
|
51
|
+
# therefore not documented.
|
52
|
+
#
|
53
|
+
# To use the Geos implementation, first obtain a factory using the
|
54
|
+
# ::RGeo::Geos::factory method. You may then call any of the standard
|
55
|
+
# factory methods on the resulting object.
|
56
|
+
|
57
|
+
module Geos
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# Dependency source files.
|
65
|
+
paths_ = [
|
66
|
+
'features',
|
67
|
+
'geos/factory',
|
68
|
+
'geos/interface',
|
69
|
+
'geos/geos_c_impl',
|
70
|
+
'geos/impl_additions',
|
71
|
+
]
|
72
|
+
paths_.each{ |path_| require "rgeo/#{path_}" }
|
@@ -0,0 +1,260 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# GEOS 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 Geos
|
40
|
+
|
41
|
+
|
42
|
+
# This the GEOS implementation of ::RGeo::Features::Factory.
|
43
|
+
|
44
|
+
class Factory
|
45
|
+
|
46
|
+
include Features::Factory
|
47
|
+
|
48
|
+
|
49
|
+
class << self
|
50
|
+
|
51
|
+
|
52
|
+
# Create a new factory. Returns nil if the GEOS implementation is
|
53
|
+
# not supported.
|
54
|
+
#
|
55
|
+
# Options include:
|
56
|
+
#
|
57
|
+
# <tt>:lenient_multi_polygon_assertions</tt>::
|
58
|
+
# If set to true, assertion checking on MultiPolygon is disabled.
|
59
|
+
# This may speed up creation of MultiPolygon objects, at the
|
60
|
+
# expense of not doing the proper checking for OGC MultiPolygon
|
61
|
+
# compliance. Default is false.
|
62
|
+
# <tt>:buffer_resolution</tt>::
|
63
|
+
# The resolution of buffers around geometries created by this
|
64
|
+
# factory. This controls the number of line segments used to
|
65
|
+
# approximate curves. The default is 1, which causes, for
|
66
|
+
# example, the buffer around a point to be approximated by a
|
67
|
+
# 4-sided polygon. A resolution of 2 would cause that buffer
|
68
|
+
# to be approximated by an 8-sided polygon. The exact behavior
|
69
|
+
# for different kinds of buffers is not well-defined.
|
70
|
+
# <tt>:srid</tt>::
|
71
|
+
# Set the SRID returned by geometries created by this factory.
|
72
|
+
# Default is 0.
|
73
|
+
|
74
|
+
def create(opts_={})
|
75
|
+
return nil unless respond_to?(:_create)
|
76
|
+
flags_ = 0
|
77
|
+
flags_ |= 1 if opts_[:lenient_multi_polygon_assertions]
|
78
|
+
buffer_resolution_ = opts_[:buffer_resolution].to_i
|
79
|
+
buffer_resolution_ = 1 if buffer_resolution_ < 1
|
80
|
+
_create(flags_, opts_[:srid].to_i, buffer_resolution_)
|
81
|
+
end
|
82
|
+
alias_method :new, :create
|
83
|
+
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# Returns the SRID of geometries created by this factory.
|
89
|
+
|
90
|
+
def srid
|
91
|
+
_srid
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# Returns the resolution used by buffer calculations on geometries
|
96
|
+
# created by this factory
|
97
|
+
|
98
|
+
def buffer_resolution
|
99
|
+
_buffer_resolution
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
# Returns true if this factory is lenient with MultiPolygon assertions
|
104
|
+
|
105
|
+
def lenient_multi_polygons?
|
106
|
+
_flags & 0x1 != 0
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# Equivalence test.
|
111
|
+
|
112
|
+
def eql?(rhs_)
|
113
|
+
rhs_.is_a?(Factory) && rhs_.srid == _srid && rhs_._buffer_resolution == _buffer_resolution && rhs_._flags == _flags
|
114
|
+
end
|
115
|
+
alias_method :==, :eql?
|
116
|
+
|
117
|
+
|
118
|
+
# See ::RGeo::Features::Factory#parse_wkt
|
119
|
+
|
120
|
+
def parse_wkt(str_)
|
121
|
+
_parse_wkt_impl(str_)
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
# See ::RGeo::Features::Factory#parse_wkb
|
126
|
+
|
127
|
+
def parse_wkb(str_)
|
128
|
+
_parse_wkb_impl(str_)
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
# See ::RGeo::Features::Factory#point
|
133
|
+
|
134
|
+
def point(x_, y_)
|
135
|
+
PointImpl.create(self, x_, y_) rescue nil
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
# See ::RGeo::Features::Factory#line_string
|
140
|
+
|
141
|
+
def line_string(points_)
|
142
|
+
points_ = points_.to_a unless points_.kind_of?(::Array)
|
143
|
+
LineStringImpl.create(self, points_) rescue nil
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
# See ::RGeo::Features::Factory#line
|
148
|
+
|
149
|
+
def line(start_, end_)
|
150
|
+
LineImpl.create(self, start_, end_) rescue nil
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
# See ::RGeo::Features::Factory#linear_ring
|
155
|
+
|
156
|
+
def linear_ring(points_)
|
157
|
+
points_ = points_.to_a unless points_.kind_of?(::Array)
|
158
|
+
if points_.size > 1 && points_.first != points_.last
|
159
|
+
points_ << points_.first
|
160
|
+
end
|
161
|
+
LinearRingImpl.create(self, points_) rescue nil
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
# See ::RGeo::Features::Factory#polygon
|
166
|
+
|
167
|
+
def polygon(outer_ring_, inner_rings_=nil)
|
168
|
+
inner_rings_ = inner_rings_.to_a unless inner_rings_.kind_of?(::Array)
|
169
|
+
PolygonImpl.create(self, outer_ring_, inner_rings_) rescue nil
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
# See ::RGeo::Features::Factory#collection
|
174
|
+
|
175
|
+
def collection(elems_)
|
176
|
+
elems_ = elems_.to_a unless elems_.kind_of?(::Array)
|
177
|
+
GeometryCollectionImpl.create(self, elems_) rescue nil
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
# See ::RGeo::Features::Factory#multi_point
|
182
|
+
|
183
|
+
def multi_point(elems_)
|
184
|
+
elems_ = elems_.to_a unless elems_.kind_of?(::Array)
|
185
|
+
MultiPointImpl.create(self, elems_) rescue nil
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
# See ::RGeo::Features::Factory#multi_line_string
|
190
|
+
|
191
|
+
def multi_line_string(elems_)
|
192
|
+
elems_ = elems_.to_a unless elems_.kind_of?(::Array)
|
193
|
+
MultiLineStringImpl.create(self, elems_) rescue nil
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
# See ::RGeo::Features::Factory#multi_polygon
|
198
|
+
|
199
|
+
def multi_polygon(elems_)
|
200
|
+
elems_ = elems_.to_a unless elems_.kind_of?(::Array)
|
201
|
+
MultiPolygonImpl.create(self, elems_) rescue nil
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
# See ::RGeo::Features::Factory#convert
|
206
|
+
|
207
|
+
def convert(original_, force_new_=false)
|
208
|
+
return nil unless Geos.supported?
|
209
|
+
case original_
|
210
|
+
when GeometryImpl
|
211
|
+
if original_.factory != self
|
212
|
+
result_ = original_.dup
|
213
|
+
result_.instance_variable_set(:@_factory, self)
|
214
|
+
result_
|
215
|
+
elsif force_new_
|
216
|
+
original_.dup
|
217
|
+
else
|
218
|
+
original_
|
219
|
+
end
|
220
|
+
when Features::Point
|
221
|
+
if original_.respond_to?(:z)
|
222
|
+
PointImpl.create(self, original_.x, original_.y, original_.z)
|
223
|
+
else
|
224
|
+
PointImpl.create(self, original_.x, original_.y)
|
225
|
+
end
|
226
|
+
when Features::Line
|
227
|
+
LineImpl.create(self, original_.start_point, original_.end_point)
|
228
|
+
when Features::LinearRing
|
229
|
+
LinearRingImpl.create(self, original_.points)
|
230
|
+
when Features::LineString
|
231
|
+
LineStringImpl.create(self, original_.points)
|
232
|
+
when Features::Polygon
|
233
|
+
PolygonImpl.create(self, original_.exterior_ring, original_.interior_rings)
|
234
|
+
when Features::MultiPoint
|
235
|
+
MultiPointImpl.create(self, original_.to_a)
|
236
|
+
when Features::MultiLineString
|
237
|
+
MultiLineStringImpl.create(self, original_.to_a)
|
238
|
+
when Features::MultiPolygon
|
239
|
+
MultiPolygonImpl.create(self, original_.to_a)
|
240
|
+
when Features::GeometryCollection
|
241
|
+
GeometryCollectionImpl.create(self, original_.to_a)
|
242
|
+
else
|
243
|
+
nil
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
# A GEOS extension that creates a 3-D point with a Z coordinate.
|
249
|
+
|
250
|
+
def point3d(x_, y_, z_)
|
251
|
+
PointImpl.create3d(self, x_, y_, z_) rescue nil
|
252
|
+
end
|
253
|
+
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|