[gdal-dev] Hangs on OGRLayer ResetReading

Even Rouault even.rouault at mines-paris.org
Sat Dec 19 16:06:29 EST 2009


Matthew,

I can't see why it would fail on ResetReading(). It should run just 
fine. The only point I've seen is that your code has memory leaks. It 
leaks each read OGRFeature and the OGRDataSource. See the full example 
on the tutorial to correctly deallocate those objects. But that doesn't 
explain your issue.

I think you'll have to use a debugger and step in to see what happens.

Do OGR command line utilities work on your shapefile ? For example, 
ogrinfo ?

Best regards,

Even

Matthew Denno a écrit :
> Hi,
>
> I was wondering if someone could help me out.  I have been working on
> a little piece of code here and seems to be stuck.  The piece is very
> close to one of the examples on the website so I would think that it
> would be right...maybe I have missed something simple.  Anyway below
> is the code.  It seems like it hangs on "poLayer->ResetReading();".
> It successfully prints out the number of features then dies.
>
> Thanks,
>
> Matt
>
> CODE:
>
> int z_shape_to_delaunay(Delaunay &dt,
>                         QString myLayerPath,
>                         bool useAnalysisMask,
>                         QString analysisMaskPath)
> {
>     qDebug("z_shape_to_delaunay");
>
>     OGRRegisterAll();
>
>     OGRDataSource       *poDS;
>
>     poDS = OGRSFDriverRegistrar::Open( myLayerPath, FALSE );
>     if( poDS == NULL )
>     {
>         qDebug( "Shapefile failed to open" );
>         exit( 1 );
>     }
>
>     OGRLayer  *poLayer;
>
>     poLayer = poDS->GetLayer( 0 );
>
>     qDebug() << "Number of Features: " << poLayer->GetFeatureCount(1);
>
>     if (poLayer = NULL)
>     {
>         qDebug( "Layer ID was out of range" );
>         exit( 1 );
>     }
>
>     OGRFeature *poFeature;
>
>     poLayer->ResetReading();
>
>     qDebug("start loop");
>
>     while( (poFeature = poLayer->GetNextFeature()) != NULL )
>     {
>         OGRGeometry *poGeometry;
>         poGeometry = poFeature->GetGeometryRef();
>
>         qDebug("in loop");
>
>         if (!poGeometry)
>         {
>             continue;
>         }
>
>         if( poGeometry != NULL && poGeometry->getGeometryType() == wkbPoint25D )
>         {
>             OGRPoint *poPoint = (OGRPoint *) poGeometry;
>             Point pt = Point(poPoint->getX(), poPoint->getY(), poPoint->getZ());
>             dt.insert(pt);
>         }
>         else
>         {
>             qDebug( "no point geometry" );
>         }
>      }
>
>     }
>     return (0);
> }
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>
>
>   




More information about the gdal-dev mailing list