[Gdal-dev] error reading vector file: "points.shp"

chhavi chhavi_aggl at yahoo.co.in
Tue Dec 4 01:24:24 EST 2007


For reading "points.shp" file, i compiled the following successfully and i
gave proper paths for library and header files also but while executing it
was giving error: 

could not open "points.shp" file.

Plz help me out.
Chhavi

#include "ogrsf_frmts.h" 

int main() 

{ 
    OGRRegisterAll(); 

    OGRDataSource       *poDS; 

    poDS = OGRSFDriverRegistrar::Open( "point.shp", FALSE ); 
    if( poDS == NULL ) 
    { 
        printf( "Open failed.\n" ); 
        exit( 1 ); 
    } 

    OGRLayer  *poLayer; 

    poLayer = poDS->GetLayerByName( "point" ); 

    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,%3.f\n", poPoint->getX(), poPoint->getY() ); 
        } 
        else 
        { 
            printf( "no point geometry\n" ); 
        } 
        OGRFeature::DestroyFeature( poFeature ); 
    } 

    OGRDataSource::DestroyDataSource( poDS ); 
} 


 
-- 
View this message in context: http://www.nabble.com/error-reading-vector-file%3A-%22points.shp%22-tf4901804.html#a14041328
Sent from the GDAL - Dev mailing list archive at Nabble.com.



More information about the gdal-dev mailing list