GISHelper.java
4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
58
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
89
90
91
92
93
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.pashanhoo.landsurvey.utils;
/**
* Created by jiangbotao on 2018/3/28.
*/
import java.text.DecimalFormat;
import android.util.Log;
import com.esri.android.map.MapView;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.SpatialReference;
/**
* GIS相关持有工具类
*
* @author JiangXusheng
* @date 2013-7-6 下午1:16:07
*/
public class GISHelper {
public static final int VALIDATE_X_Y = 999;
public static final double AX = 0.83;
public static final double BX = 1 - AX;
static final String TAG = GISHelper.class.getName();
public enum MarkerSymbolType {
TEXT, IMAGE, SIMPLE, IMAGE_TEXT, SIMPLE_TEXT, SIMPLE_LINE;
}
private static final double EARTH_RADIUS = 6378137.0;
/**
* 计算两点间的距离
*/
public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
double radLat1 = (lat_a * Math.PI / 180.0);
double radLat2 = (lat_b * Math.PI / 180.0);
double a = radLat1 - radLat2;
double b = (lng_a - lng_b) * Math.PI / 180.0;
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
return s;
}
// 计算方位角pab。
/**
* 计算方位角
*/
public static double gps2d(double lat_a, double lng_a, double lat_b, double lng_b) {
double d = 0;
lat_a = lat_a * Math.PI / 180;
lng_a = lng_a * Math.PI / 180;
lat_b = lat_b * Math.PI / 180;
lng_b = lng_b * Math.PI / 180;
d = Math.sin(lat_a) * Math.sin(lat_b) + Math.cos(lat_a) * Math.cos(lat_b) * Math.cos(lng_b - lng_a);
d = Math.sqrt(1 - d * d);
d = Math.cos(lat_b) * Math.sin(lng_b - lng_a) / d;
d = Math.asin(d) * 180 / Math.PI;
// d = Math.round(d*10000);
return d;
}
public static double calulateXYAnagle(double startx, double starty, double endx, double endy) {
double tan = Math.atan(Math.abs((endy - starty) / (endx - startx))) * 180 / Math.PI;
if (endx > startx && endy > starty)// 第一象限
{
return -tan;
} else if (endx > startx && endy < starty)// 第二象限
{
return tan;
} else if (endx < startx && endy > starty)// 第三象限
{
return tan - 180;
} else {
return 180 - tan;
}
}
private static double getPieValue(double dN, double dPieN_1) {
return AX * dN + BX * dPieN_1;
}
public static boolean isValidateData(Point point) {
boolean rst = false;
if (null != point && !point.isEmpty() && point.getX() != VALIDATE_X_Y && point.getY() != VALIDATE_X_Y && point.getX() != 0.0 && point.getY() != 0.0) {
rst = true;
}
return rst;
}
public static long double2Long(double x) {
return (long) (x * 1000000 + 0.5);
}
public static double long2Double(long x) {
return (x / 1000000.0);
}
private static DecimalFormat format = new DecimalFormat("0.0");
// 经纬度转墨卡托
/**
* SpatialReference.WKID_WGS84(4326) to
* SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE(102100)
*
* @param lonLat
* @return
*/
public static Point lonLat2Mercator(Point lonLat) {
// double x = lonLat.getX() * 20037508.34 / 180;
// double y = Math.log(Math.tan((90 + lonLat.getY()) * Math.PI / 360)) /
// (Math.PI / 180);
// y = y * 20037508.34 / 180;
Point point = (Point) GeometryEngine.project(lonLat, SpatialReference.create(SpatialReference.WKID_WGS84), SpatialReference.create(SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE));
// PtaDebug.e(TAG, "x:"+x+".."+point.getX()+",y"+y+".."+point.getY());
return point;
}
// 墨卡托转经纬度
/**
* SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE(102100) to
* SpatialReference.WKID_WGS84(4326)
*
* @param mercator
* @return
*/
public static Point mercator2lonLat(Point mercator) {
// double x = mercator.getX() / 20037508.34 * 180;
// double y = mercator.getY() / 20037508.34 * 180;
// y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) -
// Math.PI / 2);
Point point = (Point) GeometryEngine
.project(mercator, SpatialReference.create(SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE), SpatialReference.create(SpatialReference.WKID_WGS84));
return point;
}
}