地点からshpファイル(ports.shp)までの距離を自然地理データから計算したい。shpファイルから座標を読み取り、距離を計算する
例えば、私は、ファイルの特徴をロードしています:
...
String filename = "10m_cultural/ne_10m_ports.shp";
...
public static void Calcs(String filename)
throws IOException, NoSuchAuthorityCodeException, FactoryException, TransformException {
HashMap<String, Object> params = new HashMap<>();
params.put("url", DataUtilities.fileToURL(new File(filename)));
DataStore ds = DataStoreFinder.getDataStore(params);
String name = ds.getTypeNames()[0];
SimpleFeatureSource source = ds.getFeatureSource(name);
SimpleFeatureCollection features = source.getFeatures();
}
今、私は距離を計算したいから、例えば点は次のとおりです。
GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
Point p = gf.createPoint(new Coordinate(43, 18));
私は距離を計算することを知っています:
CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
Point start = gf.createPoint(new Coordinate(43, 18));
Point dest = gf.createPoint(new Coordinate(?????));
GeodeticCalculator gc = new GeodeticCalculator(crs);
gc.setStartingPosition(JTS.toDirectPosition(start.getCoordinate(), crs));
gc.setDestinationPosition(JTS.toDirectPosition(dest.getCoordinate(), crs));
double distance = gc.getOrthodromicDistance();
ファイルをロードするから
Point dest = gf.createPoint(new Coordinate(?????));
私はfeatures
持っているが、それはどんなgetCoordinates()
を持っていない:
が、私は先の点の座標(ports.shpファイル)を見つける方法がわかりません方法。
また、ports.shp
は多くのPOINT
ジオメトリで構成されています。私は何らかの理由で基準点のすべての点を計算してから、最も近い点を選択する必要がありますか?
これは、[gis.se] Stack Exchangeでもっと話題になっているようです。 – PolyGeo
「目的地」とは、開始座標に最も近い点を意味しますか?もしそうなら、あなたは確かに他のすべての点に対してチェックする必要があります。どのように移動することに決めましたか? – DarkCygnus
@GrayCygnus:はい、私は始点から最も近い点(ports.shpから)を意味しています。私の問題は、port.shpファイルの座標を正しく読み取る方法です。次に、始点に最も近い点を見つけます。 – George