我现在搜索了大约一天,但没有在 Javacode 中找到我的问题的任何示例。
我有一张 2000*1400 像素的世界地图,带有“Mollweide”投影。 我怎样才能找出 map 中点 (500,300) 的经度和纬度? 我想用 Java 对此进行编码。
我尝试使用“Java map 投影库”来做到这一点:
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());
有人可以帮我吗?代码示例或提示。
感谢和问候
最佳答案
维基百科有 most of the information你需要:
这些公式像往常一样假设了一些事情。 它们以比组件小的投影尺寸说话。 [0,0] 位于中心,而不是左上角。 Y坐标上升而不是下降。 结果是半径而不是度数。 解决这些问题,它们就会为您工作。
由于您没有提供链接,我假设您使用的是 Java map 投影库 on GitHub .
没有文档并且时间有限,我无法很好地理解 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 );
}
您可以将此代码粘贴到 ch.ethz.karto.gui.ProjectionSelectionPanel
的构造函数中。
IDE 应该报告映射的两个方法是私有(private)的,您需要先将它们更改为公共(public)(或使用反射)。
然后启动它,选择 Mollweide,单击地球并观察控制台。随意调整窗口大小。
关于java - 在 Mollweide 投影中获取我的世界地图中某个点的经度纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12007423/