通常经纬度坐标转平面坐标有两种做法:
- 墨卡托坐标投影(UTM坐标系)
- 米勒坐标投影
- 米勒坐标系
package sg.edu.ntu.huangcheng;
public class MillerCoordinate {
public static double[] MillierConvertion(double lat, double lon)
{
double L = 6381372 * Math.PI * 2;//地球周长
double W=L;// 平面展开后,x轴等于周长
double H=L/2;// y轴约等于周长一半
double mill=2.3;// 米勒投影中的一个常数,范围大约在正负2.3之间
double x = lon * Math.PI / 180;// 将经度从度数转换为弧度
double y = lat * Math.PI / 180;// 将纬度从度数转换为弧度
y=1.25 * Math.log( Math.tan( 0.25 * Math.PI + 0.4 * y ) );// 米勒投影的转换
// 弧度转为实际距离
x = ( W / 2 ) + ( W / (2 * Math.PI) ) * x;
y = ( H / 2 ) - ( H / ( 2 * mill ) ) * y;
double[] result=new double[2];
result[0]=x;
result[1]=y;
return result;
}
}
- UTM坐标系
缺点:由于UTM坐标系将整个地球划分为不同的区域(ZONES),不同区域的坐标间距很难计算。
package sg.edu.ntu.huangcheng;
/*
* Author: Sami Salkosuo, sami.salkosuo@fi.ibm.com
*
* (c) Copyright IBM Corp. 2007
*/
import java.util.Hashtable;
import java.util.Map;
public class CoordinateConversion
{
public CoordinateConversion()
{
}
public double[] utm2LatLon(String UTM)
{
UTM2LatLon c = new UTM2LatLon();
return c.convertUTMToLatLong(UTM);
}
public String latLon2UTM(double latitude, double longitude)
{
LatLon2UTM c = new LatLon2UTM();
return c.convertLatLonToUTM(latitude, longitude);
}
private void validate(double latitude, double longitude)
{
if (latitude < -90.0 || latitude > 90.0 || longitude < -180.0
|| longitude >= 180.0)
{
throw new IllegalArgumentException(
"Legal ranges: latitude [-90,90], longitude [-180,180).");
}
}
public String latLon2MGRUTM(double latitude, double longitude)
{
LatLon2MGRUTM c = new LatLon2MGRUTM();
return c.convertLatLonToMGRUTM(latitude, longitude);
}
public double[] mgrutm2LatLon(String MGRUTM)
{
MGRUTM2LatLon c = new MGRUTM2LatLon();
return c.convertMGRUTMToLatLong(MGRUTM);
}
public double degreeToRadian(double degree)
{
return degree * Math.PI / 180;
}
public double radianToDegree(double radian)
{
return radian * 180 / Math.PI;
}
private double POW(double a, double b)
{
return Math.pow(a, b);
}
private double SIN(double value)
{
return Math.sin(value);
}
private double COS(double value)
{
return Math.cos(value);
}
private double TAN(double value)
{
return Math.tan(value);
}
private class LatLon2UTM
{
public String convertLatLonToUTM(double latitude, double longitude)
{
validate(latitude, longitude);
String UTM = "";
setVariables(latitude, longitude);
String longZone = getLongZone(longitude);
LatZones latZones = new LatZones();
String latZone = latZones.getLatZone(latitude);
double _easting = getEasting();
double _northing = getNorthing(latitude);
UTM = longZone + " " + latZone + " " + ((int) _easting) + " "
+ ((int) _northing);
// UTM = longZone + " " + latZone + " " + decimalFormat.format(_easting) +
// " "+ decimalFormat.format(_northing);
return UTM;
}
protected void setVariables(double latitude, double longitude)
{
latitude = degreeToRadian(latitude);
rho = equatorialRadius * (1 - e * e)
/ POW(1 - POW(e * SIN(latitude), 2), 3 / 2.0);
nu = equatorialRadius / POW(1 - POW(e * SIN(latitude), 2), (1 / 2.0));
double var1;