1

Given a list of coordinates, I need to create a line shapefile joining each of the point with a Python GDAL/OGR script. The procedure described here Convert XY points to a line? works fine in almost all cases, except when the points are crossing the date change meridian. When this happens, the line connects the two points by crossing the entire world, which is a obvious mistake.

How can I force the script to connect the 2 points through the shortest distance?

Here are some coordinate examples:

lon, lat
172.5, 50.0
175.0, 43.4
-175.0, 35.0
-173.1, 31
-172.1, 28.0
-171.3, 26.5
-173.9, 21.8
2

For the shortest distance, you might want to look into the calculation of great circles.

Here is one example done in QGIS: great circles in QGIS and export in 3857 webmap

The local CRS does not break at the date line.

If your area of interest is just around the date line, you can use a local transverse mercator projection:

+proj=tmerc +lat_0=50 +lon_0=172.5 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs

or follow my advice at QGIS display world country shape files centered on pacific ocean using Robinson, Miller Cylindrical or other projection

If you want to display your lines in a "normal" projection, you have to densify your line geometry, and cut it at the date line (similar to Lines on reprojected sp objects with Mollweide projection)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.