[Gdal-dev] OGR:GetNextFeature() throws exception in WINXP
vdharan nadra
vdharan2001 at gmail.com
Mon Mar 20 08:42:47 EST 2006
Dear Mateusz Łoskot,
Thanks for your suggestion.But I have made a mistake while pasting my code .
The actual code is as follows and it still has the problem running in XP. I
have also added the check for NULL layer as you have suggested. In XP i get
the output of "printf( "%.3f,%.3f\n", poPoint->getX(), poPoint->getY() );"
for few polygons and then the application crashes.
Best Regards,
N.Vidhiyadharan
#include "stdafx.h"
#include "ogrsf_frmts.h"
int main()
{
OGRRegisterAll();
OGRDataSource *poDS;
poDS = OGRSFDriverRegistrar::Open( "F:\\india\\india_ds.shp", FALSE );
if( poDS == NULL )
{
printf( "Open failed.\n%s" );
exit( 1 );
}
OGRLayer *poLayer;
poLayer = poDS->GetLayerByName( "india_ds" );
OGRFeature *poFeature;
poLayer->ResetReading();
if (NULL == poLayer)
{
printf("Layer not found\n");
OGRDataSource::DestroyDataSource(poDS);
return -1;
}
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
int iField;
for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
if( poFieldDefn->GetType() == OFTInteger )
printf( "%d,", poFeature->GetFieldAsInteger( iField ) );
else if( poFieldDefn->GetType() == OFTReal )
printf( "%.3f,", poFeature->GetFieldAsDouble(iField) );
else if( poFieldDefn->GetType() == OFTString )
printf( "%s,", poFeature->GetFieldAsString(iField) );
else
printf( "%s,", poFeature->GetFieldAsString(iField) );
}
OGRGeometry *poGeometry;
poGeometry = poFeature->GetGeometryRef();
if( poGeometry != NULL
&& wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )
{
OGRPoint *poPoint = (OGRPoint *) poGeometry;
printf( "%.3f,%.3f\n", poPoint->getX(), poPoint->getY() );
}
else
{
printf( "no point geometry\n" );
}
if( poGeometry != NULL
&& wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon )
{
OGRPolygon *poPolygon = (OGRPolygon *)poGeometry ;
OGRLinearRing *poLinearRing ;
poLinearRing = poPolygon->getExteriorRing();
OGRPoint *poPoint = (OGRPoint *) poGeometry;
int i2 ;
int i3 = poLinearRing->getNumPoints();
for(i2=0;i2<i3;i2++){
poLinearRing->getPoint(i2,poPoint);
printf( "%.3f,%.3f\n", poPoint->getX(), poPoint->getY() );
}
}
else
{
printf( "no polygon geometry\n" );
}
//OGRFeature::DestroyFeature( poFeature );
}
OGRFeature::DestroyFeature( poFeature );
OGRDataSource::DestroyDataSource( poDS );
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20060320/803ecb4b/attachment.html
More information about the Gdal-dev
mailing list