rgeo-dschee 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +29 -0
- data/ext/geos_c_impl/coordinates.c +65 -0
- data/ext/geos_c_impl/coordinates.h +2 -0
- data/ext/geos_c_impl/extconf.rb +43 -0
- data/ext/geos_c_impl/factory.c +995 -0
- data/ext/geos_c_impl/factory.h +238 -0
- data/ext/geos_c_impl/geometry.c +1093 -0
- data/ext/geos_c_impl/geometry.h +23 -0
- data/ext/geos_c_impl/geometry_collection.c +757 -0
- data/ext/geos_c_impl/geometry_collection.h +46 -0
- data/ext/geos_c_impl/line_string.c +675 -0
- data/ext/geos_c_impl/line_string.h +32 -0
- data/ext/geos_c_impl/main.c +40 -0
- data/ext/geos_c_impl/point.c +236 -0
- data/ext/geos_c_impl/point.h +30 -0
- data/ext/geos_c_impl/polygon.c +359 -0
- data/ext/geos_c_impl/polygon.h +43 -0
- data/ext/geos_c_impl/preface.h +38 -0
- data/ext/proj4_c_impl/extconf.rb +62 -0
- data/ext/proj4_c_impl/main.c +315 -0
- data/lib/rgeo.rb +89 -0
- data/lib/rgeo/cartesian.rb +25 -0
- data/lib/rgeo/cartesian/analysis.rb +77 -0
- data/lib/rgeo/cartesian/bounding_box.rb +398 -0
- data/lib/rgeo/cartesian/calculations.rb +113 -0
- data/lib/rgeo/cartesian/factory.rb +347 -0
- data/lib/rgeo/cartesian/feature_classes.rb +100 -0
- data/lib/rgeo/cartesian/feature_methods.rb +88 -0
- data/lib/rgeo/cartesian/interface.rb +135 -0
- data/lib/rgeo/coord_sys.rb +43 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +1315 -0
- data/lib/rgeo/coord_sys/cs/factories.rb +148 -0
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +272 -0
- data/lib/rgeo/coord_sys/proj4.rb +293 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +115 -0
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +140 -0
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +62 -0
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +63 -0
- data/lib/rgeo/error.rb +27 -0
- data/lib/rgeo/feature.rb +54 -0
- data/lib/rgeo/feature/curve.rb +111 -0
- data/lib/rgeo/feature/factory.rb +278 -0
- data/lib/rgeo/feature/factory_generator.rb +96 -0
- data/lib/rgeo/feature/geometry.rb +624 -0
- data/lib/rgeo/feature/geometry_collection.rb +95 -0
- data/lib/rgeo/feature/line.rb +26 -0
- data/lib/rgeo/feature/line_string.rb +60 -0
- data/lib/rgeo/feature/linear_ring.rb +26 -0
- data/lib/rgeo/feature/mixins.rb +143 -0
- data/lib/rgeo/feature/multi_curve.rb +71 -0
- data/lib/rgeo/feature/multi_line_string.rb +26 -0
- data/lib/rgeo/feature/multi_point.rb +33 -0
- data/lib/rgeo/feature/multi_polygon.rb +57 -0
- data/lib/rgeo/feature/multi_surface.rb +73 -0
- data/lib/rgeo/feature/point.rb +84 -0
- data/lib/rgeo/feature/polygon.rb +97 -0
- data/lib/rgeo/feature/surface.rb +79 -0
- data/lib/rgeo/feature/types.rb +284 -0
- data/lib/rgeo/geographic.rb +40 -0
- data/lib/rgeo/geographic/factory.rb +450 -0
- data/lib/rgeo/geographic/interface.rb +489 -0
- data/lib/rgeo/geographic/proj4_projector.rb +58 -0
- data/lib/rgeo/geographic/projected_feature_classes.rb +107 -0
- data/lib/rgeo/geographic/projected_feature_methods.rb +212 -0
- data/lib/rgeo/geographic/projected_window.rb +383 -0
- data/lib/rgeo/geographic/simple_mercator_projector.rb +110 -0
- data/lib/rgeo/geographic/spherical_feature_classes.rb +100 -0
- data/lib/rgeo/geographic/spherical_feature_methods.rb +134 -0
- data/lib/rgeo/geographic/spherical_math.rb +188 -0
- data/lib/rgeo/geos.rb +89 -0
- data/lib/rgeo/geos/capi_factory.rb +470 -0
- data/lib/rgeo/geos/capi_feature_classes.rb +129 -0
- data/lib/rgeo/geos/ffi_factory.rb +592 -0
- data/lib/rgeo/geos/ffi_feature_classes.rb +83 -0
- data/lib/rgeo/geos/ffi_feature_methods.rb +574 -0
- data/lib/rgeo/geos/interface.rb +202 -0
- data/lib/rgeo/geos/utils.rb +74 -0
- data/lib/rgeo/geos/zm_factory.rb +405 -0
- data/lib/rgeo/geos/zm_feature_classes.rb +80 -0
- data/lib/rgeo/geos/zm_feature_methods.rb +344 -0
- data/lib/rgeo/impl_helper.rb +19 -0
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +185 -0
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +61 -0
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +146 -0
- data/lib/rgeo/impl_helper/basic_point_methods.rb +104 -0
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +87 -0
- data/lib/rgeo/impl_helper/math.rb +14 -0
- data/lib/rgeo/impl_helper/utils.rb +29 -0
- data/lib/rgeo/version.rb +3 -0
- data/lib/rgeo/wkrep.rb +37 -0
- data/lib/rgeo/wkrep/wkb_generator.rb +201 -0
- data/lib/rgeo/wkrep/wkb_parser.rb +251 -0
- data/lib/rgeo/wkrep/wkt_generator.rb +207 -0
- data/lib/rgeo/wkrep/wkt_parser.rb +415 -0
- data/lib/rgeo/yaml.rb +23 -0
- data/test/cartesian_analysis_test.rb +65 -0
- data/test/cartesian_bbox_test.rb +123 -0
- data/test/common/factory_tests.rb +78 -0
- data/test/common/geometry_collection_tests.rb +237 -0
- data/test/common/line_string_tests.rb +330 -0
- data/test/common/multi_line_string_tests.rb +182 -0
- data/test/common/multi_point_tests.rb +200 -0
- data/test/common/multi_polygon_tests.rb +191 -0
- data/test/common/point_tests.rb +370 -0
- data/test/common/polygon_tests.rb +261 -0
- data/test/coord_sys/ogc_cs_test.rb +342 -0
- data/test/coord_sys/proj4_srs_data_test.rb +41 -0
- data/test/coord_sys/proj4_test.rb +150 -0
- data/test/coord_sys/sr_org_test.rb +32 -0
- data/test/coord_sys/url_reader_test.rb +42 -0
- data/test/geos_capi/factory_test.rb +31 -0
- data/test/geos_capi/geometry_collection_test.rb +24 -0
- data/test/geos_capi/line_string_test.rb +24 -0
- data/test/geos_capi/misc_test.rb +116 -0
- data/test/geos_capi/multi_line_string_test.rb +24 -0
- data/test/geos_capi/multi_point_test.rb +24 -0
- data/test/geos_capi/multi_polygon_test.rb +39 -0
- data/test/geos_capi/parsing_unparsing_test.rb +40 -0
- data/test/geos_capi/point_test.rb +72 -0
- data/test/geos_capi/polygon_test.rb +154 -0
- data/test/geos_capi/zmfactory_test.rb +57 -0
- data/test/geos_ffi/factory_test.rb +31 -0
- data/test/geos_ffi/geometry_collection_test.rb +24 -0
- data/test/geos_ffi/line_string_test.rb +24 -0
- data/test/geos_ffi/misc_test.rb +63 -0
- data/test/geos_ffi/multi_line_string_test.rb +24 -0
- data/test/geos_ffi/multi_point_test.rb +24 -0
- data/test/geos_ffi/multi_polygon_test.rb +33 -0
- data/test/geos_ffi/parsing_unparsing_test.rb +41 -0
- data/test/geos_ffi/point_test.rb +77 -0
- data/test/geos_ffi/polygon_test.rb +46 -0
- data/test/geos_ffi/zmfactory_test.rb +58 -0
- data/test/mixins_test.rb +141 -0
- data/test/oneoff_test.rb +26 -0
- data/test/projected_geographic/factory_test.rb +25 -0
- data/test/projected_geographic/geometry_collection_test.rb +24 -0
- data/test/projected_geographic/line_string_test.rb +24 -0
- data/test/projected_geographic/multi_line_string_test.rb +26 -0
- data/test/projected_geographic/multi_point_test.rb +30 -0
- data/test/projected_geographic/multi_polygon_test.rb +25 -0
- data/test/projected_geographic/point_test.rb +51 -0
- data/test/projected_geographic/polygon_test.rb +24 -0
- data/test/simple_cartesian/calculations_test.rb +99 -0
- data/test/simple_cartesian/factory_test.rb +27 -0
- data/test/simple_cartesian/geometry_collection_test.rb +30 -0
- data/test/simple_cartesian/line_string_test.rb +31 -0
- data/test/simple_cartesian/multi_line_string_test.rb +28 -0
- data/test/simple_cartesian/multi_point_test.rb +31 -0
- data/test/simple_cartesian/multi_polygon_test.rb +31 -0
- data/test/simple_cartesian/point_test.rb +50 -0
- data/test/simple_cartesian/polygon_test.rb +28 -0
- data/test/simple_mercator/factory_test.rb +25 -0
- data/test/simple_mercator/geometry_collection_test.rb +24 -0
- data/test/simple_mercator/line_string_test.rb +24 -0
- data/test/simple_mercator/multi_line_string_test.rb +26 -0
- data/test/simple_mercator/multi_point_test.rb +29 -0
- data/test/simple_mercator/multi_polygon_test.rb +25 -0
- data/test/simple_mercator/point_test.rb +55 -0
- data/test/simple_mercator/polygon_test.rb +24 -0
- data/test/simple_mercator/window_test.rb +173 -0
- data/test/spherical_geographic/calculations_test.rb +167 -0
- data/test/spherical_geographic/factory_test.rb +27 -0
- data/test/spherical_geographic/geometry_collection_test.rb +31 -0
- data/test/spherical_geographic/line_string_test.rb +31 -0
- data/test/spherical_geographic/multi_line_string_test.rb +29 -0
- data/test/spherical_geographic/multi_point_test.rb +31 -0
- data/test/spherical_geographic/multi_polygon_test.rb +31 -0
- data/test/spherical_geographic/point_test.rb +78 -0
- data/test/spherical_geographic/polygon_test.rb +28 -0
- data/test/types_test.rb +42 -0
- data/test/wkrep/wkb_generator_test.rb +185 -0
- data/test/wkrep/wkb_parser_test.rb +293 -0
- data/test/wkrep/wkt_generator_test.rb +294 -0
- data/test/wkrep/wkt_parser_test.rb +412 -0
- metadata +386 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# SRS database interface
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module CoordSys
|
9
|
+
# This module contains tools for accessing spatial reference
|
10
|
+
# databases. These are databases (either local or remote) from which
|
11
|
+
# you can look up coordinate system specifications, typically in
|
12
|
+
# either OGC or Proj4 format. For example, you can access the
|
13
|
+
# <tt>spatial_ref_sys</tt> table provided with an OGC-compliant RDBMS
|
14
|
+
# such as PostGIS. You can also read the database files provided with
|
15
|
+
# the proj4 library, or access online databases such as the
|
16
|
+
# spatialreference.org site.
|
17
|
+
|
18
|
+
module SRSDatabase
|
19
|
+
# Interface specification for spatial reference system databases.
|
20
|
+
# This module exists primarily for the sake of documentation.
|
21
|
+
# Database implementations need not actually include this module,
|
22
|
+
# but at least need to duck-type its methods.
|
23
|
+
|
24
|
+
module Interface
|
25
|
+
# Retrieve an Entry given an identifier. The identifier is usually
|
26
|
+
# a numeric spatial reference ID (SRID), but could be a string
|
27
|
+
# value for certain database types.
|
28
|
+
|
29
|
+
def get(_ident_)
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# Clears any cache utilized by this database.
|
34
|
+
|
35
|
+
def clear_cache
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# An entry in a spatial reference system database.
|
41
|
+
# Every entry has an identifier, but all the other attributes are
|
42
|
+
# optional and may or may not be present depending on the database.
|
43
|
+
|
44
|
+
class Entry
|
45
|
+
# Create an entry.
|
46
|
+
# You must provide an identifier, which may be numeric or a
|
47
|
+
# string. The data hash should contain any other attributes,
|
48
|
+
# keyed by symbol.
|
49
|
+
#
|
50
|
+
# Some attribute inputs have special behaviors:
|
51
|
+
#
|
52
|
+
# [<tt>:coord_sys</tt>]
|
53
|
+
# You can pass a CS coordinate system object, or a string in
|
54
|
+
# WKT format.
|
55
|
+
# [<tt>:proj4</tt>]
|
56
|
+
# You can pass a Proj4 object, or a proj4-format string.
|
57
|
+
# [<tt>:name</tt>]
|
58
|
+
# If the name is not provided directly, it is taken from the
|
59
|
+
# coord_sys.
|
60
|
+
# [<tt>:authority</tt>]
|
61
|
+
# If the authority name is not provided directly, it is taken
|
62
|
+
# from the coord_sys.
|
63
|
+
# [<tt>:authority_code</tt>]
|
64
|
+
# If the authority code is not provided directly, it is taken
|
65
|
+
# from the coord_sys.
|
66
|
+
|
67
|
+
def initialize(ident_, data_ = {})
|
68
|
+
@identifier = ident_
|
69
|
+
@authority = data_[:authority]
|
70
|
+
@authority_code = data_[:authority_code]
|
71
|
+
@name = data_[:name]
|
72
|
+
@description = data_[:description]
|
73
|
+
@coord_sys = data_[:coord_sys]
|
74
|
+
if @coord_sys.is_a?(::String)
|
75
|
+
@coord_sys = CS.create_from_wkt(@coord_sys)
|
76
|
+
end
|
77
|
+
@proj4 = data_[:proj4]
|
78
|
+
if Proj4.supported?
|
79
|
+
if @proj4.is_a?(::String) || @proj4.is_a?(::Hash)
|
80
|
+
@proj4 = Proj4.create(@proj4)
|
81
|
+
end
|
82
|
+
else
|
83
|
+
@proj4 = nil
|
84
|
+
end
|
85
|
+
if @coord_sys
|
86
|
+
@name = @coord_sys.name unless @name
|
87
|
+
@authority = @coord_sys.authority unless @authority
|
88
|
+
@authority_code = @coord_sys.authority unless @authority_code
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# The database key or identifier.
|
93
|
+
attr_reader :identifier
|
94
|
+
|
95
|
+
# The authority name, if present. Example: "epsg".
|
96
|
+
attr_reader :authority
|
97
|
+
|
98
|
+
# The authority code, e.g. an EPSG code.
|
99
|
+
attr_reader :authority_code
|
100
|
+
|
101
|
+
# A human-readable name for this coordinate system.
|
102
|
+
attr_reader :name
|
103
|
+
|
104
|
+
# A human-readable description for this coordinate system.
|
105
|
+
attr_reader :description
|
106
|
+
|
107
|
+
# The CS::CoordinateSystem object.
|
108
|
+
attr_reader :coord_sys
|
109
|
+
|
110
|
+
# The Proj4 object.
|
111
|
+
attr_reader :proj4
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# SRS database interface
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
module CoordSys
|
9
|
+
module SRSDatabase
|
10
|
+
# A spatial reference database implementation backed by coordinate
|
11
|
+
# system files installed as part of the proj4 library. For a given
|
12
|
+
# Proj4Data object, you specify a single file (e.g. the epsg data
|
13
|
+
# file), and you can retrieve records by ID number.
|
14
|
+
|
15
|
+
class Proj4Data
|
16
|
+
# Connect to one of the proj4 data files. You should provide the
|
17
|
+
# file name, optionally the installation directory if it is not
|
18
|
+
# in a typical location, and several additional options.
|
19
|
+
#
|
20
|
+
# These options are recognized:
|
21
|
+
#
|
22
|
+
# [<tt>:dir</tt>]
|
23
|
+
# The path for the share/proj directory that contains the
|
24
|
+
# requested data file. By default, the Proj4Data class will
|
25
|
+
# try a number of directories for you, including
|
26
|
+
# /usr/local/share/proj, /opt/local/share/proj, /usr/share/proj,
|
27
|
+
# and a few other variants. However, if you have proj4 installed
|
28
|
+
# elsewhere, you can provide an explicit directory using this
|
29
|
+
# option. You may also pass nil as the value, in which case all
|
30
|
+
# the normal lookup paths will be disabled, and you will have to
|
31
|
+
# provide the full path as the file name.
|
32
|
+
# [<tt>:cache</tt>]
|
33
|
+
# If set to true, this class caches previously looked up entries
|
34
|
+
# so subsequent lookups do not have to reread the file. If set
|
35
|
+
# to <tt>:read_all</tt>, then ALL values in the file are read in
|
36
|
+
# and cached the first time a lookup is done. If set to
|
37
|
+
# <tt>:preload</tt>, then ALL values in the file are read in
|
38
|
+
# immediately when the database is created. Default is false,
|
39
|
+
# indicating that the file will be reread on every lookup.
|
40
|
+
# [<tt>:authority</tt>]
|
41
|
+
# If set, its value is taken as the authority name for all
|
42
|
+
# entries. The authority code will be set to the identifier. If
|
43
|
+
# not set, then the authority fields of entries will be blank.
|
44
|
+
|
45
|
+
def initialize(filename_, opts_ = {})
|
46
|
+
dir_ = nil
|
47
|
+
if opts_.include?(:dir)
|
48
|
+
dir_ = opts_[:dir]
|
49
|
+
else
|
50
|
+
["/usr/local/share/proj", "/usr/local/proj/share/proj", "/usr/local/proj4/share/proj", "/opt/local/share/proj", "/opt/proj/share/proj", "/opt/proj4/share/proj", "/opt/share/proj", "/usr/share/proj"].each do |d_|
|
51
|
+
if ::File.directory?(d_) && ::File.readable?(d_)
|
52
|
+
dir_ = d_
|
53
|
+
break
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@path = dir_ ? "#{dir_}/#{filename_}" : filename_
|
58
|
+
@authority = opts_[:authority]
|
59
|
+
if opts_[:cache]
|
60
|
+
@cache = {}
|
61
|
+
case opts_[:cache]
|
62
|
+
when :read_all
|
63
|
+
@populate_state = 1
|
64
|
+
when :preload
|
65
|
+
_search_file(nil)
|
66
|
+
@populate_state = 2
|
67
|
+
else
|
68
|
+
@populate_state = 0
|
69
|
+
end
|
70
|
+
else
|
71
|
+
@cache = nil
|
72
|
+
@populate_state = 0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Retrieve the Entry for the given ID number.
|
77
|
+
|
78
|
+
def get(ident_)
|
79
|
+
ident_ = ident_.to_s
|
80
|
+
return @cache[ident_] if @cache && @cache.include?(ident_)
|
81
|
+
result_ = nil
|
82
|
+
if @populate_state == 0
|
83
|
+
data_ = _search_file(ident_)
|
84
|
+
result_ = Entry.new(ident_, authority: @authority, authority_code: @authority ? ident_ : nil, name: data_[1], proj4: data_[2]) if data_
|
85
|
+
@cache[ident_] = result_ if @cache
|
86
|
+
elsif @populate_state == 1
|
87
|
+
_search_file(nil)
|
88
|
+
result_ = @cache[ident_]
|
89
|
+
@populate_state = 2
|
90
|
+
end
|
91
|
+
result_
|
92
|
+
end
|
93
|
+
|
94
|
+
# Clear the cache if one exists.
|
95
|
+
|
96
|
+
def clear_cache
|
97
|
+
@cache.clear if @cache
|
98
|
+
@populate_state = 1 if @populate_state == 2
|
99
|
+
end
|
100
|
+
|
101
|
+
def _search_file(ident_) # :nodoc:
|
102
|
+
::File.open(@path) do |file_|
|
103
|
+
cur_name_ = nil
|
104
|
+
cur_ident_ = nil
|
105
|
+
cur_text_ = nil
|
106
|
+
file_.each do |line_|
|
107
|
+
line_.strip!
|
108
|
+
if (comment_delim_ = line_.index('#'))
|
109
|
+
cur_name_ = line_[comment_delim_ + 1..-1].strip
|
110
|
+
line_ = line_[0..comment_delim_ - 1].strip
|
111
|
+
end
|
112
|
+
unless cur_ident_
|
113
|
+
if line_ =~ /^<(\w+)>(.*)/
|
114
|
+
cur_ident_ = Regexp.last_match(1)
|
115
|
+
cur_text_ = []
|
116
|
+
line_ = Regexp.last_match(2).strip
|
117
|
+
end
|
118
|
+
end
|
119
|
+
next unless cur_ident_
|
120
|
+
if line_[-2..-1] == "<>"
|
121
|
+
cur_text_ << line_[0..-3].strip
|
122
|
+
cur_text_ = cur_text_.join(" ")
|
123
|
+
if ident_.nil?
|
124
|
+
@cache[ident_] = Entry.new(ident_, authority: @authority, authority_code: @authority ? id_ : nil, name: cur_name_, proj4: cur_text_)
|
125
|
+
end
|
126
|
+
return [ident_, cur_name_, cur_text_] if cur_ident_ == ident_
|
127
|
+
cur_ident_ = nil
|
128
|
+
cur_name_ = nil
|
129
|
+
cur_text_ = nil
|
130
|
+
else
|
131
|
+
cur_text_ << line_
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# SRS database interface
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
require "net/http"
|
8
|
+
|
9
|
+
module RGeo
|
10
|
+
module CoordSys
|
11
|
+
module SRSDatabase
|
12
|
+
# A spatial reference database implementation that fetches data
|
13
|
+
# from the spatialreference.org website.
|
14
|
+
|
15
|
+
class SrOrg
|
16
|
+
# Create a database backed by the given catalog of the
|
17
|
+
# spatialreference.org website. Catalogs currently supported by
|
18
|
+
# spatialreference.org are "epsg", "esri", "iau2000" and "sr-org".
|
19
|
+
#
|
20
|
+
# Options:
|
21
|
+
#
|
22
|
+
# [<tt>:cache</tt>]
|
23
|
+
# If set to true, lookup results are cached so if the same URL
|
24
|
+
# is requested again, the result is served from cache rather
|
25
|
+
# than issuing another HTTP request. Default is false.
|
26
|
+
|
27
|
+
def initialize(catalog_, opts_ = {})
|
28
|
+
@catalog = catalog_.to_s.downcase
|
29
|
+
@cache = opts_[:cache] ? {} : nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# The spatialreference.org catalog used by this database.
|
33
|
+
attr_reader :catalog
|
34
|
+
|
35
|
+
# Retrieve the Entry from a spatialreference.org catalog given an
|
36
|
+
# integer ID.
|
37
|
+
|
38
|
+
def get(ident_)
|
39
|
+
ident_ = ident_.to_s
|
40
|
+
return @cache[ident_] if @cache && @cache.include?(ident_)
|
41
|
+
coord_sys_ = nil
|
42
|
+
proj4_ = nil
|
43
|
+
::Net::HTTP.start("spatialreference.org") do |http_|
|
44
|
+
response_ = http_.request_get("/ref/#{@catalog}/#{ident_}/ogcwkt/")
|
45
|
+
coord_sys_ = response_.body if response_.is_a?(::Net::HTTPSuccess)
|
46
|
+
response_ = http_.request_get("/ref/#{@catalog}/#{ident_}/proj4/")
|
47
|
+
proj4_ = response_.body if response_.is_a?(::Net::HTTPSuccess)
|
48
|
+
end
|
49
|
+
result_ = Entry.new(ident_, coord_sys: coord_sys_.strip, proj4: proj4_.strip)
|
50
|
+
@cache[ident_] = result_ if @cache
|
51
|
+
result_
|
52
|
+
end
|
53
|
+
|
54
|
+
# Clear the cache if one exists.
|
55
|
+
|
56
|
+
def clear_cache
|
57
|
+
@cache.clear if @cache
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# SRS database interface
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
require "net/http"
|
8
|
+
|
9
|
+
module RGeo
|
10
|
+
module CoordSys
|
11
|
+
module SRSDatabase
|
12
|
+
# A spatial reference database implementation that fetches data from
|
13
|
+
# internet URLs.
|
14
|
+
|
15
|
+
class UrlReader
|
16
|
+
# Create a URL-based spatial reference database.
|
17
|
+
#
|
18
|
+
# Options:
|
19
|
+
#
|
20
|
+
# [<tt>:cache</tt>]
|
21
|
+
# If set to true, lookup results are cached so if the same URL
|
22
|
+
# is requested again, the result is served from cache rather
|
23
|
+
# than issuing another HTTP request. Default is false.
|
24
|
+
|
25
|
+
def initialize(opts_ = {})
|
26
|
+
@cache = opts_[:cache] ? {} : nil
|
27
|
+
end
|
28
|
+
|
29
|
+
# Retrieve the given URL and return an Entry.
|
30
|
+
# Returns nil if the URL cannot be read as an OGC WKT or Proj4
|
31
|
+
# coordinate system
|
32
|
+
|
33
|
+
def get(ident_)
|
34
|
+
ident_ = ident_.to_s
|
35
|
+
return @cache[ident_] if @cache && @cache.include?(ident_)
|
36
|
+
uri_ = ::URI.parse(ident_)
|
37
|
+
result_ = nil
|
38
|
+
::Net::HTTP.start(uri_.host, uri_.port) do |http_|
|
39
|
+
request_ = uri_.path
|
40
|
+
request_ = "#{request_}?#{uri_.query}" if uri_.query
|
41
|
+
response_ = http_.request_get(request_)
|
42
|
+
if response_.is_a?(::Net::HTTPSuccess)
|
43
|
+
response_ = response_.body.strip
|
44
|
+
if response_[0, 1] == "+"
|
45
|
+
result_ = Entry.new(ident_, proj4: response_)
|
46
|
+
else
|
47
|
+
result_ = Entry.new(ident_, coord_sys: response_)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
@cache[ident_] = result_ if @cache
|
52
|
+
result_
|
53
|
+
end
|
54
|
+
|
55
|
+
# Clear the cache if one is present.
|
56
|
+
|
57
|
+
def clear_cache
|
58
|
+
@cache.clear if @cache
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/rgeo/error.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Error classes for RGeo
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
# All RGeo errors are members of this namespace.
|
9
|
+
|
10
|
+
module Error
|
11
|
+
# Base class for all RGeo-related exceptions
|
12
|
+
class RGeoError < ::RuntimeError
|
13
|
+
end
|
14
|
+
|
15
|
+
# The specified geometry is invalid
|
16
|
+
class InvalidGeometry < RGeoError
|
17
|
+
end
|
18
|
+
|
19
|
+
# The specified operation is not supported or not implemented
|
20
|
+
class UnsupportedOperation < RGeoError
|
21
|
+
end
|
22
|
+
|
23
|
+
# Parsing failed
|
24
|
+
class ParseError < RGeoError
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/rgeo/feature.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Features namespace for RGeo
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
module RGeo
|
8
|
+
# The Feature namespace contains interfaces and general tools for
|
9
|
+
# implementations of the Open Geospatial Consortium Simple Features
|
10
|
+
# Specification (SFS), version 1.1.0.
|
11
|
+
#
|
12
|
+
# Each interface is defined as a module, and is provided primarily for
|
13
|
+
# the sake of documentation. Implementations do not necessarily include
|
14
|
+
# the modules themselves. Therefore, you should not depend on the
|
15
|
+
# kind_of? method to check type. Instead, each interface module will
|
16
|
+
# provide a check_type class method (and a corresponding === operator
|
17
|
+
# to support case-when constructs).
|
18
|
+
#
|
19
|
+
# In addition, a Factory interface is defined here. A factory is an
|
20
|
+
# object that knows how to construct geometry instances for a given
|
21
|
+
# implementation. Each implementation's front-end consists of a way to
|
22
|
+
# create factories. Those factories, in turn, provide the api for
|
23
|
+
# building the features themselves. Note that, like the geometry
|
24
|
+
# modules, the Factory module itself may not actually be included in a
|
25
|
+
# factory implementation.
|
26
|
+
#
|
27
|
+
# Any particular implementation may extend these interfaces to provide
|
28
|
+
# implementation-specific features beyond what is stated in the SFS
|
29
|
+
# itself. The implementation should separately document any such
|
30
|
+
# extensions that it may provide.
|
31
|
+
|
32
|
+
module Feature
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Implementation files
|
37
|
+
require "rgeo/feature/factory"
|
38
|
+
require "rgeo/feature/mixins"
|
39
|
+
require "rgeo/feature/types"
|
40
|
+
require "rgeo/feature/geometry"
|
41
|
+
require "rgeo/feature/point"
|
42
|
+
require "rgeo/feature/curve"
|
43
|
+
require "rgeo/feature/line_string"
|
44
|
+
require "rgeo/feature/linear_ring"
|
45
|
+
require "rgeo/feature/line"
|
46
|
+
require "rgeo/feature/surface"
|
47
|
+
require "rgeo/feature/polygon"
|
48
|
+
require "rgeo/feature/geometry_collection"
|
49
|
+
require "rgeo/feature/multi_point"
|
50
|
+
require "rgeo/feature/multi_curve"
|
51
|
+
require "rgeo/feature/multi_line_string"
|
52
|
+
require "rgeo/feature/multi_surface"
|
53
|
+
require "rgeo/feature/multi_polygon"
|
54
|
+
require "rgeo/feature/factory_generator"
|