<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">Le 16/10/2023 à 15:15, Javier Jimenez
Shaw via gdal-dev a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:CADRrdKvRJvfVdvWsXygz23w7vUeuxcdi3Vw9hLgBhpt0opRTeA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>Do you mean a MultiLineString?</div>
<div><br>
</div>
<div>This piece of code is working for me (I hope without any
bug).<br>
</div>
<div><br>
</div>
<div><span style="font-family:monospace">if
(wkbFlatten(poGeometry->getGeometryType()) ==
wkbMultiLineString)</span></div>
<div><span style="font-family:monospace">
multiLineStringGeometry(poGeometry);</span></div>
<div><span style="font-family:monospace">...<br>
</span></div>
<div><span style="font-family:monospace">
multiLineStringGeometry(OGRGeometry* poGeometry)<br>
{<br>
OGRMultiLineString* multiLine =
dynamic_cast<OGRMultiLineString*>(poGeometry);<br>
int numGeometries =
multiLine->getNumGeometries();<br>
for (int i = 0; i < numGeometries; i++)<br>
{<br>
OGRGeometry* eachGeometry =
multiLine->getGeometryRef(i);<br>
OGRLineString* line =
dynamic_cast<OGRLineString*>(eachGeometry);<br>
// do whatever with that LineString<br>
}</span></div>
<div><span style="font-family:monospace"> }</span><br>
</div>
</div>
</blockquote>
<p>Can further be simplified to something like:<br>
</p>
<div><span style="font-family:monospace">
multiLineStringGeometry(const OGRGeometry* poGeometry)<br>
{<br>
for (const OGRLineString* line:
poGeometry->toMultiLineString())<br>
{<br>
// do whatever with that LineString<br>
}</span></div>
<span style="font-family:monospace"> }</span>
<p></p>
<blockquote type="cite"
cite="mid:CADRrdKvRJvfVdvWsXygz23w7vUeuxcdi3Vw9hLgBhpt0opRTeA@mail.gmail.com"><br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Mon, 16 Oct 2023 at 12:14,
Roland Baviere via gdal-dev <<a
href="mailto:gdal-dev@lists.osgeo.org"
moz-do-not-send="true" class="moz-txt-link-freetext">gdal-dev@lists.osgeo.org</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">Hi all,
<div><br>
</div>
<div> I hope this e-mel finds you well.</div>
<div><br>
</div>
<div>I am trying to read a shapefile layer from OGR from a
C++ application following the tutorial found here: <a
href="https://gdal.org/tutorials/vector_api_tut.html#reading-from-ogr"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://gdal.org/tutorials/vector_api_tut.html#reading-from-ogr</a></div>
<div><br>
</div>
<div>We have difficulties with a layer containing PolyLines
with several parts.</div>
<div><br>
</div>
<div>The pre-existing code works fine for polylines having a
unique part.</div>
<div><br>
</div>
<div>Do you have any example or advice to help me implement
a version that works for polylines containing several
parts. My intention is to display each shape on a map, so
I need to retrieve the coordinates of points and draw
segment between points when relevant.</div>
<div><br>
</div>
<div>Thanks a lot for your help.</div>
<div><br>
</div>
<div>Kind regards,</div>
<div><br>
</div>
<div>Roland</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>//// CODE THAT WORKS for "simple" polylines but fails
when dealiing with a polyline containing several parts</div>
<div> </div>
<div>int o = 0;<br>
</div>
<div> for(auto y :
poGeometry->toLineString()) {<br>
if (o == 0) {<br>
line.mInCoord =
QGeoCoordinate(y.getX(), y.getY());<br>
} else if (o ==
(poGeometry->toLineString()->getNumPoints() - 1)) {<br>
line.mOutCoord =
QGeoCoordinate(y.getX(), y.getY());<br>
} else {<br>
line.mPath.addCoordinate(QGeoCoordinate(y.getX(),
y.getY()));<br>
}<br>
qDebug() << o;<br>
o++;<br>
}<br>
</div>
<div><br>
</div>
</div>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote>
</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>