Would you mind reading the "OGR C++ API Read/Write Tutorial" available on http://gdal.org/ogr/ogr_apitut.html ? The answer is in the first code snippet ;-)
Le Wednesday 03 March 2010 21:43:49 deadpickle, vous avez écrit : > I have finally compiled my C program and tried running it for the > first time. When I ran the file I got the error: > [t...@updraft ~/Programs]$ ./gdal_test_convert > ERROR 10: Pointer 'hDriver' is NULL in 'OGR_Dr_CreateDataSource'. > I'm trying to load the ESRI Shapefile driver. When I compiled it I > linked it to the libgdal.a library. Is there something I'm missing? > > #include "ogr_api.h" > #include "ogr_srs_api.h" > #include "stdio.h" > > int main() > { > //~ variable declaration > const char *name = "testc.shp", *dir = "C:\\Users\\deadpickle\\Desktop > \\case study\\verify\\"; > char *source, *target; > const char *sprj = "+proj=lcc +lat_1=33.000000 +lat_2=45.000000 > +lat_0=39.000000 +lon_0=-96.000000 +x_0=0.0 +y_0=0.0 +datum=NAD83"; > const char *tprj = "WGS84"; > char c[100]; > OGRSFDriverH driver; > OGRDataSourceH ds; > OGRCoordinateTransformationH ctrans; > OGRLayerH layer; > OGRFieldDefnH fieldDefn; > OGRGeometryH line; > OGRFeatureDefnH featureDefn; > OGRFeatureH feature; > FILE *file; > > //~ working directory > chdir(dir); > > //~ get driver and create ds > driver = OGRGetDriverByName("ESRI Shapefile"); > ds = OGR_Dr_CreateDataSource(driver, "testc.shp", NULL); > > //~ create spatrefs and trans > OSRNewSpatialReference(source); > OSRNewSpatialReference(target); > OSRSetFromUserInput(source, sprj); > OSRSetFromUserInput(target, tprj); > ctrans = OCTNewCoordinateTransformation(target, source); > > //~ create the layer > layer = OGR_DS_CreateLayer(ds, "test", source, wkbMultiLineString, > NULL); > > //~ add an id field > fieldDefn = OGR_Fld_Create("id", OFTInteger); > OGR_L_CreateField(layer, fieldDefn, FALSE); > > //~ create geometry > line = OGR_G_CreateGeometry(wkbMultiLineString); > > //~ layer def and create feature > featureDefn = OGR_L_GetLayerDefn(layer); > feature = OGR_F_Create(featureDefn); > > //~ open file > file = fopen("2006track.csv","r"); > > if(file==NULL) { > printf("Error: can't open file.\n"); > /* fclose(file); DON'T PASS A NULL POINTER TO fclose !! */ > return 1; > } > else { > printf("File opened successfully. Contents:\n\n"); > > while(fgets(c, 100, file)!=NULL) { > /* keep looping until NULL pointer... */ > printf("String: %s", c); > /* print the file one line at a time */ > } > > printf("\n\nNow closing file...\n"); > } > > //~ close file > fclose(file); > } > _______________________________________________ > gdal-dev mailing list > gdal-dev@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/gdal-dev _______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev