I want to find out the geometry column and then want to export the geometry to WKB format from a shapefile. I wrote a code in C to find the geometry column. But a run-time error occurred. Can you please explain?
#include <stdio.h>
#include <stdlib.h>
#include <ogr_api.h>
#include <cpl_conv.h>
#include <cpl_port.h>
#include <gdal.h>
#include <string.h>
#include <gdal_utils.h>
#include <cpl_progress.h>
#include <cpl_minixml.h>
#include <ogr_core.h>
int main()
{
char path1[200],filename1[]="/1.shp";
GDALDatasetH inShapeDS;
OGRLayerH inShapeLayer;
OGRFeatureH inShapeFeature;
GDALAllRegister();
getcwd(path1, sizeof(path1));
strcat(path1,filename1);
inShapeDS = GDALOpenEx(path1, GDAL_OF_VECTOR, NULL, NULL, NULL );
if( inShapeDS == NULL )
{
printf( "Open failed.\n" );
exit( 1 );
}
inShapeLayer = GDALDatasetGetLayerByName(inShapeDS, path1);
printf("number of layers:%d\n",GDALDatasetGetLayerCount(inShapeDS));
printf("geom col name:%s",OGR_L_GetGeometryColumn(inShapeLayer));
GDALClose(inShapeDS);
return 0;
}
Error:
number of layers:1
ERROR 10: Pointer 'hLayer' is NULL in 'OGR_L_GetGeometryColumn'.
geom col name:(null)
inShapeLayer
is null?