Class: GD::GIS::CRS::Normalizer
- Inherits:
-
Object
- Object
- GD::GIS::CRS::Normalizer
- Defined in:
- lib/gd/gis/crs_normalizer.rb
Overview
Normalizes coordinates from different CRS definitions into a consistent [longitude, latitude] order.
This class handles:
-
Axis order normalization (e.g. EPSG:4326)
-
Web Mercator (EPSG:3857) to WGS84 conversion
-
Flexible input formats
The output is always expressed as:
[longitude, latitude] in degrees
Instance Method Summary collapse
-
#initialize(crs) ⇒ Normalizer
constructor
Creates a new CRS normalizer.
-
#normalize(*args) ⇒ Array<Float>?
Normalizes coordinates into [longitude, latitude].
Constructor Details
#initialize(crs) ⇒ Normalizer
Creates a new CRS normalizer.
36 37 38 |
# File 'lib/gd/gis/crs_normalizer.rb', line 36 def initialize(crs) @crs = normalize_name(crs) end |
Instance Method Details
#normalize(*args) ⇒ Array<Float>?
Normalizes coordinates into [longitude, latitude].
Accepted input forms:
normalize(lon, lat)
normalize(lon, lat, z)
normalize([lon, lat])
normalize([lon, lat, z])
Extra dimensions (e.g. Z) are ignored.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gd/gis/crs_normalizer.rb', line 54 def normalize(*args) lon, lat = args.flatten return nil if lon.nil? || lat.nil? lon = lon.to_f lat = lat.to_f case @crs when CRS84, nil [lon, lat] when EPSG4326 # axis order lat,lon → lon,lat [lat, lon] when EPSG3857 mercator_to_wgs84(lon, lat) when "EPSG:22195" gk_to_wgs84(lon, lat) else raise ArgumentError, "Unsupported CRS: #{@crs}" end end |