rgeo 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,90 @@
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
+ class UrlReader
48
+
49
+
50
+ def initialize(opts_={})
51
+ @cache = opts_[:cache] ? {} : nil
52
+ end
53
+
54
+
55
+ def get(ident_)
56
+ ident_ = ident_.to_s
57
+ return @cache[ident_] if @cache && @cache.include?(ident_)
58
+ uri_ = ::URI.parse(ident_)
59
+ result_ = nil
60
+ ::Net::HTTP.start(uri_.host, uri_.port) do |http_|
61
+ request_ = uri_.path
62
+ request_ = "#{request_}?#{uri_.query}" if uri_.query
63
+ response_ = http_.request_get(request_)
64
+ if response_.kind_of?(::Net::HTTPSuccess)
65
+ response_ = response_.body.strip
66
+ if response_[0,1] == '+'
67
+ result_ = Entry.new(ident_, :proj4 => response_)
68
+ else
69
+ result_ = Entry.new(ident_, :coord_sys => response_)
70
+ end
71
+ end
72
+ end
73
+ @cache[ident_] = result_ if @cache
74
+ result_
75
+ end
76
+
77
+
78
+ def clear_cache
79
+ @cache.clear if @cache
80
+ end
81
+
82
+
83
+ end
84
+
85
+
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -39,6 +39,14 @@ module RGeo
39
39
  module Feature
40
40
 
41
41
 
42
+ # All geometry implementations MUST include this submodule.
43
+ # This serves as a marker that may be used to test an object for
44
+ # feature-ness.
45
+
46
+ module Instance
47
+ end
48
+
49
+
42
50
  # These methods are available as module methods (not instance methods)
43
51
  # of the various feature types.
44
52
  # For example, you may determine whether a feature object is a
@@ -57,12 +65,8 @@ module RGeo
57
65
  module Type
58
66
 
59
67
 
60
- # All geometry implementations MUST include this submodule.
61
- # This serves as a marker that may be used to test an object for
62
- # feature-ness.
63
-
64
- module Instance
65
- end
68
+ # Deprecated alias for RGeo::Feature::Instance
69
+ Instance = Feature::Instance
66
70
 
67
71
 
68
72
  # Returns true if the given object is this type or a subtype
@@ -72,7 +76,7 @@ module RGeo
72
76
  # Note that feature objects need not actually include this module.
73
77
 
74
78
  def check_type(rhs_)
75
- rhs_ = rhs_.geometry_type if rhs_.kind_of?(Instance)
79
+ rhs_ = rhs_.geometry_type if rhs_.kind_of?(Feature::Instance)
76
80
  rhs_.kind_of?(Type) && (rhs_ == self || rhs_.include?(self))
77
81
  end
78
82
  alias_method :===, :check_type
@@ -74,8 +74,13 @@ module RGeo
74
74
  else
75
75
  proj4_ = nil
76
76
  end
77
+ coord_sys_ = opts_[:coord_sys]
78
+ if coord_sys_.kind_of?(::String)
79
+ coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_) rescue nil
80
+ end
77
81
  result_ = _create(flags_, opts_[:srid].to_i, buffer_resolution_)
78
82
  result_.instance_variable_set(:@proj4, proj4_)
83
+ result_.instance_variable_set(:@coord_sys, coord_sys_)
79
84
  result_
80
85
  end
81
86
  alias_method :new, :create
@@ -233,7 +238,7 @@ module RGeo
233
238
  # See ::RGeo::Feature::Factory#coord_sys
234
239
 
235
240
  def coord_sys
236
- nil
241
+ @coord_sys
237
242
  end
238
243
 
239
244
 
@@ -40,7 +40,7 @@ module RGeo
40
40
 
41
41
  class GeometryImpl # :nodoc:
42
42
 
43
- include ::RGeo::Feature::Type::Instance
43
+ include Feature::Instance
44
44
 
45
45
  def inspect
46
46
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
@@ -41,7 +41,7 @@ module RGeo
41
41
 
42
42
  class ZMGeometryImpl # :nodoc:
43
43
 
44
- include Feature::Type::Instance
44
+ include Feature::Instance
45
45
 
46
46
 
47
47
  def initialize(factory_, zgeometry_, mgeometry_)
@@ -41,7 +41,7 @@ module RGeo
41
41
 
42
42
  module BasicGeometryMethods # :nodoc:
43
43
 
44
- include ::RGeo::Feature::Type::Instance
44
+ include Feature::Instance
45
45
 
46
46
 
47
47
  def inspect # :nodoc:
@@ -0,0 +1,97 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for OGC CS classes
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 'test/unit'
38
+ require 'rgeo'
39
+ require 'yaml'
40
+
41
+
42
+ module RGeo
43
+ module Tests # :nodoc:
44
+ module CoordSys # :nodoc:
45
+ module ActiveRecordTableTests # :nodoc:
46
+
47
+ database_configs_ = ::YAML.load_file(::File.dirname(__FILE__)+'/database.yml') rescue nil
48
+
49
+ if database_configs_
50
+
51
+ require 'active_record'
52
+
53
+ PostGIS_CONFIG = database_configs_['postgis'] rescue nil
54
+
55
+
56
+ if PostGIS_CONFIG
57
+
58
+ class TestPostGIS < ::Test::Unit::TestCase # :nodoc:
59
+
60
+ class ARBase < ::ActiveRecord::Base
61
+ establish_connection(PostGIS_CONFIG)
62
+ end
63
+
64
+ @@db = ::RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new(:ar_base_class => ARBase, :auth_name_column => 'auth_name', :auth_srid_column => 'auth_srid', :srtext_column => 'srtext', :proj4text_column => 'proj4text')
65
+
66
+
67
+ def test_4326
68
+ entry_ = @@db.get(4326)
69
+ assert_equal('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs', entry_.proj4.original_str)
70
+ assert_kind_of(::RGeo::CoordSys::CS::GeographicCoordinateSystem, entry_.coord_sys)
71
+ assert_equal('WGS 84', entry_.name)
72
+ end
73
+
74
+
75
+ def test_3785
76
+ entry_ = @@db.get(3785)
77
+ assert_equal('+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs', entry_.proj4.original_str)
78
+ assert_kind_of(::RGeo::CoordSys::CS::ProjectedCoordinateSystem, entry_.coord_sys)
79
+ assert_equal('Popular Visualisation CRS / Mercator (deprecated)', entry_.name)
80
+ end
81
+
82
+
83
+ end
84
+
85
+ else
86
+ puts "WARNING: No postgis section in database.yml; skipping PostGIS tests."
87
+ end
88
+
89
+
90
+ else
91
+ puts "WARNING: Couldn't find database.yml; skipping ActiveRecord tests."
92
+ end
93
+
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,356 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for OGC CS classes
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 'test/unit'
38
+ require 'rgeo'
39
+
40
+
41
+ module RGeo
42
+ module Tests # :nodoc:
43
+ module CoordSys # :nodoc:
44
+
45
+ class TestOgcCs < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def test_axis_info_by_value
49
+ obj_ = ::RGeo::CoordSys::CS::AxisInfo.create('N', ::RGeo::CoordSys::CS::AO_NORTH)
50
+ assert_equal('N', obj_.name)
51
+ assert_equal(::RGeo::CoordSys::CS::AO_NORTH, obj_.orientation)
52
+ assert_equal('AXIS["N",NORTH]', obj_.to_wkt)
53
+ end
54
+
55
+
56
+ def test_axis_info_by_name
57
+ obj_ = ::RGeo::CoordSys::CS::AxisInfo.create('S', 'SOUTH')
58
+ assert_equal('S', obj_.name)
59
+ assert_equal(::RGeo::CoordSys::CS::AO_SOUTH, obj_.orientation)
60
+ assert_equal('AXIS["S",SOUTH]', obj_.to_wkt)
61
+ obj2_ = ::RGeo::CoordSys::CS::AxisInfo.create('S', ::RGeo::CoordSys::CS::AO_SOUTH)
62
+ assert_equal(obj_, obj2_)
63
+ end
64
+
65
+
66
+ def test_parameter
67
+ obj_ = ::RGeo::CoordSys::CS::ProjectionParameter.create('false_easting', 400000)
68
+ assert_equal('false_easting', obj_.name)
69
+ assert_equal(400000, obj_.value)
70
+ assert_equal('PARAMETER["false_easting",400000.0]', obj_.to_wkt)
71
+ end
72
+
73
+
74
+ def test_towgs84
75
+ obj_ = ::RGeo::CoordSys::CS::WGS84ConversionInfo.create(1, 2, 3, 4, 5, 6, 7)
76
+ assert_equal(1, obj_.dx)
77
+ assert_equal(2, obj_.dy)
78
+ assert_equal(3, obj_.dz)
79
+ assert_equal(4, obj_.ex)
80
+ assert_equal(5, obj_.ey)
81
+ assert_equal(6, obj_.ez)
82
+ assert_equal(7, obj_.ppm)
83
+ assert_equal('TOWGS84[1.0,2.0,3.0,4.0,5.0,6.0,7.0]', obj_.to_wkt)
84
+ end
85
+
86
+
87
+ def test_unit
88
+ obj_ = ::RGeo::CoordSys::CS::Unit.create('metre', 1)
89
+ assert_equal('metre', obj_.name)
90
+ assert_equal(1, obj_.conversion_factor)
91
+ assert_nil(obj_.authority)
92
+ assert_equal('UNIT["metre",1.0]', obj_.to_wkt)
93
+ end
94
+
95
+
96
+ def test_unit_with_authority
97
+ obj_ = ::RGeo::CoordSys::CS::Unit.create('metre', 1, 'EPSG', 9001)
98
+ assert_equal('metre', obj_.name)
99
+ assert_equal(1, obj_.conversion_factor)
100
+ assert_equal('EPSG', obj_.authority)
101
+ assert_equal('9001', obj_.authority_code)
102
+ assert_equal('UNIT["metre",1.0,AUTHORITY["EPSG","9001"]]', obj_.to_wkt)
103
+ end
104
+
105
+
106
+ def test_linear_unit
107
+ obj_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1)
108
+ assert_equal(1, obj_.meters_per_unit)
109
+ assert_equal('UNIT["metre",1.0]', obj_.to_wkt)
110
+ end
111
+
112
+
113
+ def test_angular_unit
114
+ obj_ = ::RGeo::CoordSys::CS::AngularUnit.create('radian', 1)
115
+ assert_equal(1, obj_.radians_per_unit)
116
+ assert_equal('UNIT["radian",1.0]', obj_.to_wkt)
117
+ end
118
+
119
+
120
+ def test_prime_meridian
121
+ obj1_ = ::RGeo::CoordSys::CS::AngularUnit.create('radian', 1)
122
+ obj_ = ::RGeo::CoordSys::CS::PrimeMeridian.create('Greenwich', obj1_, 0, 'EPSG', '8901')
123
+ assert_equal('Greenwich', obj_.name)
124
+ assert_equal(0, obj_.longitude)
125
+ assert_equal('PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]]', obj_.to_wkt)
126
+ end
127
+
128
+
129
+ def test_create_flattened_sphere
130
+ obj1_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1)
131
+ obj_ = ::RGeo::CoordSys::CS::Ellipsoid.create_flattened_sphere('WGS 84', 6378137, 298.257223563, obj1_, 'EPSG', '7030')
132
+ assert_equal('WGS 84', obj_.name)
133
+ assert_equal(6378137, obj_.semi_major_axis)
134
+ assert_in_delta(298.257223563, obj_.inverse_flattening, 0.1)
135
+ assert_in_delta(6356752.314245, obj_.semi_minor_axis, 0.1)
136
+ assert_equal('EPSG', obj_.authority)
137
+ assert_equal('7030', obj_.authority_code)
138
+ assert_equal('SPHEROID["WGS 84",6378137.0,298.257223563,AUTHORITY["EPSG","7030"]]', obj_.to_wkt)
139
+ end
140
+
141
+
142
+ def test_create_unflattened_sphere
143
+ obj1_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1)
144
+ obj_ = ::RGeo::CoordSys::CS::Ellipsoid.create_flattened_sphere('Popular Visualisation Sphere', 6378137, 0, obj1_, 'EPSG', '7059')
145
+ assert_equal('Popular Visualisation Sphere', obj_.name)
146
+ assert_equal(6378137, obj_.semi_major_axis)
147
+ assert_equal(0, obj_.inverse_flattening)
148
+ assert_equal(6378137, obj_.semi_minor_axis)
149
+ assert_equal('EPSG', obj_.authority)
150
+ assert_equal('7059', obj_.authority_code)
151
+ assert_equal('SPHEROID["Popular Visualisation Sphere",6378137.0,0.0,AUTHORITY["EPSG","7059"]]', obj_.to_wkt)
152
+ end
153
+
154
+
155
+ def test_create_ellipsoid
156
+ obj1_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1)
157
+ obj_ = ::RGeo::CoordSys::CS::Ellipsoid.create_ellipsoid('WGS 84', 6378137, 6356752.314245, obj1_, 'EPSG', '7030')
158
+ assert_in_delta(298.257223563, obj_.inverse_flattening, 0.1)
159
+ end
160
+
161
+
162
+ def test_create_spherical_ellipsoid
163
+ obj1_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1)
164
+ obj_ = ::RGeo::CoordSys::CS::Ellipsoid.create_ellipsoid('Popular Visualisation Sphere', 6378137, 6378137, obj1_, 'EPSG', '7059')
165
+ assert_equal(0, obj_.inverse_flattening)
166
+ end
167
+
168
+
169
+ def test_local_datum
170
+ obj_ = ::RGeo::CoordSys::CS::LocalDatum.create('Random Local Datum', ::RGeo::CoordSys::CS::LD_MIN)
171
+ assert_equal('Random Local Datum', obj_.name)
172
+ assert_equal(::RGeo::CoordSys::CS::LD_MIN, obj_.datum_type)
173
+ assert_equal('LOCAL_DATUM["Random Local Datum",10000]', obj_.to_wkt)
174
+ end
175
+
176
+
177
+ def test_vertical_datum
178
+ obj_ = ::RGeo::CoordSys::CS::VerticalDatum.create('Ordnance Datum Newlyn', ::RGeo::CoordSys::CS::VD_GEOID_MODE_DERIVED, 'EPSG', '5101')
179
+ assert_equal('Ordnance Datum Newlyn', obj_.name)
180
+ assert_equal(::RGeo::CoordSys::CS::VD_GEOID_MODE_DERIVED, obj_.datum_type)
181
+ assert_equal('EPSG', obj_.authority)
182
+ assert_equal('5101', obj_.authority_code)
183
+ assert_equal('VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["EPSG","5101"]]', obj_.to_wkt)
184
+ end
185
+
186
+
187
+ def test_horizontal_datum
188
+ obj1_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1)
189
+ obj2_ = ::RGeo::CoordSys::CS::Ellipsoid.create_ellipsoid('Popular Visualisation Sphere', 6378137, 6378137, obj1_, 'EPSG', '7059')
190
+ obj3_ = ::RGeo::CoordSys::CS::WGS84ConversionInfo.create(0, 0, 0, 0, 0, 0, 0)
191
+ obj_ = ::RGeo::CoordSys::CS::HorizontalDatum.create('Popular_Visualisation_Datum', ::RGeo::CoordSys::CS::HD_GEOCENTRIC, obj2_, obj3_, 'EPSG', '6055')
192
+ assert_equal('Popular_Visualisation_Datum', obj_.name)
193
+ assert_equal(::RGeo::CoordSys::CS::HD_GEOCENTRIC, obj_.datum_type)
194
+ assert_equal('EPSG', obj_.authority)
195
+ assert_equal('6055', obj_.authority_code)
196
+ assert_equal('DATUM["Popular_Visualisation_Datum",SPHEROID["Popular Visualisation Sphere",6378137.0,0.0,AUTHORITY["EPSG","7059"]],TOWGS84[0.0,0.0,0.0,0.0,0.0,0.0,0.0],AUTHORITY["EPSG","6055"]]', obj_.to_wkt)
197
+ end
198
+
199
+
200
+ def test_projection
201
+ obj_ = ::RGeo::CoordSys::CS::Projection.create('Transverse_Mercator', 'Transverse_Mercator', [])
202
+ assert_equal('Transverse_Mercator', obj_.name)
203
+ assert_equal('Transverse_Mercator', obj_.class_name)
204
+ assert_equal(0, obj_.num_parameters)
205
+ assert_equal('PROJECTION["Transverse_Mercator"]', obj_.to_wkt)
206
+ end
207
+
208
+
209
+ def test_local_coordinate_system
210
+ obj1_ = ::RGeo::CoordSys::CS::LocalDatum.create('Random Local Datum', ::RGeo::CoordSys::CS::LD_MIN)
211
+ obj2_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1, 'EPSG', 9001)
212
+ obj3_ = ::RGeo::CoordSys::CS::AxisInfo.create('N', ::RGeo::CoordSys::CS::AO_NORTH)
213
+ obj4_ = ::RGeo::CoordSys::CS::AxisInfo.create('E', ::RGeo::CoordSys::CS::AO_EAST)
214
+ obj_ = ::RGeo::CoordSys::CS::LocalCoordinateSystem.create('My CS', obj1_, obj2_, [obj3_, obj4_])
215
+ assert_equal('My CS', obj_.name)
216
+ assert_equal(2, obj_.dimension)
217
+ assert_equal('Random Local Datum', obj_.local_datum.name)
218
+ assert_equal('N', obj_.get_axis(0).name)
219
+ assert_equal('E', obj_.get_axis(1).name)
220
+ assert_equal('metre', obj_.get_units(0).name)
221
+ assert_equal('metre', obj_.get_units(1).name)
222
+ assert_equal('LOCAL_CS["My CS",LOCAL_DATUM["Random Local Datum",10000],UNIT["metre",1.0,AUTHORITY["EPSG","9001"]],AXIS["N",NORTH],AXIS["E",EAST]]', obj_.to_wkt)
223
+ end
224
+
225
+
226
+ def test_geocentric_coordinate_system
227
+ obj1_ = ::RGeo::CoordSys::CS::Ellipsoid.create_flattened_sphere('WGS 84', 6378137, 298.257223563, nil, 'EPSG', '7030')
228
+ obj2_ = ::RGeo::CoordSys::CS::HorizontalDatum.create('World Geodetic System 1984', ::RGeo::CoordSys::CS::HD_GEOCENTRIC, obj1_, nil, 'EPSG', '6326')
229
+ obj3_ = ::RGeo::CoordSys::CS::PrimeMeridian.create('Greenwich', nil, 0.0, 'EPSG', '8901')
230
+ obj4_ = ::RGeo::CoordSys::CS::LinearUnit.create('m', 1.0)
231
+ obj5_ = ::RGeo::CoordSys::CS::AxisInfo.create('Geocentric X', ::RGeo::CoordSys::CS::AO_OTHER)
232
+ obj6_ = ::RGeo::CoordSys::CS::AxisInfo.create('Geocentric Y', ::RGeo::CoordSys::CS::AO_EAST)
233
+ obj7_ = ::RGeo::CoordSys::CS::AxisInfo.create('Geocentric Z', ::RGeo::CoordSys::CS::AO_NORTH)
234
+ obj_ = ::RGeo::CoordSys::CS::GeocentricCoordinateSystem.create('WGS 84 (geocentric)', obj2_, obj3_, obj4_, obj5_, obj6_, obj7_, 'EPSG', 4328)
235
+ assert_equal('WGS 84 (geocentric)', obj_.name)
236
+ assert_equal(3, obj_.dimension)
237
+ assert_equal('World Geodetic System 1984', obj_.horizontal_datum.name)
238
+ assert_equal('Greenwich', obj_.prime_meridian.name)
239
+ assert_equal('m', obj_.linear_unit.name)
240
+ assert_equal('Geocentric X', obj_.get_axis(0).name)
241
+ assert_equal('Geocentric Y', obj_.get_axis(1).name)
242
+ assert_equal('Geocentric Z', obj_.get_axis(2).name)
243
+ assert_equal('m', obj_.get_units(0).name)
244
+ assert_equal('m', obj_.get_units(1).name)
245
+ assert_equal('m', obj_.get_units(2).name)
246
+ assert_equal('GEOCCS["WGS 84 (geocentric)",DATUM["World Geodetic System 1984",SPHEROID["WGS 84",6378137.0,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["m",1.0],AXIS["Geocentric X",OTHER],AXIS["Geocentric Y",EAST],AXIS["Geocentric Z",NORTH],AUTHORITY["EPSG","4328"]]', obj_.to_wkt)
247
+ end
248
+
249
+
250
+ def test_vertical_coordinate_system
251
+ obj1_ = ::RGeo::CoordSys::CS::VerticalDatum.create('Ordnance Datum Newlyn', ::RGeo::CoordSys::CS::VD_GEOID_MODE_DERIVED, 'EPSG', 5101)
252
+ obj2_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1, 'EPSG', 9001)
253
+ obj3_ = ::RGeo::CoordSys::CS::AxisInfo.create('Up', ::RGeo::CoordSys::CS::AO_UP)
254
+ obj_ = ::RGeo::CoordSys::CS::VerticalCoordinateSystem.create('Newlyn', obj1_, obj2_, obj3_, 'EPSG', 5701)
255
+ assert_equal('Newlyn', obj_.name)
256
+ assert_equal(1, obj_.dimension)
257
+ assert_equal('Ordnance Datum Newlyn', obj_.vertical_datum.name)
258
+ assert_equal('metre', obj_.vertical_unit.name)
259
+ assert_equal('Up', obj_.get_axis(0).name)
260
+ assert_equal('metre', obj_.get_units(0).name)
261
+ assert_equal('VERT_CS["Newlyn",VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["EPSG","5101"]],UNIT["metre",1.0,AUTHORITY["EPSG","9001"]],AXIS["Up",UP],AUTHORITY["EPSG","5701"]]', obj_.to_wkt)
262
+ end
263
+
264
+
265
+ def test_geographic_coordinate_system
266
+ obj1_ = ::RGeo::CoordSys::CS::Ellipsoid.create_flattened_sphere('WGS 84', 6378137, 298.257223563, nil, 'EPSG', '7030')
267
+ obj2_ = ::RGeo::CoordSys::CS::AngularUnit.create('degree', 0.01745329251994328, 'EPSG', 9122)
268
+ obj3_ = ::RGeo::CoordSys::CS::HorizontalDatum.create('WGS_1984', ::RGeo::CoordSys::CS::HD_GEOCENTRIC, obj1_, nil, 'EPSG', '6326')
269
+ obj4_ = ::RGeo::CoordSys::CS::PrimeMeridian.create('Greenwich', nil, 0, 'EPSG', '8901')
270
+ obj_ = ::RGeo::CoordSys::CS::GeographicCoordinateSystem.create('WGS 84', obj2_, obj3_, obj4_, nil, nil, 'EPSG', 4326)
271
+ assert_equal('WGS 84', obj_.name)
272
+ assert_equal(2, obj_.dimension)
273
+ assert_equal('WGS_1984', obj_.horizontal_datum.name)
274
+ assert_equal('Greenwich', obj_.prime_meridian.name)
275
+ assert_equal('degree', obj_.angular_unit.name)
276
+ assert_nil(obj_.get_axis(0))
277
+ assert_nil(obj_.get_axis(1))
278
+ assert_equal('degree', obj_.get_units(0).name)
279
+ assert_equal('degree', obj_.get_units(1).name)
280
+ assert_equal('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137.0,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]', obj_.to_wkt)
281
+ end
282
+
283
+
284
+ def test_projected_coordinate_system
285
+ obj1_ = ::RGeo::CoordSys::CS::Ellipsoid.create_flattened_sphere('Airy 1830', 6377563.396, 299.3249646, nil, 'EPSG', '7001')
286
+ obj2_ = ::RGeo::CoordSys::CS::WGS84ConversionInfo.create(375, -111, 431, 0, 0, 0, 0)
287
+ obj3_ = ::RGeo::CoordSys::CS::AngularUnit.create('DMSH', 0.0174532925199433, 'EPSG', 9108)
288
+ obj4_ = ::RGeo::CoordSys::CS::HorizontalDatum.create('OSGB_1936', ::RGeo::CoordSys::CS::HD_CLASSIC, obj1_, obj2_, 'EPSG', '6277')
289
+ obj5_ = ::RGeo::CoordSys::CS::PrimeMeridian.create('Greenwich', nil, 0, 'EPSG', '8901')
290
+ obj6_ = ::RGeo::CoordSys::CS::AxisInfo.create('Lat', ::RGeo::CoordSys::CS::AO_NORTH)
291
+ obj7_ = ::RGeo::CoordSys::CS::AxisInfo.create('Long', ::RGeo::CoordSys::CS::AO_EAST)
292
+ obj8_ = ::RGeo::CoordSys::CS::GeographicCoordinateSystem.create('OSGB 1936', obj3_, obj4_, obj5_, obj6_, obj7_, 'EPSG', 4277)
293
+ obj9_ = ::RGeo::CoordSys::CS::ProjectionParameter.create('latitude_of_origin', 49)
294
+ obj10_ = ::RGeo::CoordSys::CS::ProjectionParameter.create('central_meridian', -2)
295
+ obj11_ = ::RGeo::CoordSys::CS::ProjectionParameter.create('scale_factor', 0.999601272)
296
+ obj12_ = ::RGeo::CoordSys::CS::ProjectionParameter.create('false_easting', 400000)
297
+ obj13_ = ::RGeo::CoordSys::CS::ProjectionParameter.create('false_northing', -100000)
298
+ obj14_ = ::RGeo::CoordSys::CS::Projection.create('Transverse_Mercator', 'Transverse_Mercator', [obj9_, obj10_, obj11_, obj12_, obj13_])
299
+ obj15_ = ::RGeo::CoordSys::CS::LinearUnit.create('metre', 1, 'EPSG', 9001)
300
+ obj16_ = ::RGeo::CoordSys::CS::AxisInfo.create('E', ::RGeo::CoordSys::CS::AO_EAST)
301
+ obj17_ = ::RGeo::CoordSys::CS::AxisInfo.create('N', ::RGeo::CoordSys::CS::AO_NORTH)
302
+ obj_ = ::RGeo::CoordSys::CS::ProjectedCoordinateSystem.create('OSGB 1936 / British National Grid', obj8_, obj14_, obj15_, obj16_, obj17_, 'EPSG', 27700)
303
+ assert_equal('OSGB 1936 / British National Grid', obj_.name)
304
+ assert_equal(2, obj_.dimension)
305
+ assert_equal('OSGB_1936', obj_.horizontal_datum.name)
306
+ assert_equal('OSGB 1936', obj_.geographic_coordinate_system.name)
307
+ assert_equal('Transverse_Mercator', obj_.projection.name)
308
+ assert_equal(5, obj_.projection.num_parameters)
309
+ assert_equal('latitude_of_origin', obj_.projection.get_parameter(0).name)
310
+ assert_equal(49, obj_.projection.get_parameter(0).value)
311
+ assert_equal('false_northing', obj_.projection.get_parameter(4).name)
312
+ assert_equal(-100000, obj_.projection.get_parameter(4).value)
313
+ assert_equal('metre', obj_.linear_unit.name)
314
+ assert_equal('E', obj_.get_axis(0).name)
315
+ assert_equal('N', obj_.get_axis(1).name)
316
+ assert_equal('metre', obj_.get_units(0).name)
317
+ assert_equal('metre', obj_.get_units(1).name)
318
+ assert_equal('PROJCS["OSGB 1936 / British National Grid",GEOGCS["OSGB 1936",DATUM["OSGB_1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],TOWGS84[375.0,-111.0,431.0,0.0,0.0,0.0,0.0],AUTHORITY["EPSG","6277"]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["DMSH",0.0174532925199433,AUTHORITY["EPSG","9108"]],AXIS["Lat",NORTH],AXIS["Long",EAST],AUTHORITY["EPSG","4277"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49.0],PARAMETER["central_meridian",-2.0],PARAMETER["scale_factor",0.999601272],PARAMETER["false_easting",400000.0],PARAMETER["false_northing",-100000.0],UNIT["metre",1.0,AUTHORITY["EPSG","9001"]],AXIS["E",EAST],AXIS["N",NORTH],AUTHORITY["EPSG","27700"]]', obj_.to_wkt)
319
+ end
320
+
321
+
322
+ def test_parse_epsg_6055
323
+ input_ = 'DATUM["Popular_Visualisation_Datum",SPHEROID["Popular Visualisation Sphere",6378137.0,0.0,AUTHORITY["EPSG","7059"]],TOWGS84[0.0,0.0,0.0,0.0,0.0,0.0,0.0],AUTHORITY["EPSG","6055"]]'
324
+ obj_ = ::RGeo::CoordSys::CS.create_from_wkt(input_)
325
+ assert_kind_of(::RGeo::CoordSys::CS::HorizontalDatum, obj_)
326
+ assert_equal('Popular_Visualisation_Datum', obj_.name)
327
+ assert_equal(::RGeo::CoordSys::CS::HD_GEOCENTRIC, obj_.datum_type)
328
+ assert_equal('EPSG', obj_.authority)
329
+ assert_equal('6055', obj_.authority_code)
330
+ assert_equal('Popular Visualisation Sphere', obj_.ellipsoid.name)
331
+ assert_equal(6378137, obj_.ellipsoid.semi_major_axis)
332
+ assert_equal(0, obj_.ellipsoid.inverse_flattening)
333
+ assert_equal(6378137, obj_.ellipsoid.semi_minor_axis)
334
+ assert_equal('EPSG', obj_.ellipsoid.authority)
335
+ assert_equal('7059', obj_.ellipsoid.authority_code)
336
+ assert_equal(0, obj_.wgs84_parameters.dx)
337
+ assert_equal(input_, obj_.to_wkt)
338
+ end
339
+
340
+
341
+ def test_parse_epsg_7405
342
+ input_ = 'COMPD_CS["OSGB36 / British National Grid + ODN",PROJCS["OSGB 1936 / British National Grid",GEOGCS["OSGB 1936",DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-4.2261596151967575],AUTHORITY["EPSG","6277"]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943295],AXIS["Geodetic latitude",NORTH],AXIS["Geodetic longitude",EAST],AUTHORITY["EPSG","4277"]],PROJECTION["Transverse Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["central_meridian",-2.0],PARAMETER["latitude_of_origin",49.0],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000.0],PARAMETER["false_northing",-100000.0],UNIT["m",1.0],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","27700"]],VERT_CS["Newlyn",VERT_DATUM["Ordnance Datum Newlyn",2005,AUTHORITY["EPSG","5101"]],UNIT["m",1.0],AXIS["Gravity-related height",UP],AUTHORITY["EPSG","5701"]],AUTHORITY["EPSG","7405"]]'
343
+ obj_ = ::RGeo::CoordSys::CS.create_from_wkt(input_)
344
+ assert_kind_of(::RGeo::CoordSys::CS::CompoundCoordinateSystem, obj_)
345
+ assert_kind_of(::RGeo::CoordSys::CS::ProjectedCoordinateSystem, obj_.head)
346
+ assert_kind_of(::RGeo::CoordSys::CS::VerticalCoordinateSystem, obj_.tail)
347
+ assert_equal(3, obj_.dimension)
348
+ assert_equal(input_, obj_.to_wkt)
349
+ end
350
+
351
+
352
+ end
353
+
354
+ end
355
+ end
356
+ end