[Gdal-dev] OGR:GetNextFeature() throws exception in WINXP
Vidhiyadharan Nadarajah
vdharan2001 at gmail.com
Thu Mar 16 19:41:42 EST 2006
Hi,
Iam a begineer in this field. I have been using OGR for the past 6 months.
I have built a windows application (using VC++) which is runing perfectly
fine in WIN2K.
I have built this application based on the sample provided in the OGR
Tutorial (http://gdal.maptools.org/ogr/ogr_apitut.html). Reading a point
layer is alone described in the tutorial and i have added some code for
reading the polygon layer.
My problem is the same application crashes in WinXP. The function
"poLayer->GetNextFeature()" throws an exception in winXP.Iam unable to find
the exact exception.
I have compiled GDAL1.3.0 and PROJ4 and linking the DLL in my application.
Please find below the piece of code that Iam using. Please help me to find
out the mistake that Iam doing. I can also send the VC++ workspace and the
shape file, if it is needed for finding out the problem.
#include "stdafx.h"
#include "ogrsf_frmts.h"
int main()
{
OGRRegisterAll();
OGRDataSource *poDS;
poDS = OGRSFDriverRegistrar::Open( "C:\ind.shp", FALSE );
if( poDS == NULL )
{
printf( "Open failed.\n%s" );
exit( 1 );
}
OGRLayer *poLayer;
poLayer = poDS->GetLayerByName( "india_ds" );
OGRFeature *poFeature;
poLayer->ResetReading();
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;
}
Best Regards,
N.Vidhiyadharan
--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.12/266 - Release Date: 21/02/2006
More information about the Gdal-dev
mailing list