2つの面間の最短距離アルゴリズム(記録)
geotools 3を使用しました.5.2.JArパッケージは、2つのジオメトリを作成し、JARメソッドで2つの面間の最短距離を返します.
import com.vividsolutions.jts.geom.*;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import com.vividsolutions.jts.operation.distance.DistanceOp;
import org.geotools.geometry.jts.JTSFactoryFinder;
/**
* Created by 18621 on 2016/8/31.
*/
public class GeoToolsTest {
public static void main(String args []){
String wktPoly = "POLYGON ((121.58078350879 30.804800706056, 121.6261021123 30.460104661134, 122.14108624316 30.469717698243, 121.88290753222 30.833639817384,121.88290753222 30.833639817384,121.58078350879 30.804800706056))"; // wkt
String wktPoly1 = "POLYGON ((121.8719212041 31.117911057618, 121.94607891894 30.936636643556, 122.29764141894 30.840506272462,122.29489483691 31.237387375978 ,122.04632916308 31.106924729493,121.8719212041 31.117911057618))";
WKTReader reader = new WKTReader();
//GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
try {
Geometry poly = reader.read(wktPoly);
Geometry poly1 = reader.read(wktPoly1);
DistanceOp t = new DistanceOp(poly,poly1);
Coordinate[] a = t.nearestPoints();
System.out.println(a[0]+":"+a[1]+"distance:"+poly.distance(poly1));
//geometryFactory.createPolygon(wktPoly);
} catch (ParseException e) {
e.printStackTrace();
}
//geometry.intersects(geometry);
//geometry.setUserData("");
}
}