<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Nicolas,</p>
    <p>ogr2ogr uses the OGRGeometryFactory::transformWithOptions()
      method that has logic to deal with poles, antimerdian, etc.
      whereas OGRGeometry::transform() does basic point-to-point
      reprojection</p>
    <p>You can achieve what you want by using the
      ogr.GeomTransformer(ct) method that returns a ogr.GeomTransformer
      object that has a Transform(ogr.Geometry) method. See below test
      from GDAL's autotest suite:<br>
    </p>
    <p>def test_ogr_geomtransfomer_default():<br>
      <br>
          src = osr.SpatialReference()<br>
          src.ImportFromEPSG(32660)<br>
      <br>
          dst = osr.SpatialReference()<br>
          dst.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)<br>
          dst.ImportFromEPSG(4326)<br>
      <br>
          ct = osr.CoordinateTransformation(src, dst)<br>
          geom = ogr.CreateGeometryFromWkt(<br>
              "LINESTRING(832864.275023695 0,835092.849076364 0)"<br>
          )<br>
          transformer = ogr.GeomTransformer(ct)<br>
      <br>
          geom_dst = transformer.Transform(geom)<br>
          assert (<br>
              geom_dst.ExportToWkt()<br>
              == "MULTILINESTRING ((179.99 0.0,180 0),(-180 0,-179.99
      0.0))"<br>
          )<br>
    </p>
    <p>Even<br>
    </p>
    <div class="moz-cite-prefix">Le 14/03/2023 à 19:15,
      Dion-Degodez,Nicolas (ECCC) a écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:YT3PR01MB817835B009AC1F1886D28BA9F2BE9@YT3PR01MB8178.CANPRD01.PROD.OUTLOOK.COM">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <div class="WordSection1">
        <p class="MsoNormal"><u>Context</u></p>
        <p class="MsoNormal">We are trying to reproject a GeoJSON
          polygon to EPSG:4326.</p>
        <p class="MsoNormal">In some cases, depending on whether we use
          the ogr2ogr command line or the equivalent in python, the
          resulting polygon is different.
        </p>
        <p class="MsoNormal">In those situations, the command line gives
          us the appropriate polygon, whereas the python code gives us a
          distorted polygon.</p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal"><u>Question</u></p>
        <p class="MsoNormal">Any idea why there is a difference between
          the command line and the python results? Is there a mistake in
          our interpretation of the code/how we converted it in python?</p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal"><u>Sample GeoJSON</u>: <a
            href="https://pastebin.com/hUiVVjFv" moz-do-not-send="true"
            class="moz-txt-link-freetext">
            https://pastebin.com/hUiVVjFv</a></p>
        <p class="MsoNormal">Proj4: "+proj=stere +lat_0=90 +lat_ts=60
          +lon_0=264 +x_0=0 +y_0=0 +R=6371229 +units=m +no_defs"</p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal"><u>Command line that works</u>: ogr2ogr
          -s_srs "+proj=stere +lat_0=90 +lat_ts=60 +lon_0=264 +x_0=0
          +y_0=0 +R=6371229 +units=m +no_defs" -t_srs EPSG:4326
          result_command_line.json geojson.json</p>
        <p class="MsoNormal">Result: <a
            href="https://pasteboard.co/cTpZBRamEYv8.jpg"
            moz-do-not-send="true" class="moz-txt-link-freetext">https://pasteboard.co/cTpZBRamEYv8.jpg</a>
        </p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal"><u>Python code</u> (we would expect the
          same output as the command line):
          <a href="https://pastebin.com/QgWDBL1W" moz-do-not-send="true"
            class="moz-txt-link-freetext">https://pastebin.com/QgWDBL1W</a></p>
        <p class="MsoNormal">Result: <a
            href="https://pasteboard.co/8iSv0vbnQlHw.jpg"
            moz-do-not-send="true" class="moz-txt-link-freetext">https://pasteboard.co/8iSv0vbnQlHw.jpg</a><br>
          <br>
          Thank you!</p>
        <p class="MsoNormal">Nicolas D.</p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal"> </p>
        <p class="MsoNormal"> </p>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
  </body>
</html>