I am using com.vividsolutions.jts.geom to perform the distance calculations. I have a list of "LineString"s and a Point (Say A). I want to determine the
- The nearest LineString to the Point A.
- The nearest Coordinate in the LineString (which I got from above) to the Point A.
For achieving this I am looping through all the "LineString"s and use the method distance() to find the distance from LineString to Point A.
Below is the code segment I am using currently.
private double findMinDistance(List<LineString> coastalLines, Coordinate c) {
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Point point = geometryFactory.createPoint(c);
double minDistance = -1;
for (LineString lineString : coastalLines) {
double currentDistance = lineString.distance(point);
if (minDistance == -1 || minDistance > currentDistance) {
minDistance = currentDistance;
}
}
return minDistance; // result 0.008030136081505605
}
I want the minimum distance in meters. I am not sure what units does the distance method returns. On googling I found that the return value of distance() method is in central angle degrees. So to convert it to meters I am using the below code.
minDistance = (minDistance * (Math.PI / 180) * 6378137);
Is this is the proper valid approach? I don't think this gives me the accurate results. I am expecting the result to be as accurate as possible. Is there a concrete API which converts the distance to meters?
Note: I am working for a project to perform some geographical calculations of Western Australia.
Thanks in advance.
Sai.
Aucun commentaire:
Enregistrer un commentaire