[gdal-dev] [ogr2ogr] Anti-meridian issue when reprojecting from a Polar Stereographic projection to a geographic CRS
Andrey VI
andrey_vi at list.ru
Thu Oct 16 05:44:16 PDT 2025
Thanks Vedran, but I think this procedure will not help solve the problem. I tried to figure out the cause of the issue and may have found it.
I created 3 polygons in EPSG:3996 saved as test_polys_3996.csv:
WKT,ID
"POLYGON ((-3368075.98202296 0.0,0.0 3368075.98202296,3368075.98202296 0.0,0.0 -3368075.98202296,-3368075.98202296 0.0),(-2217499.59851296 0.0,0.0 -2217499.59851296,2217499.59851296 0.0,0.0 2217499.59851296,-2217499.59851296 0.0))",1
"POLYGON ((-2217499.59851296 0.0,0.0 2217499.59851296,2217499.59851296 0.0,0.0 -2217499.59851296,-2217499.59851296 0.0),(0.0 1100597.55599312,-1100597.55599312 0.0,0.0 -1100597.55599312,1100597.55599312 0.0,0.0 1100597.55599312))",2
"POLYGON ((0.0 -1100597.55599312,-1100597.55599312 0.0,0.0 1100597.55599312,1100597.55599312 0.0,0.0 -1100597.55599312))",3
IDs 1 and 2 are polygons with ring.
Then executed 3 commands:
ogr2ogr -f CSV --config OGR_WKT_PRECISION=3 -oo KEEP_GEOM_COLUMNS=NO -s_srs EPSG:3996 -t_srs EPSG:4326 -lco GEOMETRY=AS_WKT test_polys_3996-4326.csv test_polys_3996.csv
ogr2ogr -f CSV --config OGR_WKT_PRECISION=3 -oo KEEP_GEOM_COLUMNS=NO -s_srs EPSG:3996 -t_srs EPSG:4326 -wrapdateline -lco GEOMETRY=AS_WKT test_polys_3996-4326_wdl.csv test_polys_3996.csv
ogr2ogr -f CSV --config OGR_WKT_PRECISION=3 -oo KEEP_GEOM_COLUMNS=NO -s_srs EPSG:3996 -t_srs EPSG:4326 -wrapdateline -datelineoffset 180 -lco GEOMETRY=AS_WKT test_polys_3996-4326_wdl_dlo180.csv test_polys_3996.csv
ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
All 3 resulting files had the same content despite different options used:
WKT,ID
"POLYGON ((-90 60.0,180.0 60.0,90.0 60.0,0.0 60.0,-90 60.0),(-90 70.0,0.0 70.0,90.0 70.0,180.0 70.0,-90 70.0))","1"
"POLYGON ((-90 70.0,180.0 70.0,90.0 70.0,0.0 70.0,-90 70.0),(180.0 80.0,-90 80.0,0.0 80.0,90.0 80.0,180.0 80.0))","2"
"POLYGON ((-90 80.0,-180 80.0,-180 90,180 90,180.0 80.0,90.0 80.0,0.0 80.0,-90 80.0))","3"
Polygons with IDs 1 and 2 have incorrect geometry. These polygons are not wrapped at anti-meridian.
Polygon ID 1 should be
POLYGON ((180 60, 90 60, 0 60, -90 60, -180 60, -180 70, -90 70, 0 70, 90 70, 180 70, 180 60))
Polygon ID 2 should be
POLYGON ((180 70, 90 70, 0 70, -90 70, -180 70, -180 80, -90 80, 0 80, 90 80, 180 80, 180 70))
Polygon ID 3 has the correct geometry even without -wrapdateline option.
This could mean that -wrapdateline or reprojecting in general does not work right with polygons with rings and OGR produces incorrect geometry for them.
So this looks like an OGR bug to me. But this is my personal opinion as a non-specialist. Maybe I'm wrong.
>Wednesday, October 15, 2025 10:46 AM +03:00 from Vedran Stojnović < phidrho at gmail.com >:
>
>Hi Andrey,
>
>I am aware that this is not ogr2ogr solution, but you can watch my lecture on this kind of problem and procedure to avoid this problem in QGIS - and then maybe you can apply the same procedure/logic using only ogr2ogr.
>
>See this video, you can skip to around 45 minutes.
>https://www.youtube.com/watch?v=5M-Q0AinuiY&t=2702s
>
>uto, 14. lis 2025. u 22:02 Andrey VI via gdal-dev < gdal-dev at lists.osgeo.org > napisao je:
>>Unfortunately, the result is still incorrect.
>>The empty areas are still here around 88-89°N and some polygons are still broken (for example at -67°W, 76°N):
>>Example .
>>These polygons turned out to be hidden under others, although in the original data all polygons are adjacent but not overlapping. Not sure if this is a result of reported errors or a separate issue.
>>>Tuesday, October 14, 2025 4:48 PM +03:00 from Rahkonen Jukka < jukka.rahkonen at maanmittauslaitos.fi >:
>>>
>>>Hi,
>>>
>>>This command prints also 6 error lines, but at least the result does not have empty areas:
>>>
>>>ogr2ogr -t_srs epsg:4626 -wrapdateline -datelineoffset 180 foo3.shp polys.shp
>>>
>>>I do not know if the result is correct or not, just that it is different.
>>>
>>>-Jukka Rahkonen-
>>>
>>>
>>>________________________________________
>>>Lähettäjä: gdal-dev < gdal-dev-bounces at lists.osgeo.org > käyttäjän Andrey VI via gdal-dev < gdal-dev at lists.osgeo.org > puolesta
>>>Lähetetty: Tiistai 14. lokakuuta 2025 15.50
>>>Vastaanottaja: gdal-dev at lists.osgeo.org < gdal-dev at lists.osgeo.org >
>>>Aihe: [gdal-dev] [ogr2ogr] Anti-meridian issue when reprojecting from a Polar Stereographic projection to a geographic CRS
>>>
>>>Hello. I can't reproject data from a Polar Stereographic projection (EPSG:3996) to a geographic projection (EPSG:4326) correctly using ogr2ogr. Command:ogr2ogr -t_srs EPSG:4326 -wrapdateline polys_4326.shp polys.shpERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
>>>ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
>>>ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
>>>ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
>>>ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring
>>>ERROR 1: IllegalArgumentException: Points of LinearRing do not form a closed linestring As a result some polygons are broken and also some polygons appears with artifacts.[X]The data used and the result (58 MB): https://drive.google.com/file/d/176jtROjjeTlAQTITAJ75tBT1GwiUzSUm/view?usp=sharing . How to reproject from a projection naturally crossing the anti-meridian to a geographic CRS without any errors using ogr2ogr?--Andrey
>>
>>--
>>Andrey VI
>>Sent from Mail _______________________________________________
>>gdal-dev mailing list
>>gdal-dev at lists.osgeo.org
>>https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>--
>Srdačan pozdrav / Kind regards,
>Vedran Stojnović.
--
Andrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20251016/bae3a2a7/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_polys_3996.zip
Type: application/zip
Size: 939 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20251016/bae3a2a7/attachment-0001.zip>
More information about the gdal-dev
mailing list