Class: RGeo::Geographic::SimpleMercatorProjector
- Inherits:
-
Object
- Object
- RGeo::Geographic::SimpleMercatorProjector
- Defined in:
- lib/rgeo/geographic/simple_mercator_projector.rb
Overview
:nodoc:
Constant Summary collapse
- EQUATORIAL_RADIUS =
6378137.0
Class Method Summary collapse
-
._coordsys_3785 ⇒ Object
:nodoc:.
-
._proj4_3785 ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(geography_factory_, opts_ = {}) ⇒ SimpleMercatorProjector
constructor
A new instance of SimpleMercatorProjector.
- #limits_window ⇒ Object
- #project(geometry_) ⇒ Object
- #projection_factory ⇒ Object
- #unproject(geometry_) ⇒ Object
- #wraps? ⇒ Boolean
Constructor Details
#initialize(geography_factory_, opts_ = {}) ⇒ SimpleMercatorProjector
Returns a new instance of SimpleMercatorProjector.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 47 def initialize(geography_factory_, opts_={}) @geography_factory = geography_factory_ @projection_factory = Cartesian.preferred_factory(:srid => 3785, :proj4 => SimpleMercatorProjector._proj4_3785, :coord_sys => SimpleMercatorProjector._coordsys_3785, :buffer_resolution => opts_[:buffer_resolution], :lenient_multi_polygon_assertions => opts_[:lenient_multi_polygon_assertions], :has_z_coordinate => opts_[:has_z_coordinate], :has_m_coordinate => opts_[:has_m_coordinate]) end |
Class Method Details
._coordsys_3785 ⇒ Object
:nodoc:
144 145 146 147 148 149 |
# File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 144 def self._coordsys_3785 # :nodoc: unless defined?(@coordsys_3785) @coordsys_3785 = CoordSys::CS.create_from_wkt('PROJCS["Popular Visualisation CRS / Mercator",GEOGCS["Popular Visualisation CRS",DATUM["Popular_Visualisation_Datum",SPHEROID["Popular Visualisation Sphere",6378137,0,AUTHORITY["EPSG","7059"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6055"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4055"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],AUTHORITY["EPSG","3785"],AXIS["X",EAST],AXIS["Y",NORTH]]') end @coordsys_3785 end |
._proj4_3785 ⇒ Object
:nodoc:
136 137 138 139 140 141 |
# File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 136 def self._proj4_3785 # :nodoc: unless defined?(@proj4_3785) @proj4_3785 = CoordSys::Proj4.create('+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs') end @proj4_3785 end |
Instance Method Details
#limits_window ⇒ Object
129 130 131 132 133 |
# File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 129 def limits_window @limits_window ||= ProjectedWindow.new(@geography_factory, -20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789, :is_limits => true) end |
#project(geometry_) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 64 def project(geometry_) case geometry_ when Feature::Point rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE radius_ = EQUATORIAL_RADIUS @projection_factory.point(geometry_.x * rpd_ * radius_, ::Math.log(::Math.tan(::Math::PI / 4.0 + geometry_.y * rpd_ / 2.0)) * radius_) when Feature::Line @projection_factory.line(project(geometry_.start_point), project(geometry_.end_point)) when Feature::LinearRing @projection_factory.linear_ring(geometry_.points.map{ |p_| project(p_) }) when Feature::LineString @projection_factory.line_string(geometry_.points.map{ |p_| project(p_) }) when Feature::Polygon @projection_factory.polygon(project(geometry_.exterior_ring), geometry_.interior_rings.map{ |p_| project(p_) }) when Feature::MultiPoint @projection_factory.multi_point(geometry_.map{ |p_| project(p_) }) when Feature::MultiLineString @projection_factory.multi_line_string(geometry_.map{ |p_| project(p_) }) when Feature::MultiPolygon @projection_factory.multi_polygon(geometry_.map{ |p_| project(p_) }) when Feature::GeometryCollection @projection_factory.collection(geometry_.map{ |p_| project(p_) }) else nil end end |
#projection_factory ⇒ Object
59 60 61 |
# File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 59 def projection_factory @projection_factory end |
#unproject(geometry_) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 94 def unproject(geometry_) case geometry_ when Feature::Point dpr_ = ImplHelper::Math::DEGREES_PER_RADIAN radius_ = EQUATORIAL_RADIUS @geography_factory.point(geometry_.x / radius_ * dpr_, (2.0 * ::Math.atan(::Math.exp(geometry_.y / radius_)) - ::Math::PI / 2.0) * dpr_) when Feature::Line @geography_factory.line(unproject(geometry_.start_point), unproject(geometry_.end_point)) when Feature::LinearRing @geography_factory.linear_ring(geometry_.points.map{ |p_| unproject(p_) }) when Feature::LineString @geography_factory.line_string(geometry_.points.map{ |p_| unproject(p_) }) when Feature::Polygon @geography_factory.polygon(unproject(geometry_.exterior_ring), geometry_.interior_rings.map{ |p_| unproject(p_) }) when Feature::MultiPoint @geography_factory.multi_point(geometry_.map{ |p_| unproject(p_) }) when Feature::MultiLineString @geography_factory.multi_line_string(geometry_.map{ |p_| unproject(p_) }) when Feature::MultiPolygon @geography_factory.multi_polygon(geometry_.map{ |p_| unproject(p_) }) when Feature::GeometryCollection @geography_factory.collection(geometry_.map{ |p_| unproject(p_) }) else nil end end |
#wraps? ⇒ Boolean
124 125 126 |
# File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 124 def wraps? true end |