使用 GeoTools 和 Maven,应该不会太难。Maven 将处理依赖项。幸运的是,您不需要整个 Geotools 套件来进行“无头”计算。
我希望这是你正在寻找的。
绒球:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.bar</groupId>
<artifactId>geo</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>opengeo</id>
<name>OpenGeo Maven Repository</name>
<url>http://repo.opengeo.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>9.0</version>
</dependency>
</dependencies>
</project>
编码:
package org.bar;
import org.geotools.referencing.GeodeticCalculator;
import java.awt.geom.Point2D;
/**
* How far is NY from London ?
*/
public class DistanceTest {
public final static void main(final String[] args) {
final GeodeticCalculator calc = new GeodeticCalculator();
final Point2D london = new Point2D.Double(-0.127512, 51.507222);
final Point2D ny = new Point2D.Double(-73.94, 40.67 );
calc.setStartingGeographicPoint(london);
calc.setDestinationGeographicPoint(ny);
System.out.println("Distance London-NY: " + calc.getOrthodromicDistance()/1000 + " kms");
}
}