mcf*_*oft 6 java projection map
我现在搜索了一天,但没有在Javacode找到我的问题的任何例子.
我有一个大小为2000*1400像素的世界地图,带有"Mollweide"投影.如何找出地图中点(500,300)的经度和纬度?我想用Java编写代码.
我尝试使用'Java Map Projection Library'来做到这一点:
Point2D.Double pointonmap = null;
Point2D.Double latlon = null;
MolleweideProjection molproj=new MolleweideProjection();
pointonmap = new Point2D.Double (1400,1000);
latlon=molproj.inverseTransform(pointonmap,new Point2D.Double ());
System.out.println("latlon: " + latlon.getX() + ", " + latlon.getY());
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?Codeexample或提示.
感谢致敬
维基百科拥有您需要的大部分信息:
像往常一样,这些公式假设了一些事情。它们以投影尺寸表示,该尺寸小于组件。[0,0] 位于中心,而不是左上角。Y 坐标上升而不是下降。结果是半径而不是度数。解决这些问题,它们就会为你工作。
由于您没有提供链接,我假设您正在使用GitHub 上的Java 地图投影库。没有文档且时间有限,我无法 inverseTransform充分理解来修复您的代码;但捆绑的 MapComponent 的编码更简单:
map.addMouseListener( new MouseAdapter() { @Override public void mouseClicked( MouseEvent e ) {
double x = e.getX() - map.getWidth() / 2, // Mouse X with [0,0] at centre.
y = e.getY() - map.getHeight() / 2, // Mouse Y with [0,0] at centre.
// Max Y of projected map, in pixel with [0,0] at centre.
maxY = map.getMapExtension().getMaxY() * map.getScaleToShowAll(),
sqrt2 = Math.sqrt( 2 ), // Can be optimised away, but let's be faithful.
R = maxY / sqrt2, // Radius of projection, in pixel.
theta = Math.asin( y / ( R * sqrt2 ) );
int delta_long = -lon0Slider.getValue(); // Longtitude shift from -180 to 180.
// Find lat long in radius and converts to degree.
double latInRad = Math.asin( -( 2 * theta + Math.sin( 2 * theta ) ) / Math.PI ),
latitude = Math.toDegrees( latInRad ),
longInRad = Math.PI * x / ( 2 * R * sqrt2 * Math.cos( theta ) ),
longitude = Math.toDegrees( longInRad ) + delta_long;
System.out.println( "Lat: " + latitude + ", Long: " + longitude );
}
Run Code Online (Sandbox Code Playgroud)
您可以将此代码粘贴到 的构造函数中ch.ethz.karto.gui.ProjectionSelectionPanel。IDE 应该报告映射的两个方法是私有的,您需要先将它们更改为公共(或使用反射)。然后启动它,选择 Mollweide,单击地球仪并观看控制台。请随意调整窗口大小。
| 归档时间: |
|
| 查看次数: |
225 次 |
| 最近记录: |