I want to identify closest points to a polygon over the dateline in an OGR/Python script. I found this workaround for PostGIS but I'm not 100% certain about the applicability in my case. This may be because I'm not very good at reading SQL but I'm also not convinced about the fixed longitude values to detect dateline intersections (-178.75 lon) in the script. I experimented with map projections because I want to process data automatically, regardless of the input data and the distance to the dateline.
Problems don't occur when the longitutes are outside the -180 / +180 degree range (as long as coordinates are adjacent), but when, for instance, the polygon is at -179° longitude and a close point is at +179° longitude. The first image shows a case, where the closest points are correctly identified. Imagine the orange line to be the dateline and the green lines the connectors between points and closest point on the polygon outline. The second case is what I would like to consider.
I experimented with map projections. I defined a central meridian for the longitude of the polygon's centroid. However, this didn't solve the issue as in the 'not OK' case, the point which is causing problems simply has a longitude of +350° while the polygon has a central longitude of 0°. For calculations, points and polygon seem far off even though they are very close on a spheroid. Can you help me find a workaround for this? Are map projections suitable for the consideration of dateline intersections?