<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML-esimuotoiltu Char";
        margin:0cm;
        font-size:10.0pt;
        font-family:"Courier New";}
span.pre
        {mso-style-name:pre;}
span.sig-paren
        {mso-style-name:sig-paren;}
span.HTML-esimuotoiltuChar
        {mso-style-name:"HTML-esimuotoiltu Char";
        mso-style-priority:99;
        mso-style-link:HTML-esimuotoiltu;
        font-family:Consolas;}
span.Shkpostityyli26
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 2.0cm 70.85pt 2.0cm;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="FI" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">I was just testing the approach with ogrinfo (GDAL 3.11.0dev) but maybe I am doing something wrong.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">This works in SpatiaLite gui (or at least the length is not the same):<br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="mso-fareast-language:EN-US">Cartesian length<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue;background:white;mso-highlight:white">select</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:#C08000;background:white;mso-highlight:white">ST_Length</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">(</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:#C08000;background:white;mso-highlight:white">ST_GeomFromText</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">(</span><span style="font-size:10.0pt;font-family:"Courier New";color:fuchsia;background:white;mso-highlight:white">'LINESTRING
 ( 339775 6936992, 548057 6951815 )'</span><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">,</span><span style="font-size:10.0pt;font-family:"Courier New";color:fuchsia;background:white;mso-highlight:white">3067</span><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">));</span><b><span style="font-size:10.0pt;font-family:"Courier New";color:blue;background:white;mso-highlight:white"><o:p></o:p></span></b></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">208808.794961<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Length along ellipsoid (accepts only Long/Lat coordinates, see
<a href="https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.1.0.html">https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.1.0.html</a>:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue;background:white;mso-highlight:white">select</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:#C08000;background:white;mso-highlight:white">ST_Length</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">(</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:#C08000;background:white;mso-highlight:white">ST_Transform</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">(<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span style="font-size:10.0pt;font-family:"Courier New";color:#C08000;background:white;mso-highlight:white">ST_GeomFromText</span></b><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">(</span><span style="font-size:10.0pt;font-family:"Courier New";color:fuchsia;background:white;mso-highlight:white">'LINESTRING
 ( 339775 6936992, 548057 6951815 )'</span><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">,</span><span style="font-size:10.0pt;font-family:"Courier New";color:fuchsia;background:white;mso-highlight:white">3067</span><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">),</span><span style="font-size:10.0pt;font-family:"Courier New";color:fuchsia;background:white;mso-highlight:white">4326</span><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">,</span><span style="font-size:10.0pt;font-family:"Courier New";color:fuchsia;background:white;mso-highlight:white">1</span><span style="font-size:10.0pt;font-family:"Courier New";color:gray;background:white;mso-highlight:white">);</span><b><span style="font-size:10.0pt;font-family:"Courier New";color:blue;background:white;mso-highlight:white"><o:p></o:p></span></b></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">208875.050186<br>
<br>
Now the same with ogrinfo. I simplified the SQL by  saving the test linesting into a file in EPSG:3067.<br>
<br>
ogrinfo -dialect sqlite -sql "select ST_Length(geometry) from length" length.json<br>
208808.794960845<br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Good so far. But with “use_ellipsoid” gives very unexpected result:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><br>
ogrinfo -dialect sqlite -sql "select ST_Length(geometry,1) from length" length.json<br>
<br>
417750.100376289<br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Same wrong result also with this:<br>
<br>
ogrinfo -dialect sqlite -sql "select ST_Length(ST_Transform(geometry,4326),1) from length" length.json<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">length.json is this:<br>
<br>
{<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">"type": "FeatureCollection",<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">"crs": {"type": "name", "properties": { "name": "EPSG:3067" }},<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">"features": [<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">{ "type": "Feature", "properties": null, "geometry": {"type":"LineString","coordinates":[[339775,6936992],[548057,6951815]]} }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">-Jukka Rahkonen-<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b>Lähettäjä:</b> gdal-dev <gdal-dev-bounces@lists.osgeo.org>
<b>Puolesta </b>Even Rouault via gdal-dev<br>
<b>Lähetetty:</b> tiistai 21. tammikuuta 2025 12.45<br>
<b>Vastaanottaja:</b> Thomas Knudsen <knudsen.thomas@gmail.com>; Peter Bennewitz <geo25@pab-opto.de><br>
<b>Kopio:</b> gdal-dev@lists.osgeo.org<br>
<b>Aihe:</b> Re: [gdal-dev] UTM local correction for height and distance-to-reference-meridian ?<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p><o:p> </o:p></p>
<div>
<p class="MsoNormal">Le 21/01/2025 à 11:37, Thomas Knudsen via gdal-dev a écrit :<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">If you plan to transform to a different system anyway, I would definitely prefer going to geographical coordinates, and computing the length of the geodesic between the two points.<o:p></o:p></p>
</div>
</blockquote>
<p>actually no need to do the explicit conversion to geographical coordinates, if the appropriate SRS is attached to your geometry, OGRGeometry::<span class="pre">get_GeodesicLength</span><span class="sig-paren">() will do the right thing:</span>
<a href="https://gdal.org/en/stable/api/ogrgeometry_cpp.html#_CPPv4NK13OGRLineString18get_GeodesicLengthEPK19OGRSpatialReference">
https://gdal.org/en/stable/api/ogrgeometry_cpp.html#_CPPv4NK13OGRLineString18get_GeodesicLengthEPK19OGRSpatialReference</a><o:p></o:p></p>
<p>Python API: <a href="https://gdal.org/en/stable/api/python/vector_api.html#osgeo.ogr.Geometry.GeodesicLength">
https://gdal.org/en/stable/api/python/vector_api.html#osgeo.ogr.Geometry.GeodesicLength</a><o:p></o:p></p>
<p>Python examples: <a href="https://github.com/OSGeo/gdal/blob/master/autotest/ogr/ogr_geom.py#L4560">
https://github.com/OSGeo/gdal/blob/master/autotest/ogr/ogr_geom.py#L4560</a><o:p></o:p></p>
<pre>-- <o:p></o:p></pre>
<pre><a href="http://www.spatialys.com/">http://www.spatialys.com</a><o:p></o:p></pre>
<pre>My software is free, but my time generally not.<o:p></o:p></pre>
</div>
</body>
</html>