<div>Dear Mateusz Łoskot,</div>
<div>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.
</div>
<div> </div>
<div>Best Regards,</div>
<div>N.Vidhiyadharan<br> </div>
<div>
<p>#include "stdafx.h"<br>#include "ogrsf_frmts.h"</p>
<p><br>int main()</p>
<p>{</p>
<p> OGRRegisterAll();<br> OGRDataSource *poDS;<br> poDS = OGRSFDriverRegistrar::Open( "F:\\india\\india_ds.shp", FALSE );<br> if( poDS == NULL )<br> {<br> printf( "Open failed.\n%s" );
<br> exit( 1 );<br> }</p>
<p> OGRLayer *poLayer;<br> poLayer = poDS->GetLayerByName( "india_ds" );<br> OGRFeature *poFeature;<br> poLayer->ResetReading();<br> if (NULL == poLayer)<br> {<br> printf("Layer not found\n");
<br> OGRDataSource::DestroyDataSource(poDS);<br> return -1;<br> }<br> while( (poFeature = poLayer->GetNextFeature()) != NULL )<br> {<br> OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();<br> int iField;
</p>
<p> for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )<br> {<br> OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );</p>
<p> if( poFieldDefn->GetType() == OFTInteger )<br> printf( "%d,", poFeature->GetFieldAsInteger( iField ) );<br> else if( poFieldDefn->GetType() == OFTReal )<br> printf( "%.3f,", poFeature->GetFieldAsDouble(iField) );
<br> else if( poFieldDefn->GetType() == OFTString )<br> printf( "%s,", poFeature->GetFieldAsString(iField) );<br> else<br> printf( "%s,", poFeature->GetFieldAsString(iField) );
<br> }</p>
<p> OGRGeometry *poGeometry;<br> poGeometry = poFeature->GetGeometryRef();<br> <br> if( poGeometry != NULL <br> && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )<br>
{<br> OGRPoint *poPoint = (OGRPoint *) poGeometry;</p>
<p> printf( "%.3f,%.3f\n", poPoint->getX(), poPoint->getY() );<br> }<br> else<br> {<br> printf( "no point geometry\n" );<br> }<br> <br> <br> if( poGeometry != NULL
<br> && wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon )<br> {<br> OGRPolygon *poPolygon = (OGRPolygon *)poGeometry ;<br> OGRLinearRing *poLinearRing ;<br> poLinearRing = poPolygon->getExteriorRing();
<br> OGRPoint *poPoint = (OGRPoint *) poGeometry;<br> <br> int i2 ;<br> int i3 = poLinearRing->getNumPoints();<br> for(i2=0;i2<i3;i2++){<br> poLinearRing->getPoint(i2,poPoint);<br> printf( "%.3f,%.3f\n", poPoint->getX(), poPoint->getY() );
<br> }<br> }<br> else<br> {<br> printf( "no polygon geometry\n" );<br> }</p>
<p> //OGRFeature::DestroyFeature( poFeature ); <br> }<br> OGRFeature::DestroyFeature( poFeature );<br> OGRDataSource::DestroyDataSource( poDS );<br> return 0;<br>}</p></div>