等距离转经纬度坐标
<dependency>
<groupId&hinker</groupId>
<artifactId>MeteoInfoLib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
代码
info.projection.proj4j.CRSFactory;
info.projection.proj4j.CoordinateReferenceSystem;
info.projection.proj4j.CoordinateTransform;
info.projection.proj4j.CoordinateTransformFactory;
info.projection.proj4j.ProjCoordinate;
public class Grid2WGS84Utils {
//lat_0\lon_0为中⼼点经纬度
private static final String LCC_PARAM = "+proj=lcc +lat_1=30.0 +lat_2=60.0 +lat_0=30.0 +lon_0=102.0 +x_0=3000 +y_0=3000 +units=m"; private static final String WGS_PARAM = "+proj=latlong +datum=WGS84";
private static final double X_MIN = -2850541D;//X轴最⼩值
private static final double X_DEL = 3000D;//X轴间隔3KM
private static final double Y_MIN = -1932198.7D;//Y轴最⼩值
private static final double Y_DEL = 3000D;//Y轴间隔3KM
public static final int xCount = 1901, yCount = 1801;//X、Y轴点个数,坐标(xIndex,yIndex)reference group
private static final CoordinateTransform transform;
static {
CoordinateReferenceSystem src = new CRSFactory().createFromParameters("lcc", LCC_PARAM);
CoordinateReferenceSystem dst = new CRSFactory().createFromParameters("wgs", WGS_PARAM);
transform = new CoordinateTransformFactory().createTransform(src, dst);
}
private Grid2WGS84Utils() {
// empty method
}
/**
* build ProjCoordinate from grid's index
*
* @param xIndex x index, start from 0, you can use double like 180.5
* @param yIndex y index, start from 0, you can use double like 160.5
* @return the source ProjCoordinate
*/
public static ProjCoordinate buildSource(double xIndex, double yIndex) {
double x = X_MIN + X_DEL * xIndex;
double y = Y_MIN + Y_DEL * yIndex;
return new ProjCoordinate(x, y);
}
/**
*
* @param buildSource()
* @return lon、lat
*/
public static ProjCoordinate transform(ProjCoordinate src) {
ProjCoordinate tgt = new ProjCoordinate();
ProjCoordinate tgt = new ProjCoordinate();
return tgt;
}
public static void main(String[] args) {
// ProjCoordinate pc = buildSource(0,0);//左下⾓
ProjCoordinate pc = buildSource(950,900);//这不是中⼼点,需要⾃⼰计算 ProjCoordinate pc2 = transform(pc);
System.out.println(pc2.x+"=="+pc2.y);
}
}
可以通过验证四个⾓坐标确定是否正确。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论