coordconver 0.1.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ba40d344954b440a5ec94a15ba90152193b2daa
4
- data.tar.gz: 126d11aa9acc71ba85e21e7ae598c449be8eab8e
3
+ metadata.gz: eedc1dc70bebdf731febe21f54e049d299dc19ab
4
+ data.tar.gz: 1804291196c930ed0c54e9fa85ce94e2c48d79a8
5
5
  SHA512:
6
- metadata.gz: 0e3aac5ab08cef9809cdd0e5175ff307e9e3b1839dbe0ef17235ae0eafe49c8b3effc70593d5b45594b430bcb27b1a00d76d845c3900a4b554bcb8afc2cb2625
7
- data.tar.gz: cdfbc0355a34858fa1e8940d4982be65cf7b417e6be952a023508582311d31a1c6ad2853d38017d468c04c5ff866005791e1f1e0a8e8dc38ea67abdcacf20f0e
6
+ metadata.gz: 274975cb6cf07e57c7f47f8d9a4624d31b269ef009dc56bfb2c3e6e4b1964d94588702c89f18bafc16c896feb7dd493dd631d3021c94caa126dc18ce8c0fa92e
7
+ data.tar.gz: 66e4dc511f22463bf909f399faacb9a2e7d5b3d1b6e0fea0bce3d8be56b18c72aa1a2ea99b376652114b52793e5d030d4c0f0df2ea4b0217a96660ed7b79a569
data/.gitignore CHANGED
@@ -1,9 +1,10 @@
1
- .bundle/
1
+ /.bundle/
2
2
  /.yardoc
3
3
  Gemfile.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
- doc/
6
+ /doc/
7
7
  pkg/
8
8
  /spec/reports/
9
- tmp/
9
+ /tmp/
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
6
+
7
+ script:
8
+ - bundle exec rake test
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at cheenwe@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/README.md CHANGED
@@ -1,59 +1,115 @@
1
1
  # 坐标转换/Coordconver
2
- 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换。
2
+ [![Build Status](https://travis-ci.org/cheenwe/coordconver.svg?branch=master)](https://travis-ci.org/cheenwe/coordconver)
3
3
 
4
+ - 1.提供了百度坐标(BD-09)、国测局坐标(火星坐标,GCJ-02)、和 地球坐标( WGS-84) 坐标系之间的转换。
4
5
 
5
- ## 坐标系说明
6
- ### 地球坐标 (WGS84)
6
+ - 2.坐标点到经纬度的相互转换
7
7
 
8
- - 国际标准,从 GPS 设备中取出的数据的坐标系
8
+ - 3.坐标点到地理位置的转换(TODO)
9
9
 
10
- - 国际地图提供商使用的坐标系
10
+ ## 安装
11
11
 
12
- ### 火星坐标 (GCJ-02)也叫国测局坐标系
13
- - 中国标准,从国行移动设备中定位获取的坐标数据使用这个坐标系
12
+ 添加到Gemfile:
14
13
 
15
- - 国家规定: 国内出版的各种地图系统(包括电子形式),必须至少采用GCJ-02对地理位置进行首次加密。
14
+ ```ruby
15
+ gem 'coordconver'
16
+ ```
17
+
18
+ 执行:
19
+
20
+ $ bundle
21
+
22
+ 或者只安装该GEM:
23
+
24
+ $ gem install coordconver
16
25
 
17
- ###百度坐标 (BD-09)
26
+
27
+ ## 坐标系转换
28
+
29
+ ### 用法
30
+
31
+ 提供6转换方式,传入参数需为**float**类型,如:
32
+ >Coordconver.bd_gcj(lng.to_f, lat.to_f)
33
+
34
+ | 坐标系 | 转换名称 | 方法|
35
+ | ----------- | ------- | ----- | --------- |
36
+ | BD-09 -> GCJ-02 | 百度 -> 谷歌、高德 | Coordconver.bd_gcj(lng, lat) |
37
+ | BD-09 -> WGS-84 | 百度 -> 地球坐标 | Coordconver.bd_wgs(lng, lat) |
38
+ | GCJ-02 -> WGS-84 | 谷歌、高德 -> 地球坐标 | Coordconver.gcj_wgs(lng, lat) |
39
+ | GCJ-02 -> BD-09 | 谷歌、高德 -> 百度 | Coordconver.gcj_bd(lng, lat) |
40
+ | WGS-84 -> BD-09 | 地球坐标 -> 百度 | Coordconver.wgs_bd(lng, lat) |
41
+ | WGS-84 -> GCJ-02 | 地球坐标 -> 谷歌、高德 | Coordconver.wgs_gcj(lng, lat) |
42
+
43
+ 示例:
44
+ >Coordconver.wgs_bd(121.46873833333332, 31.247138333333336) # => [121.479808223763, 31.25115814844421]
45
+
46
+ ### 坐标系说明
47
+
48
+ #### 百度坐标系 (BD-09)
18
49
  - 百度标准,百度 SDK,百度地图,Geocoding 使用
19
50
 
20
- ## 开发过程需要注意的事
21
- - 从设备获取经纬度(GPS)坐标
51
+ #### 火星坐标系 (GCJ-02)
52
+ - 中国标准(国测局坐标系),从国行移动设备中定位获取的坐标数据使用这个坐标系, 由中国国家测绘局制订的地理信息系统的坐标系统
22
53
 
23
- 如果使用的是百度sdk那么可以获得百度坐标(bd09)或者火星坐标(GCJ02),默认是bd09
24
- 如果使用的是ios的原生定位库,那么获得的坐标是WGS84
25
- 如果使用的是高德sdk,那么获取的坐标是GCJ02
54
+ - 由WGS84坐标系经加密后的坐标系
26
55
 
27
- - 互联网在线地图使用的坐标系
56
+ - 谷歌中国地图, 搜搜中国地图, iOS地图(高德), 搜搜, 阿里云, 高德地图, 腾讯
28
57
 
29
- 火星坐标系:
30
- iOS 地图(其实是高德)
31
- Google国内地图(.cn域名下)
32
- 搜搜、阿里云、高德地图、腾讯
33
- 百度坐标系:
34
- 当然只有百度地图
35
- WGS84坐标系:
36
- 国际标准,谷歌国外地图、osm地图等国外的地图一般都是这个
58
+ #### 地球坐标系 (WGS-84)
59
+ - 国际标准, 设备一般包含GPS芯片或者北斗芯片获取的经纬度为WGS84地理坐标系
37
60
 
38
- ## Installation
61
+ - 谷歌地图采用的是WGS84地理坐标系(中国范围除外)
39
62
 
40
- Add this line to your application's Gemfile:
63
+ - ios的原生定位库, osm
41
64
 
42
- ```ruby
43
- gem 'coordconver'
44
- ```
45
65
 
46
- And then execute:
66
+ ### 相关资料
47
67
 
48
- $ bundle
68
+ - [各坐标系位置在线查看](http://www.gpsspg.com/maps.htm)
49
69
 
50
- Or install it yourself as:
70
+ - [百度地图转换API](http://lbsyun.baidu.com/jsdemo.htm#a5_2)
51
71
 
52
- $ gem install coordconver
72
+ - [高德地图转换API](http://lbs.amap.com/api/webservice/guide/api/convert/#convert)
73
+
74
+
75
+ ## 坐标点与经纬度转换
76
+
77
+ ### 用法
78
+
79
+ 提供4种转换方式,传入坐标点需为**float**类型,传入经纬度需为**string**类型。
80
+
81
+ | 转换名称 | 方法|
82
+ | ----- | --------- |
83
+ | 坐标点转度数 | Coordconver.degree(lng, lat) |
84
+ | 单个坐标点转度数 | Coordconver.cal_degree(n) |
85
+ | 度数点转坐标点 | Coordconver.undegree(lng_degree, lat_degree) |
86
+ | 单个度数转坐标点 | Coordconver.cal_degree(n) |
87
+
88
+
89
+ 示例:
90
+
91
+ >Coordconver.degree(38.65777, 104.08296) # => ["38°39′27″","104°4′58″"]
92
+
93
+ >Coordconver.undegree("38°39′27.97″","104°4′58.66″") # => [38.65777,104.08296]
94
+
95
+ ### 相关资料
96
+ 地形图坐标系:我国的地形图采用高斯-克吕格平面直角坐标系。在该坐标系中,横轴:赤道,用Y表示;纵轴:中央经线,用X表示;坐标原点:中央经线与赤道的交点,用0表示。赤道以南为负,以北为正;中央经线以东为正,以西为负。我国位于北半球,故纵坐标均为正值,但为避免中央经度线以西为负值的情况,将坐标纵轴西移500公里。
97
+
98
+ 北京54坐标系:1954年我国在北京设立了大地坐标原点,采用克拉索夫斯基椭球体,依此计算出来的各大地控制点的坐标,称为北京54坐标系。
99
+ GS84坐标系:即世界通用的经纬度坐标系。
100
+
101
+ 经纬度表示:1884年国际经度会议规定,以通过英国伦敦格林威治天文台子午仪中心的经线为0°经线。从0°经线往东叫东经,往西叫西经,东、西各分180°。习惯上以西经20°和东经160°为分界把地球分为东西两个半球。假如从地轴的正中间将地球切成南北两半,上边的一半叫北半球,下边的一半叫南半球。被切的这个平面,叫赤道面。赤道面与地球表面相交的线叫赤道。纬线从赤道往两极越来越短,到了两极就缩小成一个点了。科学家们把赤道定为0°纬线,从赤道向两极各分为90°,赤道以南叫南纬,赤道以北叫北纬。在计算机或GPS上经纬度经常用度、分、秒和度.度、分.分、秒.秒的混合方式进行表示,度、分、秒间的进制是60进制,度.度、分.分、秒.秒的进制是100进制,换算时一定要注意。可以近似地认为每个纬度之间的距离是不变的111KM,每分间 1.85KM,每秒间31.8M。经度间的距离随纬度增高逐渐减小,可按以下公式计算:
102
+ Decimal Degrees = Degrees + minutes/60 + seconds/3600
103
+ 例:57°55’56.6″ =57+55/60+56.6/3600=57.9323888888888
104
+ 114°65’24.6″=114+65/60+24.6/3600=115.00683333333333
105
+
106
+
107
+ ## 坐标点与地址转换(TODO)
108
+ 1.百度地图转换
109
+
110
+ 2.高德地图转换
53
111
 
54
- ## Usage
55
112
 
56
- TODO: Write usage instructions here
57
113
 
58
114
  ## Development
59
115
 
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/coordconver ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "coordconver"
3
+
4
+ puts Coordconver.wgs84_bd09(ARGV[0],ARGV[1] )
data/coordconver.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'coordconver'
4
+ require 'coordconver/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "coordconver"
@@ -10,10 +10,9 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["cheenwe@gmail.com"]
11
11
 
12
12
  spec.summary = %q{坐标转换/Coordconver}
13
- spec.description = %q{提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换.}
13
+ spec.description = %q{1.提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换. 2.坐标点到经纬度的相互转换.}
14
14
  spec.homepage = "https://github.com/cheenwe/coordconver"
15
15
  spec.license = "MIT"
16
-
17
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
17
  spec.bindir = "exe"
19
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -21,4 +20,5 @@ Gem::Specification.new do |spec|
21
20
 
22
21
  spec.add_development_dependency "bundler", "~> 1.12"
23
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
24
  end
@@ -0,0 +1,106 @@
1
+ module Coordconver
2
+ module Coordconver
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ # 定义一些常量
9
+ X_PI = 3.14159265358979324 * 3000.0 / 180.0
10
+ PI = 3.1415926535897932384626
11
+ AA = 6378245.0 #a
12
+ EE = 0.00669342162296594323 #e
13
+
14
+ module ClassMethods
15
+
16
+ def transformlat(lng, lat)
17
+ ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt((lng).abs);
18
+ ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
19
+ ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
20
+ ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
21
+ return ret
22
+ end
23
+
24
+ def transformlng(lng, lat)
25
+ ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt((lng).abs);
26
+ ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
27
+ ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
28
+ ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
29
+ end
30
+
31
+ # 百度坐标系 (BD-09) -> 火星坐标系 (GCJ-02)
32
+ # 即 百度 -> 谷歌、高德
33
+ # Coordconver.bd_gcj(lng, lat)
34
+ def bd_gcj(lng, lat)
35
+ x = lng - 0.0065;
36
+ y = lat - 0.006;
37
+ z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
38
+ theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
39
+ gg_lng = z * Math.cos(theta);
40
+ gg_lat = z * Math.sin(theta);
41
+ return [gg_lng, gg_lat]
42
+ end
43
+
44
+ # 百度坐标系 (BD-09) -> 地球坐标 (WGS-84)
45
+ # 即 百度 -> 地球坐标
46
+ # Coordconver.bd_wgs(lng, lat)
47
+ def bd_wgs(lng, lat)
48
+ loca = wgs_gcj(lng, lat)
49
+ gcj_bd(loca[0], loca[1])
50
+ end
51
+
52
+ # 火星坐标系 (GCJ02) -> 地球坐标 (WGS-84)
53
+ # 即 谷歌、高德 -> 地球坐标
54
+ # Coordconver.gcj_wgs(lng, lat)
55
+ def gcj_wgs(lng, lat)
56
+ dlat = transformlat(lng - 105.0, lat - 35.0);
57
+ dlng = transformlng(lng - 105.0, lat - 35.0);
58
+ radlat = lat / 180.0 * PI;
59
+ magic = Math.sin(radlat);
60
+ magic = 1 - EE * magic * magic;
61
+ sqrtmagic = Math.sqrt(magic);
62
+ dlat = (dlat * 180.0) / ((AA * (1 - EE)) / (magic * sqrtmagic) * PI);
63
+ dlng = (dlng * 180.0) / (AA / sqrtmagic * Math.cos(radlat) * PI);
64
+ mglat = lat + dlat;
65
+ mglng = lng + dlng;
66
+ return [lng * 2 - mglng, lat * 2 - mglat]
67
+ end
68
+
69
+ # 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09)
70
+ # 即 谷歌、高德 -> 百度
71
+ # Coordconver.gcj_bd(lng, lat)
72
+ def gcj_bd(lng, lat)
73
+ z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * X_PI);
74
+ theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * X_PI);
75
+ bd_lng = z * Math.cos(theta) + 0.0065;
76
+ bd_lat = z * Math.sin(theta) + 0.006;
77
+ return [bd_lng, bd_lat]
78
+ end
79
+
80
+ # 地球坐标 ( WGS-84) 与百度坐标系 (BD-09)
81
+ # 即 地球坐标 -> 百度
82
+ # Coordconver.wgs_bd(lng, lat)
83
+ def wgs_bd(lng, lat)
84
+ loca = wgs_gcj(lng, lat)
85
+ gcj_bd(loca[0], loca[1])
86
+ end
87
+
88
+ # 地球坐标 ( WGS-84) 与火星坐标系 (GCJ-02)
89
+ # 即 地球坐标 -> 谷歌、高德
90
+ # Coordconver.wgs_gcj(lng, lat)
91
+ def wgs_gcj(lng, lat)
92
+ dlat = transformlat(lng - 105.0, lat - 35.0);
93
+ dlng = transformlng(lng - 105.0, lat - 35.0);
94
+ radlat = lat / 180.0 * PI;
95
+ magic = Math.sin(radlat);
96
+ magic = 1 - EE * magic * magic;
97
+ sqrtmagic = Math.sqrt(magic);
98
+ dlat = (dlat * 180.0) / ((AA * (1 - EE)) / (magic * sqrtmagic) * PI);
99
+ dlng = (dlng * 180.0) / (AA / sqrtmagic * Math.cos(radlat) * PI);
100
+ mglat = lat + dlat;
101
+ mglng = lng + dlng;
102
+ return [mglng, mglat]
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,60 @@
1
+ module Coordconver
2
+ module Degree
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+
9
+ # 取整数位
10
+ def num(n)
11
+ n.to_i
12
+ end
13
+
14
+ # 取小数数位 Decimal digit
15
+ def dig(n)
16
+ n.to_f-num(n)
17
+ end
18
+
19
+ # 计算分
20
+ def min(n)
21
+ dig(n)*60
22
+ end
23
+
24
+ # 计算秒
25
+ def sec(n)
26
+ (min(n)-num(min(n)))*60
27
+ end
28
+
29
+ # 坐标转度数
30
+ def degree(lng, lat)
31
+ [cal_degree(lng),cal_degree(lat)]
32
+ end
33
+
34
+ def cal_degree(n)
35
+ "#{num(n)}°#{num(min(n))}′#{num(sec(n))}″"
36
+ end
37
+
38
+
39
+ # 获取分
40
+ def get_min(n)
41
+ n.split('°').last.to_f
42
+ end
43
+
44
+ # 获取秒
45
+ def get_sec(n)
46
+ n.split('′').last.to_f
47
+ end
48
+
49
+ # 度数转坐标
50
+ def cal_undegree(n)
51
+ (num(n) + get_min(n)/60 + get_sec(n)/3600).round(5)
52
+ end
53
+
54
+ def undegree(lng, lat)
55
+ [cal_undegree(lng),cal_undegree(lat)]
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Coordconver
2
+ VERSION = "0.1.3"
3
+ end
data/lib/coordconver.rb CHANGED
@@ -1,88 +1,8 @@
1
- class Coordconver
2
- VERSION = "0.1.0"
1
+ require "coordconver/version"
2
+ require "coordconver/coordconver"
3
+ require "coordconver/degree"
3
4
 
4
- # 定义一些常量
5
- X_PI = 3.14159265358979324 * 3000.0 / 180.0
6
- PI = 3.1415926535897932384626
7
- AA = 6378245.0 #a
8
- EE = 0.00669342162296594323 #e
9
-
10
- class << self
11
-
12
- def transformlat(lng, lat)
13
-
14
- ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt((lng).abs);
15
- ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
16
- ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
17
- ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
18
- return ret
19
- end
20
-
21
- def transformlng(lng, lat)
22
- ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt((lng).abs);
23
- ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
24
- ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
25
- ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
26
- end
27
-
28
-
29
- # 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
30
- # 即 百度 转 谷歌、高德
31
- def bd09_gcj02(bd_lon, bd_lat)
32
- x = bd_lon - 0.0065;
33
- y = bd_lat - 0.006;
34
- z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
35
- theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
36
- gg_lng = z * Math.cos(theta);
37
- gg_lat = z * Math.sin(theta);
38
- return [gg_lng, gg_lat]
39
- end
40
-
41
- # 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
42
- # 即谷歌、高德 转 百度
43
- def gcj02_bd09(lng, lat)
44
- z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * X_PI);
45
- theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * X_PI);
46
- bd_lng = z * Math.cos(theta) + 0.0065;
47
- bd_lat = z * Math.sin(theta) + 0.006;
48
- return [bd_lng, bd_lat]
49
- end
50
-
51
-
52
- # WGS84转GCj02
53
- def wgs84_gcj02(lng, lat)
54
- dlat = transformlat(lng - 105.0, lat - 35.0);
55
- dlng = transformlng(lng - 105.0, lat - 35.0);
56
- radlat = lat / 180.0 * PI;
57
- magic = Math.sin(radlat);
58
- magic = 1 - EE * magic * magic;
59
- sqrtmagic = Math.sqrt(magic);
60
- dlat = (dlat * 180.0) / ((AA * (1 - EE)) / (magic * sqrtmagic) * PI);
61
- dlng = (dlng * 180.0) / (AA / sqrtmagic * Math.cos(radlat) * PI);
62
- mglat = lat + dlat;
63
- mglng = lng + dlng;
64
- return [mglng, mglat]
65
- end
66
-
67
- # GCJ02 转换为 WGS84
68
- def gcj02_wgs84(lng, lat)
69
- dlat = transformlat(lng - 105.0, lat - 35.0);
70
- dlng = transformlng(lng - 105.0, lat - 35.0);
71
- radlat = lat / 180.0 * PI;
72
- magic = Math.sin(radlat);
73
- magic = 1 - EE * magic * magic;
74
- sqrtmagic = Math.sqrt(magic);
75
- dlat = (dlat * 180.0) / ((AA * (1 - EE)) / (magic * sqrtmagic) * PI);
76
- dlng = (dlng * 180.0) / (AA / sqrtmagic * Math.cos(radlat) * PI);
77
- mglat = lat + dlat;
78
- mglng = lng + dlng;
79
- return [lng * 2 - mglng, lat * 2 - mglat]
80
- end
81
-
82
- # WGS84 转换 BD08
83
- def wgs84_bd09(lng, lat)
84
- loca = wgs84_gcj02(lng, lat)
85
- gcj02_bd09(loca[0], loca[1])
86
- end
87
- end
5
+ module Coordconver
6
+ include Coordconver
7
+ include Degree
88
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coordconver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - chenwei
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,21 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换.
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: 1.提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换. 2.坐标点到经纬度的相互转换.
42
56
  email:
43
57
  - cheenwe@gmail.com
44
58
  executables: []
@@ -46,14 +60,20 @@ extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
62
  - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
49
65
  - Gemfile
50
66
  - LICENSE.txt
51
67
  - README.md
52
68
  - Rakefile
53
69
  - bin/console
70
+ - bin/coordconver
54
71
  - bin/setup
55
72
  - coordconver.gemspec
56
73
  - lib/coordconver.rb
74
+ - lib/coordconver/coordconver.rb
75
+ - lib/coordconver/degree.rb
76
+ - lib/coordconver/version.rb
57
77
  homepage: https://github.com/cheenwe/coordconver
58
78
  licenses:
59
79
  - MIT
@@ -74,9 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
94
  version: '0'
75
95
  requirements: []
76
96
  rubyforge_project:
77
- rubygems_version: 2.6.1
97
+ rubygems_version: 2.5.1
78
98
  signing_key:
79
99
  specification_version: 4
80
100
  summary: 坐标转换/Coordconver
81
101
  test_files: []
82
- has_rdoc: