{"id":15581006,"url":"https://github.com/nbulaj/spherical_mercator","last_synced_at":"2025-06-25T23:36:18.287Z","repository":{"id":26627086,"uuid":"109392463","full_name":"nbulaj/spherical_mercator","owner":"nbulaj","description":"🗺️ Spherical Mercator math in Ruby","archived":false,"fork":false,"pushed_at":"2022-02-14T06:29:03.000Z","size":25,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-24T02:49:02.073Z","etag":null,"topics":["mapbox","ruby","ruby-gem","spherical","spherical-geometry"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nbulaj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-03T12:22:39.000Z","updated_at":"2022-02-14T07:00:18.000Z","dependencies_parsed_at":"2022-07-27T08:32:29.679Z","dependency_job_id":null,"html_url":"https://github.com/nbulaj/spherical_mercator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbulaj%2Fspherical_mercator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbulaj%2Fspherical_mercator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbulaj%2Fspherical_mercator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbulaj%2Fspherical_mercator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nbulaj","download_url":"https://codeload.github.com/nbulaj/spherical_mercator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250552035,"owners_count":21449161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mapbox","ruby","ruby-gem","spherical","spherical-geometry"],"created_at":"2024-10-02T19:41:00.804Z","updated_at":"2025-04-24T02:49:07.785Z","avatar_url":"https://github.com/nbulaj.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ruby port of Mapbox Spherical Mercator\n[![Gem Version](https://badge.fury.io/rb/spherical_mercator.svg)](http://badge.fury.io/rb/spherical_mercator)\n[![CI](https://github.com/nbulaj/spherical_mercator/actions/workflows/ci.yml/badge.svg)](https://github.com/nbulaj/spherical_mercator/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/nbulaj/spherical_mercator/badge.svg)](https://coveralls.io/github/nbulaj/spherical_mercator)\n[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg)](#license)\n\nSpherical Mercator gem is a port of [Mapbox sphericalmercator JS lib](https://github.com/mapbox/sphericalmercator) that provides projection math\nfor converting between mercator meters, screen pixels (of 256x256 or configurable-size tiles), and latitude/longitude.\n\n## Requirements\n\n* Ruby \u003e= 2.0\n\n## Installation\n\nSimple:\n\n`gem install spherical_mercator`\n\nFor Gemfile:\n\n`gem 'spherical_mercator'`\n\n## API\n\n_NOTE_: API description copied from the original repo.\n\nSome datatypes are assumed to be arrays: `ll` is `[lon, lat]`, `xy` and `px` are\n`[x, y]`.\n\n```ruby\n# By default, precomputes up to z30\nmercator = SphericalMercator.new(size: 256)\n# Whether to round pixel values at integer zoom levels. Defaults to true.\nmercator = SphericalMercator.new(round: false)\n```\n\n### `px(lon_lat, zoom)`\n\nConvert lon, lat to screen pixel x, y from 0, 0 origin, at a certain zoom level.\nThe inverse of `ll`\n\nScreen pixel values are rounded, unless the zoom level is a floating point value. To disable rounding on integer zoom levels, specify `round: false` when creating the SphericalMercator.\n\n### `ll(px, zoom)`\n\nConvert screen pixel value to lon, lat, at a certain zoom level. The inverse\nof `px`\n\n### `bbox(x, y, zoom, tms_style, srs)`\n\nConvert tile xyz value to bbox of the form `[west, south, east, north]`\n\n* `x` {Number} x (longitude) number.\n* `y` {Number} y (latitude) number.\n* `zoom` {Number} zoom.\n* `tms_style` {Boolean} whether to compute using tms-style. (optional, default `false`)\n* `srs` {String} projection for resulting bbox ('WGS84'|'900913'). (optional, default 'WGS84')\n\nReturns bbox array of values in form `[west, south, east, north]`.\n\n### `xyz(bbox, zoom, tms_style, srs)`\n\nConvert bbox to xyz bounds\n\n* `bbox` {Number} bbox in the form `[west, south, east, north]`.\n* `zoom` {Number} zoom.\n* `tms_style` {Boolean} whether to compute using tms-style. (optional, default `false`)\n* `srs` {String} projection of input bbox ('WGS84'|'900913'). (optional, default 'WGS84')\n\nReturns `Hash` object (`{...}`) for XYZ bounds containing `:minX`, `:maxX`, `:minY`, `:maxY` properties.\n\n### `convert(bbox, to)`\n\nConvert bbox from 900913 to WGS84 or vice versa\n\n* `bbox` {Number} bbox in the form `[west, south, east, north]`.\n* `to` {String} projection of resulting bbox ('WGS84'|'900913'). (optional, default 'WGS84')\n\nReturns bbox array of values in form `[west, south, east, north]`.\n\n### `forward(lon_lat)`\n\nConvert lon, lat values (must be an array like `[lon, lat]`) to mercator x, y\n\n### `inverse(xy)`\n\nConvert mercator x, y values (`xy` must be an array like `[x, y]`) to lon, lat\n\n## Contributing\n\nYou are very welcome to help improve spherical_mercator if you have suggestions for features that other people can use.\n\nTo contribute:\n\n1. Fork the project.\n2. Create your feature branch (`git checkout -b my-new-feature`).\n3. Implement your feature or bug fix.\n4. Add documentation for your feature or bug fix.\n5. Run \u003ctt\u003erake doc:yard\u003c/tt\u003e. If your changes are not 100% documented, go back to step 4.\n6. Add tests for your feature or bug fix.\n7. Run `rake` to make sure all tests pass.\n8. Commit your changes (`git commit -am 'Add new feature'`).\n9. Push to the branch (`git push origin my-new-feature`).\n10. Create new pull request.\n\nThanks.\n\n## License\n\nSpherical Mercator gem is released under the [MIT License](http://www.opensource.org/licenses/MIT).\n\nCopyright (c) 2017 Nikita Bulai (bulajnikita@gmail.com) and [original lib authors](https://github.com/mapbox/sphericalmercator/graphs/contributors).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnbulaj%2Fspherical_mercator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnbulaj%2Fspherical_mercator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnbulaj%2Fspherical_mercator/lists"}