Re: [gdal-dev] Reading a shapefile containing multi-parts Polyline from OGR (C++ API)

2023-10-16 Thread Roland Baviere via gdal-dev
Thanks a lot Javier. I'll test this and come back to you.

Here is a download link to the shapefile causing this issue for me:
https://filesender.renater.fr/?s=download=da2a7ff6-9755-4086-b1ed-71c6ebc72a0f



Le lun. 16 oct. 2023 à 15:21, Even Rouault  a
écrit :

>
> Le 16/10/2023 à 15:15, Javier Jimenez Shaw via gdal-dev a écrit :
>
> Do you mean a MultiLineString?
>
> This piece of code is working for me (I hope without any bug).
>
> if (wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString)
> multiLineStringGeometry(poGeometry);
> ...
> multiLineStringGeometry(OGRGeometry* poGeometry)
> {
> OGRMultiLineString* multiLine =
> dynamic_cast(poGeometry);
> int numGeometries = multiLine->getNumGeometries();
> for (int i = 0; i < numGeometries; i++)
> {
> OGRGeometry* eachGeometry =
> multiLine->getGeometryRef(i);
> OGRLineString* line =
> dynamic_cast(eachGeometry);
> // do whatever with that LineString
> }
> }
>
> Can further be simplified to something like:
> multiLineStringGeometry(const OGRGeometry* poGeometry)
> {
> for (const OGRLineString* line:
> poGeometry->toMultiLineString())
> {
> // do whatever with that LineString
> }
> }
>
>
> On Mon, 16 Oct 2023 at 12:14, Roland Baviere via gdal-dev <
> gdal-dev@lists.osgeo.org> wrote:
>
>> Hi all,
>>
>>  I hope this e-mel finds you well.
>>
>> I am trying to read a shapefile layer from OGR from a C++ application
>> following the tutorial found here:
>> https://gdal.org/tutorials/vector_api_tut.html#reading-from-ogr
>>
>> We have difficulties with a layer containing PolyLines with several parts.
>>
>> The pre-existing code works fine for polylines having a unique part.
>>
>> 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.
>>
>> Thanks a lot for your help.
>>
>> Kind regards,
>>
>> Roland
>>
>>
>>
>>  CODE THAT WORKS for "simple" polylines but fails when dealiing with
>> a polyline containing several parts
>>
>> int o = 0;
>> for(auto y : poGeometry->toLineString()) {
>> if (o == 0) {
>> line.mInCoord = QGeoCoordinate(y.getX(),
>> y.getY());
>> } else if (o ==
>> (poGeometry->toLineString()->getNumPoints() - 1)) {
>> line.mOutCoord = QGeoCoordinate(y.getX(),
>> y.getY());
>> } else {
>>
>> line.mPath.addCoordinate(QGeoCoordinate(y.getX(), y.getY()));
>> }
>> qDebug() << o;
>> o++;
>> }
>>
>> ___
>> gdal-dev mailing list
>> gdal-dev@lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
> ___
> gdal-dev mailing 
> listgdal-dev@lists.osgeo.orghttps://lists.osgeo.org/mailman/listinfo/gdal-dev
>
> -- http://www.spatialys.com
> My software is free, but my time generally not.
>
>
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Reading a shapefile containing multi-parts Polyline from OGR (C++ API)

2023-10-16 Thread Even Rouault via gdal-dev


Le 16/10/2023 à 15:15, Javier Jimenez Shaw via gdal-dev a écrit :

Do you mean a MultiLineString?

This piece of code is working for me (I hope without any bug).

if (wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString)
multiLineStringGeometry(poGeometry);
...
multiLineStringGeometry(OGRGeometry* poGeometry)
            {
                OGRMultiLineString* multiLine = 
dynamic_cast(poGeometry);

                int numGeometries = multiLine->getNumGeometries();
                for (int i = 0; i < numGeometries; i++)
                {
                    OGRGeometry* eachGeometry = 
multiLine->getGeometryRef(i);
                    OGRLineString* line = 
dynamic_cast(eachGeometry);

                    // do whatever with that LineString
                }
            }


Can further be simplified to something like:

multiLineStringGeometry(const OGRGeometry* poGeometry)
            {
                for (const OGRLineString* line: 
poGeometry->toMultiLineString())

                {
                    // do whatever with that LineString
                }
            }



On Mon, 16 Oct 2023 at 12:14, Roland Baviere via gdal-dev 
 wrote:


Hi all,

 I hope this e-mel finds you well.

I am trying to read a shapefile layer from OGR from a C++
application following the tutorial found here:
https://gdal.org/tutorials/vector_api_tut.html#reading-from-ogr

We have difficulties with a layer containing PolyLines with
several parts.

The pre-existing code works fine for polylines having a unique part.

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.

Thanks a lot for your help.

Kind regards,

Roland



 CODE THAT WORKS for "simple" polylines but fails when
dealiing with a polyline containing several parts
int o = 0;
                        for(auto y : poGeometry->toLineString()) {
                            if (o == 0) {
                                line.mInCoord =
QGeoCoordinate(y.getX(), y.getY());
                            } else if (o ==
(poGeometry->toLineString()->getNumPoints() - 1)) {
                                line.mOutCoord =
QGeoCoordinate(y.getX(), y.getY());
                            } else {
line.mPath.addCoordinate(QGeoCoordinate(y.getX(), y.getY()));
                            }
                            qDebug() << o;
                            o++;
                        }

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


--
http://www.spatialys.com
My software is free, but my time generally not.
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Reading a shapefile containing multi-parts Polyline from OGR (C++ API)

2023-10-16 Thread Javier Jimenez Shaw via gdal-dev
Do you mean a MultiLineString?

This piece of code is working for me (I hope without any bug).

if (wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString)
multiLineStringGeometry(poGeometry);
...
multiLineStringGeometry(OGRGeometry* poGeometry)
{
OGRMultiLineString* multiLine =
dynamic_cast(poGeometry);
int numGeometries = multiLine->getNumGeometries();
for (int i = 0; i < numGeometries; i++)
{
OGRGeometry* eachGeometry =
multiLine->getGeometryRef(i);
OGRLineString* line =
dynamic_cast(eachGeometry);
// do whatever with that LineString
}
}

On Mon, 16 Oct 2023 at 12:14, Roland Baviere via gdal-dev <
gdal-dev@lists.osgeo.org> wrote:

> Hi all,
>
>  I hope this e-mel finds you well.
>
> I am trying to read a shapefile layer from OGR from a C++ application
> following the tutorial found here:
> https://gdal.org/tutorials/vector_api_tut.html#reading-from-ogr
>
> We have difficulties with a layer containing PolyLines with several parts.
>
> The pre-existing code works fine for polylines having a unique part.
>
> 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.
>
> Thanks a lot for your help.
>
> Kind regards,
>
> Roland
>
>
>
>  CODE THAT WORKS for "simple" polylines but fails when dealiing with a
> polyline containing several parts
>
> int o = 0;
> for(auto y : poGeometry->toLineString()) {
> if (o == 0) {
> line.mInCoord = QGeoCoordinate(y.getX(),
> y.getY());
> } else if (o ==
> (poGeometry->toLineString()->getNumPoints() - 1)) {
> line.mOutCoord = QGeoCoordinate(y.getX(),
> y.getY());
> } else {
>
> line.mPath.addCoordinate(QGeoCoordinate(y.getX(), y.getY()));
> }
> qDebug() << o;
> o++;
> }
>
> ___
> gdal-dev mailing list
> gdal-dev@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


[gdal-dev] Reading a shapefile containing multi-parts Polyline from OGR (C++ API)

2023-10-16 Thread Roland Baviere via gdal-dev
Hi all,

 I hope this e-mel finds you well.

I am trying to read a shapefile layer from OGR from a C++ application
following the tutorial found here:
https://gdal.org/tutorials/vector_api_tut.html#reading-from-ogr

We have difficulties with a layer containing PolyLines with several parts.

The pre-existing code works fine for polylines having a unique part.

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.

Thanks a lot for your help.

Kind regards,

Roland



 CODE THAT WORKS for "simple" polylines but fails when dealiing with a
polyline containing several parts

int o = 0;
for(auto y : poGeometry->toLineString()) {
if (o == 0) {
line.mInCoord = QGeoCoordinate(y.getX(),
y.getY());
} else if (o ==
(poGeometry->toLineString()->getNumPoints() - 1)) {
line.mOutCoord = QGeoCoordinate(y.getX(),
y.getY());
} else {

line.mPath.addCoordinate(QGeoCoordinate(y.getX(), y.getY()));
}
qDebug() << o;
o++;
}
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev