rgeo 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +6 -0
- data/README.rdoc +1 -1
- data/Version +1 -1
- data/ext/geos_c_impl/extconf.rb +13 -13
- data/ext/geos_c_impl/factory.c +30 -18
- data/ext/geos_c_impl/factory.h +18 -12
- data/ext/geos_c_impl/geometry.c +11 -11
- data/ext/geos_c_impl/geometry.h +7 -7
- data/ext/geos_c_impl/geometry_collection.c +15 -15
- data/ext/geos_c_impl/geometry_collection.h +8 -8
- data/ext/geos_c_impl/line_string.c +14 -14
- data/ext/geos_c_impl/line_string.h +7 -7
- data/ext/geos_c_impl/main.c +7 -7
- data/ext/geos_c_impl/point.c +9 -9
- data/ext/geos_c_impl/point.h +7 -7
- data/ext/geos_c_impl/polygon.c +9 -9
- data/ext/geos_c_impl/polygon.h +7 -7
- data/ext/geos_c_impl/preface.h +7 -7
- data/ext/proj4_c_impl/extconf.rb +13 -13
- data/ext/proj4_c_impl/main.c +12 -12
- data/lib/rgeo.rb +26 -26
- data/lib/rgeo/cartesian.rb +12 -12
- data/lib/rgeo/cartesian/analysis.rb +26 -26
- data/lib/rgeo/cartesian/bounding_box.rb +83 -83
- data/lib/rgeo/cartesian/calculations.rb +36 -36
- data/lib/rgeo/cartesian/factory.rb +78 -78
- data/lib/rgeo/cartesian/feature_classes.rb +74 -74
- data/lib/rgeo/cartesian/feature_methods.rb +34 -34
- data/lib/rgeo/cartesian/interface.rb +33 -33
- data/lib/rgeo/coord_sys.rb +15 -15
- data/lib/rgeo/coord_sys/cs/entities.rb +533 -534
- data/lib/rgeo/coord_sys/cs/factories.rb +69 -69
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +44 -44
- data/lib/rgeo/coord_sys/proj4.rb +85 -85
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/interface.rb +44 -44
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +31 -31
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +29 -29
- data/lib/rgeo/error.rb +17 -17
- data/lib/rgeo/feature.rb +15 -15
- data/lib/rgeo/feature/curve.rb +58 -58
- data/lib/rgeo/feature/factory.rb +84 -84
- data/lib/rgeo/feature/factory_generator.rb +32 -32
- data/lib/rgeo/feature/geometry.rb +215 -215
- data/lib/rgeo/feature/geometry_collection.rb +46 -46
- data/lib/rgeo/feature/line.rb +21 -21
- data/lib/rgeo/feature/line_string.rb +35 -35
- data/lib/rgeo/feature/linear_ring.rb +20 -20
- data/lib/rgeo/feature/mixins.rb +61 -61
- data/lib/rgeo/feature/multi_curve.rb +37 -37
- data/lib/rgeo/feature/multi_line_string.rb +20 -20
- data/lib/rgeo/feature/multi_point.rb +22 -22
- data/lib/rgeo/feature/multi_polygon.rb +28 -28
- data/lib/rgeo/feature/multi_surface.rb +39 -39
- data/lib/rgeo/feature/point.rb +42 -42
- data/lib/rgeo/feature/polygon.rb +50 -50
- data/lib/rgeo/feature/surface.rb +42 -42
- data/lib/rgeo/feature/types.rb +58 -58
- data/lib/rgeo/geographic.rb +14 -14
- data/lib/rgeo/geographic/factory.rb +87 -87
- data/lib/rgeo/geographic/interface.rb +55 -55
- data/lib/rgeo/geographic/proj4_projector.rb +35 -35
- data/lib/rgeo/geographic/projected_feature_classes.rb +95 -95
- data/lib/rgeo/geographic/projected_feature_methods.rb +81 -81
- data/lib/rgeo/geographic/projected_window.rb +103 -103
- data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -32
- data/lib/rgeo/geographic/spherical_feature_classes.rb +93 -93
- data/lib/rgeo/geographic/spherical_feature_methods.rb +25 -25
- data/lib/rgeo/geographic/spherical_math.rb +58 -58
- data/lib/rgeo/geos.rb +22 -17
- data/lib/rgeo/geos/factory.rb +93 -93
- data/lib/rgeo/geos/ffi_classes.rb +306 -231
- data/lib/rgeo/geos/ffi_factory.rb +100 -96
- data/lib/rgeo/geos/impl_additions.rb +22 -22
- data/lib/rgeo/geos/interface.rb +45 -45
- data/lib/rgeo/geos/zm_factory.rb +90 -90
- data/lib/rgeo/geos/zm_impl.rb +167 -167
- data/lib/rgeo/impl_helper.rb +11 -11
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +71 -71
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +29 -29
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +61 -61
- data/lib/rgeo/impl_helper/basic_point_methods.rb +43 -43
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +35 -35
- data/lib/rgeo/impl_helper/math.rb +13 -13
- data/lib/rgeo/version.rb +10 -10
- data/lib/rgeo/wkrep.rb +16 -16
- data/lib/rgeo/wkrep/wkb_generator.rb +51 -51
- data/lib/rgeo/wkrep/wkb_parser.rb +52 -52
- data/lib/rgeo/wkrep/wkt_generator.rb +51 -51
- data/lib/rgeo/wkrep/wkt_parser.rb +66 -66
- data/lib/rgeo/yaml.rb +14 -14
- data/test/common/geometry_collection_tests.rb +53 -53
- data/test/common/line_string_tests.rb +57 -57
- data/test/common/multi_line_string_tests.rb +43 -43
- data/test/common/multi_point_tests.rb +43 -43
- data/test/common/multi_polygon_tests.rb +43 -43
- data/test/common/point_tests.rb +75 -75
- data/test/common/polygon_tests.rb +37 -37
- data/test/coord_sys/tc_active_record_table.rb +25 -25
- data/test/coord_sys/tc_ogc_cs.rb +72 -72
- data/test/coord_sys/tc_proj4.rb +51 -51
- data/test/coord_sys/tc_proj4_srs_data.rb +17 -17
- data/test/coord_sys/tc_sr_org.rb +15 -15
- data/test/coord_sys/tc_url_reader.rb +19 -19
- data/test/geos_capi/tc_factory.rb +21 -21
- data/test/geos_capi/tc_geometry_collection.rb +15 -15
- data/test/geos_capi/tc_line_string.rb +15 -15
- data/test/geos_capi/tc_misc.rb +33 -22
- data/test/geos_capi/tc_multi_line_string.rb +15 -15
- data/test/geos_capi/tc_multi_point.rb +15 -15
- data/test/geos_capi/tc_multi_polygon.rb +15 -15
- data/test/geos_capi/tc_parsing_unparsing.rb +19 -19
- data/test/geos_capi/tc_point.rb +21 -21
- data/test/geos_capi/tc_polygon.rb +19 -19
- data/test/geos_capi/tc_zmfactory.rb +17 -17
- data/test/geos_ffi/tc_factory.rb +21 -21
- data/test/geos_ffi/tc_geometry_collection.rb +15 -15
- data/test/geos_ffi/tc_line_string.rb +15 -15
- data/test/geos_ffi/tc_misc.rb +49 -15
- data/test/geos_ffi/tc_multi_line_string.rb +15 -15
- data/test/geos_ffi/tc_multi_point.rb +15 -15
- data/test/geos_ffi/tc_multi_polygon.rb +15 -15
- data/test/geos_ffi/tc_parsing_unparsing.rb +19 -19
- data/test/geos_ffi/tc_point.rb +21 -21
- data/test/geos_ffi/tc_polygon.rb +19 -19
- data/test/geos_ffi/tc_zmfactory.rb +17 -17
- data/test/projected_geographic/tc_geometry_collection.rb +15 -15
- data/test/projected_geographic/tc_line_string.rb +15 -15
- data/test/projected_geographic/tc_multi_line_string.rb +15 -15
- data/test/projected_geographic/tc_multi_point.rb +15 -15
- data/test/projected_geographic/tc_multi_polygon.rb +15 -15
- data/test/projected_geographic/tc_point.rb +23 -23
- data/test/projected_geographic/tc_polygon.rb +15 -15
- data/test/simple_cartesian/tc_calculations.rb +31 -31
- data/test/simple_cartesian/tc_geometry_collection.rb +17 -17
- data/test/simple_cartesian/tc_line_string.rb +17 -17
- data/test/simple_cartesian/tc_multi_line_string.rb +17 -17
- data/test/simple_cartesian/tc_multi_point.rb +17 -17
- data/test/simple_cartesian/tc_multi_polygon.rb +17 -17
- data/test/simple_cartesian/tc_point.rb +21 -21
- data/test/simple_cartesian/tc_polygon.rb +17 -17
- data/test/simple_mercator/tc_geometry_collection.rb +15 -15
- data/test/simple_mercator/tc_line_string.rb +15 -15
- data/test/simple_mercator/tc_multi_line_string.rb +15 -15
- data/test/simple_mercator/tc_multi_point.rb +15 -15
- data/test/simple_mercator/tc_multi_polygon.rb +15 -15
- data/test/simple_mercator/tc_point.rb +23 -23
- data/test/simple_mercator/tc_polygon.rb +15 -15
- data/test/simple_mercator/tc_window.rb +50 -50
- data/test/spherical_geographic/tc_calculations.rb +47 -47
- data/test/spherical_geographic/tc_geometry_collection.rb +17 -17
- data/test/spherical_geographic/tc_line_string.rb +17 -17
- data/test/spherical_geographic/tc_multi_line_string.rb +17 -17
- data/test/spherical_geographic/tc_multi_point.rb +17 -17
- data/test/spherical_geographic/tc_multi_polygon.rb +17 -17
- data/test/spherical_geographic/tc_point.rb +23 -23
- data/test/spherical_geographic/tc_polygon.rb +17 -17
- data/test/tc_cartesian_analysis.rb +23 -23
- data/test/tc_mixins.rb +39 -39
- data/test/tc_oneoff.rb +15 -15
- data/test/tc_types.rb +17 -17
- data/test/wkrep/tc_wkb_generator.rb +67 -67
- data/test/wkrep/tc_wkb_parser.rb +73 -73
- data/test/wkrep/tc_wkt_generator.rb +75 -75
- data/test/wkrep/tc_wkt_parser.rb +97 -97
- metadata +3 -3
data/lib/rgeo.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# RGeo main file
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -36,74 +36,74 @@
|
|
36
36
|
|
37
37
|
# RGeo is a spatial data library for Ruby. It focuses on the storage and
|
38
38
|
# manipulation of spatial data types such as points, lines, and polygons.
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# RGeo comprises a number of modules. The "rgeo" gem provides a suite of
|
41
41
|
# standard modules. Additional optional modules are provided by separate
|
42
42
|
# gems with names of the form "<tt>rgeo-*</tt>".
|
43
|
-
#
|
43
|
+
#
|
44
44
|
# === Standard modules
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# These are the standard modules provided by the "rgeo" gem.
|
47
|
-
#
|
47
|
+
#
|
48
48
|
# * RGeo::Feature contains interface specifications for spatial
|
49
49
|
# objects implemented by RGeo. These interfaces closely follow the OGC
|
50
50
|
# Simple Features Specifiation (SFS). This module forms the core of RGeo.
|
51
|
-
#
|
51
|
+
#
|
52
52
|
# * RGeo::CoordSys contains classes for representing spatial
|
53
53
|
# reference systems and coordinate transformations. For example, it
|
54
54
|
# includes a wrapper for the Proj4 library, supporting many geographic
|
55
55
|
# projections.
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# * RGeo::Cartesian is a gateway for geometric data implementations
|
58
58
|
# that operate in Caresian (flat) coordinate systems. It also provides a
|
59
59
|
# basic pure ruby Cartesian implementation. This implementation does not
|
60
60
|
# cover all the geometric analysis operations defined by the SFS, but it
|
61
61
|
# does not require an external C library and is often sufficient for
|
62
62
|
# basic applications.
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# * RGeo::Geos is another Cartesian implementation that wraps the
|
65
65
|
# GEOS library to provide a full, high-performance implementation of
|
66
66
|
# Cartesian geometry that includes every operation defined in the SFS.
|
67
67
|
# It requires GEOS 3.2 or later.
|
68
|
-
#
|
68
|
+
#
|
69
69
|
# * RGeo::Geographic contains spatial implementations that operate
|
70
70
|
# in latitude-longitude coordinates and are well-suited for geographic
|
71
71
|
# location based applications. Geographic spatial objects may also be
|
72
72
|
# linked to projections.
|
73
|
-
#
|
73
|
+
#
|
74
74
|
# * RGeo::WKRep contains tools for reading and writing spatial
|
75
75
|
# data in the OGC Well-Known Text (WKT) and Well-Known Binary (WKB)
|
76
76
|
# representations. It also supports common variants such as the PostGIS
|
77
77
|
# EWKT and EWKB representations.
|
78
|
-
#
|
78
|
+
#
|
79
79
|
# === Optional Modules
|
80
|
-
#
|
80
|
+
#
|
81
81
|
# Here is a partial list of optional modules available as separate gems.
|
82
|
-
#
|
82
|
+
#
|
83
83
|
# * <b>rgeo-geojson</b> provides the RGeo::GeoJSON module, containing
|
84
84
|
# tools for GeoJSON encoding and decoding of spatial objects.
|
85
|
-
#
|
85
|
+
#
|
86
86
|
# * <b>rgeo-shapefile</b> provides the RGeo::Shapefile module, containing
|
87
87
|
# tools for reading ESRI shapefiles.
|
88
|
-
#
|
88
|
+
#
|
89
89
|
# * <b>rgeo-activerecord</b> provides the RGeo::ActiveRecord module,
|
90
90
|
# containing some ActiveRecord extensions for spatial databases, and a
|
91
91
|
# set of common tools for ActiveRecord spatial database adapters.
|
92
|
-
#
|
92
|
+
#
|
93
93
|
# Several ActiveRecord adapters use RGeo. These include:
|
94
|
-
#
|
94
|
+
#
|
95
95
|
# * <b>mysqlspatial</b>, an adapter for MySQL spatial extensions based on
|
96
96
|
# the mysql adapter. Available as the activerecord-mysqlspatial-adapter
|
97
97
|
# gem.
|
98
|
-
#
|
98
|
+
#
|
99
99
|
# * <b>mysql2spatial</b>, an adapter for MySQL spatial extensions based on
|
100
100
|
# the mysql2 adapter. Available as the activerecord-mysql2spatial-adapter
|
101
101
|
# gem.
|
102
|
-
#
|
102
|
+
#
|
103
103
|
# * <b>spatialite</b>, an adapter for the SpatiaLite extension to the
|
104
104
|
# Sqlite3 database, and based on the sqlite3 adapter. Available as the
|
105
105
|
# activerecord-spatialite-adapter gem.
|
106
|
-
#
|
106
|
+
#
|
107
107
|
# * <b>postgis</b>, an adapter for the PostGIS extension to the PostgreSQL
|
108
108
|
# database, and based on the postgresql adapter. Available as the
|
109
109
|
# activerecord-postgis-adapter gem.
|
data/lib/rgeo/cartesian.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Cartesian features for RGeo
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,18 +35,18 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
39
|
-
|
38
|
+
|
39
|
+
|
40
40
|
# The Cartesian module is a gateway to implementations that use the
|
41
41
|
# Cartesian (i.e. flat) coordinate system. It provides convenient
|
42
42
|
# access to Cartesian factories such as the Geos implementation and
|
43
43
|
# the simple Cartesian implementation. It also provides a namespace
|
44
44
|
# for Cartesian-specific analysis tools.
|
45
|
-
|
45
|
+
|
46
46
|
module Cartesian
|
47
47
|
end
|
48
|
-
|
49
|
-
|
48
|
+
|
49
|
+
|
50
50
|
end
|
51
51
|
|
52
52
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Cartesian
|
4
|
-
#
|
2
|
+
#
|
3
|
+
# Cartesian geometric analysis utilities
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,30 +35,30 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
38
|
+
|
39
39
|
module Cartesian
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# This provides includes some spatial analysis algorithms supporting
|
43
43
|
# Cartesian data.
|
44
|
-
|
44
|
+
|
45
45
|
module Analysis
|
46
|
-
|
46
|
+
|
47
47
|
class << self
|
48
|
-
|
49
|
-
|
48
|
+
|
49
|
+
|
50
50
|
# Given a LineString, which must be a ring, determine whether the
|
51
51
|
# ring proceeds clockwise or counterclockwise.
|
52
52
|
# Returns 1 for counterclockwise, or -1 for clockwise.
|
53
|
-
#
|
53
|
+
#
|
54
54
|
# Returns 0 if the ring is empty.
|
55
55
|
# The return value is undefined if the object is not a ring, or
|
56
56
|
# is not in a Cartesian coordinate system.
|
57
|
-
|
57
|
+
|
58
58
|
def ring_direction(ring_)
|
59
59
|
size_ = ring_.num_points - 1
|
60
60
|
return 0 if size_ == 0
|
61
|
-
|
61
|
+
|
62
62
|
# Extract unit-length segments from the ring.
|
63
63
|
segs_ = []
|
64
64
|
size_.times do |i_|
|
@@ -74,7 +74,7 @@ module RGeo
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
segs_ << segs_[0] << segs_[1]
|
77
|
-
|
77
|
+
|
78
78
|
# Extract angles from the segments by subtracting the segments.
|
79
79
|
# Note angles are represented as cos/sin pairs so we don't
|
80
80
|
# have to calculate any trig functions.
|
@@ -83,7 +83,7 @@ module RGeo
|
|
83
83
|
x0_, y0_, x1_, y1_ = segs_[i_*2,4]
|
84
84
|
angs_ << x0_*x1_ + y0_*y1_ << x0_*y1_ - x1_*y0_
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
# Now add the angles and count revolutions.
|
88
88
|
# Again, our running sum is represented as a cos/sin pair.
|
89
89
|
revolutions_ = 0
|
@@ -108,13 +108,13 @@ module RGeo
|
|
108
108
|
end
|
109
109
|
revolutions_
|
110
110
|
end
|
111
|
-
|
112
|
-
|
111
|
+
|
112
|
+
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
end
|
116
|
-
|
117
|
-
|
116
|
+
|
117
|
+
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# Cartesian
|
4
|
-
#
|
2
|
+
#
|
3
|
+
# Cartesian bounding box
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,50 +35,50 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
38
|
+
|
39
39
|
module Cartesian
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# This is a bounding box for Cartesian data.
|
43
43
|
# The simple cartesian implementation uses this internally to compute
|
44
44
|
# envelopes. You may also use it directly to compute and represent
|
45
45
|
# bounding boxes.
|
46
|
-
#
|
46
|
+
#
|
47
47
|
# A bounding box is a set of ranges in each dimension: X, Y, as well
|
48
48
|
# as Z and M if supported. You can compute a bounding box for one or
|
49
49
|
# more geometry objects by creating a new bounding box object, and
|
50
50
|
# adding the geometries to it. You may then query it for the bounds,
|
51
51
|
# or use it to determine whether it encloses other geometries or
|
52
52
|
# bounding boxes.
|
53
|
-
|
53
|
+
|
54
54
|
class BoundingBox
|
55
|
-
|
56
|
-
|
55
|
+
|
56
|
+
|
57
57
|
# Create a new empty bounding box with the given factory.
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# The factory defines the coordinate system for the bounding box,
|
60
60
|
# and also defines whether it should track Z and M coordinates.
|
61
61
|
# All geometries will be cast to this factory when added to this
|
62
62
|
# bounding box, and any generated envelope geometry will have this
|
63
63
|
# as its factory.
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# Options include:
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# [<tt>:ignore_z</tt>]
|
68
68
|
# If true, ignore z coordinates even if the factory supports them.
|
69
69
|
# Default is false.
|
70
70
|
# [<tt>:ignore_m</tt>]
|
71
71
|
# If true, ignore m coordinates even if the factory supports them.
|
72
72
|
# Default is false.
|
73
|
-
|
73
|
+
|
74
74
|
def initialize(factory_, opts_={})
|
75
75
|
@factory = factory_
|
76
76
|
@has_z = !opts_[:ignore_z] && factory_.property(:has_z_coordinate) ? true : false
|
77
77
|
@has_m = !opts_[:ignore_m] && factory_.property(:has_m_coordinate) ? true : false
|
78
78
|
@min_x = @max_x = @min_y = @max_y = @min_z = @max_z = @min_m = @max_m = nil
|
79
79
|
end
|
80
|
-
|
81
|
-
|
80
|
+
|
81
|
+
|
82
82
|
def eql?(rhs_) # :nodoc:
|
83
83
|
rhs_.is_a?(BoundingBox) && @factory == rhs_.factory &&
|
84
84
|
@min_x == rhs_.min_x && @max_x == rhs_.max_x &&
|
@@ -87,95 +87,95 @@ module RGeo
|
|
87
87
|
@min_m == rhs_.min_m && @max_m == rhs_.max_m
|
88
88
|
end
|
89
89
|
alias_method :==, :eql?
|
90
|
-
|
91
|
-
|
90
|
+
|
91
|
+
|
92
92
|
# Returns the bounding box's factory.
|
93
|
-
|
93
|
+
|
94
94
|
def factory
|
95
95
|
@factory
|
96
96
|
end
|
97
|
-
|
98
|
-
|
97
|
+
|
98
|
+
|
99
99
|
# Returns true if this bounding box is still empty.
|
100
|
-
|
100
|
+
|
101
101
|
def empty?
|
102
102
|
@min_x.nil?
|
103
103
|
end
|
104
|
-
|
105
|
-
|
104
|
+
|
105
|
+
|
106
106
|
# Returns true if this bounding box tracks Z coordinates.
|
107
|
-
|
107
|
+
|
108
108
|
def has_z
|
109
109
|
@has_z
|
110
110
|
end
|
111
|
-
|
112
|
-
|
111
|
+
|
112
|
+
|
113
113
|
# Returns true if this bounding box tracks M coordinates.
|
114
|
-
|
114
|
+
|
115
115
|
def has_m
|
116
116
|
@has_m
|
117
117
|
end
|
118
|
-
|
119
|
-
|
118
|
+
|
119
|
+
|
120
120
|
# Returns the minimum X, or nil if this bounding box is empty.
|
121
|
-
|
121
|
+
|
122
122
|
def min_x
|
123
123
|
@min_x
|
124
124
|
end
|
125
|
-
|
126
|
-
|
125
|
+
|
126
|
+
|
127
127
|
# Returns the maximum X, or nil if this bounding box is empty.
|
128
|
-
|
128
|
+
|
129
129
|
def max_x
|
130
130
|
@max_x
|
131
131
|
end
|
132
|
-
|
133
|
-
|
132
|
+
|
133
|
+
|
134
134
|
# Returns the minimum Y, or nil if this bounding box is empty.
|
135
|
-
|
135
|
+
|
136
136
|
def min_y
|
137
137
|
@min_y
|
138
138
|
end
|
139
|
-
|
140
|
-
|
139
|
+
|
140
|
+
|
141
141
|
# Returns the maximum Y, or nil if this bounding box is empty.
|
142
|
-
|
142
|
+
|
143
143
|
def max_y
|
144
144
|
@max_y
|
145
145
|
end
|
146
|
-
|
147
|
-
|
146
|
+
|
147
|
+
|
148
148
|
# Returns the minimum Z, or nil if this bounding box is empty.
|
149
|
-
|
149
|
+
|
150
150
|
def min_z
|
151
151
|
@min_z
|
152
152
|
end
|
153
|
-
|
154
|
-
|
153
|
+
|
154
|
+
|
155
155
|
# Returns the maximum Z, or nil if this bounding box is empty.
|
156
|
-
|
156
|
+
|
157
157
|
def max_z
|
158
158
|
@max_z
|
159
159
|
end
|
160
|
-
|
161
|
-
|
160
|
+
|
161
|
+
|
162
162
|
# Returns the minimum M, or nil if this bounding box is empty.
|
163
|
-
|
163
|
+
|
164
164
|
def min_m
|
165
165
|
@min_m
|
166
166
|
end
|
167
|
-
|
168
|
-
|
167
|
+
|
168
|
+
|
169
169
|
# Returns the maximum M, or nil if this bounding box is empty.
|
170
|
-
|
170
|
+
|
171
171
|
def max_m
|
172
172
|
@max_m
|
173
173
|
end
|
174
|
-
|
175
|
-
|
174
|
+
|
175
|
+
|
176
176
|
# Returns a point representing the minimum extent in all dimensions,
|
177
177
|
# or nil if this bounding box is empty.
|
178
|
-
|
178
|
+
|
179
179
|
def min_point
|
180
180
|
if @min_x
|
181
181
|
extras_ = []
|
@@ -186,11 +186,11 @@ module RGeo
|
|
186
186
|
nil
|
187
187
|
end
|
188
188
|
end
|
189
|
-
|
190
|
-
|
189
|
+
|
190
|
+
|
191
191
|
# Returns a point representing the maximum extent in all dimensions,
|
192
192
|
# or nil if this bounding box is empty.
|
193
|
-
|
193
|
+
|
194
194
|
def max_point
|
195
195
|
if @min_x
|
196
196
|
extras_ = []
|
@@ -201,12 +201,12 @@ module RGeo
|
|
201
201
|
nil
|
202
202
|
end
|
203
203
|
end
|
204
|
-
|
205
|
-
|
204
|
+
|
205
|
+
|
206
206
|
# Adjusts the extents of this bounding box to encompass the given
|
207
207
|
# object, which may be a geometry or another bounding box.
|
208
208
|
# Returns self.
|
209
|
-
|
209
|
+
|
210
210
|
def add(geometry_)
|
211
211
|
case geometry_
|
212
212
|
when BoundingBox
|
@@ -221,11 +221,11 @@ module RGeo
|
|
221
221
|
end
|
222
222
|
self
|
223
223
|
end
|
224
|
-
|
225
|
-
|
224
|
+
|
225
|
+
|
226
226
|
# Converts this bounding box to an envelope polygon.
|
227
227
|
# Returns the empty collection if this bounding box is empty.
|
228
|
-
|
228
|
+
|
229
229
|
def to_geometry
|
230
230
|
if @min_x
|
231
231
|
extras_ = []
|
@@ -251,20 +251,20 @@ module RGeo
|
|
251
251
|
@factory.collection([])
|
252
252
|
end
|
253
253
|
end
|
254
|
-
|
255
|
-
|
254
|
+
|
255
|
+
|
256
256
|
# Returns true if this bounding box contains the given object,
|
257
257
|
# which may be a geometry or another bounding box.
|
258
|
-
#
|
258
|
+
#
|
259
259
|
# Supports these options:
|
260
|
-
#
|
260
|
+
#
|
261
261
|
# [<tt>:ignore_z</tt>]
|
262
262
|
# Ignore the Z coordinate when testing, even if both objects
|
263
263
|
# have Z. Default is false.
|
264
264
|
# [<tt>:ignore_m</tt>]
|
265
265
|
# Ignore the M coordinate when testing, even if both objects
|
266
266
|
# have M. Default is false.
|
267
|
-
|
267
|
+
|
268
268
|
def contains?(rhs_, opts_={})
|
269
269
|
if Feature::Geometry === rhs_
|
270
270
|
contains?(BoundingBox.new(@factory).add(rhs_))
|
@@ -282,8 +282,8 @@ module RGeo
|
|
282
282
|
true
|
283
283
|
end
|
284
284
|
end
|
285
|
-
|
286
|
-
|
285
|
+
|
286
|
+
|
287
287
|
def _add_geometry(geometry_) # :nodoc:
|
288
288
|
case geometry_
|
289
289
|
when Feature::Point
|
@@ -302,8 +302,8 @@ module RGeo
|
|
302
302
|
geometry_.each{ |g_| _add_geometry(g_) }
|
303
303
|
end
|
304
304
|
end
|
305
|
-
|
306
|
-
|
305
|
+
|
306
|
+
|
307
307
|
def _add_point(point_) # :nodoc:
|
308
308
|
if @min_x
|
309
309
|
x_ = point_.x
|
@@ -329,11 +329,11 @@ module RGeo
|
|
329
329
|
@min_m = @max_m = point_.m if @has_m
|
330
330
|
end
|
331
331
|
end
|
332
|
-
|
333
|
-
|
332
|
+
|
333
|
+
|
334
334
|
end
|
335
|
-
|
336
|
-
|
335
|
+
|
336
|
+
|
337
337
|
end
|
338
|
-
|
338
|
+
|
339
339
|
end
|