Hi Dave
This May I'll be 70. I have tried git a couple of times but never went very far. Sorry, I post again.
I further nail down the PyCoast problems we face. I now have a bug fix and a partial workaround.
I had a look at how GSHHG handles the dateline. The WEB page says (and I also checked in QGIS):
<cite>
1. ESRI shapefiles. This format is probably the most useful for users of GSHHG. Note that due to limitations of most (all?) GIS software and Google Earth, a handful of polygons straddling the Dateline (chief among them the Antarctic polar cap polygon) have been split into east and west components.
</cite>
https://www.soest.hawaii.edu/pwessel/gshhg/That's why cylindric projections (like eqc or merc) of the whole globe work with lon_0=0°, lon=+/-180° while with lon_0=180°, lon=0°-360° they will cut Africa, Eurasia and the UK in left and right parts and connect these with horizontal lines over the whole image as demonstrated already 8 years ago. The problem also exists when borders, lakes or rivers are cut in left and right parts. A theoretically simple solution would just lift the pen for unexpededly long segments.
https://groups.google.com/g/pytroll/c/tzmtaDuaGD4/m/kVrY2RZ93gEJThe problem will also show up with conic projections but is normally hidden by a smaller area_extent that does not include the meridian opposite lon_0. With cylindric projections and reduced area_extents we basically face two different problems that I name A) and B). Below I use my OPC Mercator MSLP chart areas that are 80° wide with app. lat_min=16°, lat_max=65°.
A) We have a problem mainly due to the size of Eurasia
My Atlantic East area makes one scratch below Greenland when I use
Meteosat11, Atlantic East, opcae, central meridian lon_0=-30°, symmetric area_extent
while it seems to work fine without this scratch when I use
Meteosat11, Atlantic East, opcae, central meridian lon_0=0°, asymmetric area_extent
EXPLANATION: Opposite to -30° is 150° where the Eurasia polygon has a latitude of 59.6°
Setting lon_0=-30° means that the Eurasia polygon makes the horizontal scratch when lon
passes 150°. With lon_0=0° the opposite is at 180° where latitude is above my lat_max.
B) The real big problem with coastlines seems to show up when we include the dateline lon=+/-180°.
Pycoast works with a bounding box lon_min, lon_max, lat_min, lat_max derived from the area_extent and projection. This window is compared with the bounding boxes of the coastline polygons to sort out non relevant cases. For area_extents that do not include the dateline we have lon_min < lon_max. The PyCoast code works for that case except for problem A). For our area of the western Pacific (opcpw, including the dateline) with center meridian at 175° this evaluates to
lon_min = 135.12795371957384 lon_max = -144.796221854012
unfortunately the PyCoast code in file cw_base.py does not handle this case properly. It just tries *ALL* coastline polygons. But opposite to 175° is the UK at -5° that produces a lot of horizontal scratches. The code should and -- as far as I understand it -- can easily be improved for case B) while case A) can be at least worked around with the choice of lon_0 and an asymmetric area_extent.
Original cw_base.py in function add_shapes()
# Check if polygon is possibly relevant
s_lon_ll, s_lat_ll, s_lon_ur, s_lat_ur = shape.bbox
if lon_min > lon_max:
pass
elif (lon_max < s_lon_ll or lon_min > s_lon_ur or
lat_max < s_lat_ll or lat_min > s_lat_ur):
# Polygon is irrelevant
continue
My fix in cw_bas.py in function add_shapes()
# Check if polygon is possibly relevant
s_lon_ll, s_lat_ll, s_lon_ur, s_lat_ur = shape.bbox
if lon_min > lon_max:
if (lon_max < s_lon_ll and lon_min > s_lon_ur or
lat_max < s_lat_ll or lat_min > s_lat_ur):
continue
# Polygon is irrelevant
elif (lon_max < s_lon_ll or lon_min > s_lon_ur or
lat_max < s_lat_ll or lat_min > s_lat_ur):
# Polygon is irrelevant
continue
Below I add 3 Himawari8 images of my Pacific West area opcpw. I enable coastlines, borders and rivers. The first image is with lon_0=175° and symmetric area_extent. You see a lot of case B) coastline scratches (yellow), borders scratches (red) and rivers scratches (blue). The second image is opcpw with lon_0=175° and symmetric area_extent plus my above fix applied. We still have two case A) coastline scratches (yellow) that are due to Eurasia (Spain at lon=5°). In the third image opcpw uses lon_0=170° and a slightly asymmetric area_extent plus my above fix. Everything looks clean and works for me now. I still don't have a github account. Maybe some developer can have a look at my above fix and possibly make a PR for me. Thanks!
Best Regards,
Ernst
P.S.
There is another long standing BUG in that with omerc_bb the coastline of Ireland is sometimes missing.
This is probably also due to the above code if lon_min is not evaluated to what it should be for omerc_bb.