[gdal-dev] Hangs on OGRLayer ResetReading

Matthew Denno mgdenno at gmail.com
Sun Dec 20 00:10:56 EST 2009


Hi Even,

Thanks for your reply and for pointing out my memory leak.

I tried ogrinfo as you suggested and it seems to work fine.  Also, I
am able to output the number of features from my OGRLayer so I know
that it is accessing the file ok...I think anyway.

I have tried to use a debugger but don't seem to be getting anywhere
with that.  When I try and step into the ResetReading a few messages
go by too fast to read then it stops at " Stopped: "signal-received"
".  If I try to step over it I also does something similar.  I am
using the QtCreator IDE.  I guess I need to find out if there is a way
to read all the messages that are generated.

Thanks again,

Matt

On Sat, Dec 19, 2009 at 4:06 PM, Even Rouault
<even.rouault at mines-paris.org> wrote:
> 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