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 =
- 6_378_137.0
Instance Attribute Summary collapse
- 
  
    
      #projection_factory  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute projection_factory. 
Class Method Summary collapse
- 
  
    
      ._coordsys3857  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    :nodoc:. 
Instance Method Summary collapse
- 
  
    
      #initialize(geography_factory, opts = {})  ⇒ SimpleMercatorProjector 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of SimpleMercatorProjector. 
- #limits_window ⇒ Object
- #project(geometry) ⇒ Object
- #set_factories(geography_factory, projection_factory) ⇒ Object
- #unproject(geometry) ⇒ Object
- #wraps? ⇒ Boolean
Constructor Details
#initialize(geography_factory, opts = {}) ⇒ SimpleMercatorProjector
Returns a new instance of SimpleMercatorProjector.
| 14 15 16 17 18 19 20 21 | # File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 14 def initialize(geography_factory, opts = {}) @geography_factory = geography_factory @projection_factory = Cartesian.preferred_factory(srid: 3857, coord_sys: SimpleMercatorProjector._coordsys3857, buffer_resolution: opts[:buffer_resolution], has_z_coordinate: opts[:has_z_coordinate], has_m_coordinate: opts[:has_m_coordinate]) end | 
Instance Attribute Details
#projection_factory ⇒ Object (readonly)
Returns the value of attribute projection_factory.
| 28 29 30 | # File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 28 def projection_factory @projection_factory end | 
Class Method Details
Instance Method Details
#limits_window ⇒ Object
| 94 95 96 97 98 99 100 101 102 103 104 105 | # File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 94 def limits_window return @limits_window if defined?(@limits_window) @limits_window = ProjectedWindow.new( @geography_factory, -20_037_508.342789, -20_037_508.342789, 20_037_508.342789, 20_037_508.342789, is_limits: true ) end | 
#project(geometry) ⇒ Object
| 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | # File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 30 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) }) end end | 
#set_factories(geography_factory, projection_factory) ⇒ Object
| 23 24 25 26 | # File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 23 def set_factories(geography_factory, projection_factory) @geography_factory = geography_factory @projection_factory = projection_factory end | 
#unproject(geometry) ⇒ Object
| 59 60 61 62 63 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 | # File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 59 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) }) end end | 
#wraps? ⇒ Boolean
| 90 91 92 | # File 'lib/rgeo/geographic/simple_mercator_projector.rb', line 90 def wraps? true end |