Reputation: 105
I am trying to draw a line on the earth using geotools but instead of considering the shortest distance between two points while drawing a line,The drawn lineString is taking a long route around the earth and providing wrong results.When i draw the same line on google maps the resulting route is being drawn correctly.The black and white map is using geotools and other one is from google maps.Can anyone please point me where i am going wrong PS: The coordinates are in log,lat
Coordinate[] myLineString = new Coordinate[]{
new Coordinate( -110.0,20.0),
new Coordinate( 143.41666666666666,41.583333333333336 ),
new Coordinate( 140.8,41.65)
};
Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(hints);
LineString lineString = geometryFactory.createLineString(coordinates);
Upvotes: 0
Views: 213
Reputation: 10976
The simple answer is because you are using EPSG:4326 which has a discontinuity at +/- 180 degrees. So your line is represented in the "obvious" way.
The solution is to draw your map in another projection such as PDC Mercator (EPSG:3832) which will give you a map like:
As you can see there are a few issues with the background map as Greenland and Antarctica cross the new break at the map's edges.
Upvotes: 1