[gdal-dev] OGR API for ESRI Shapefile writer
Hi All, I was trying to create a shapefile using the code below: It looks like though the fieldnames are getting created but the values (I tried just one row) are not getting created: OGRRegisterAll(); OGRSFDriver *poDriver = OGRSFDriverRegistrar::GetRegistrar()-GetDriverByName(ESRI Shapefile); OGRDataSource *poDS = poDriver-CreateDataSource(point_out.shp, 0); OGRLayer *poLayer = poDS-CreateLayer(point_out, 0, wkbPoint, 0); OGRFieldDefn oField1(Longitude, OFTReal); OGRFieldDefn oField2(Latitude, OFTReal); OGRFieldDefn oField3(Speed, OFTReal); if(poLayer-CreateField(oField1) != OGRERR_NONE) { std::cout creation of Longitude failed std::endl; exit(1); } if(poLayer-CreateField(oField2) != OGRERR_NONE) { std::cout creation of Latitude failed std::endl; exit(1); } if(poLayer-CreateField(oField3) != OGRERR_NONE) { std::cout creation of Speed failed std::endl; exit(1); } OGRFeature *poFeature = OGRFeature::CreateFeature( poLayer-GetLayerDefn() ); poFeature-SetField(Longitude, 1.1); poFeature-SetField(Latitude, 2.2); poFeature-SetField(Speed, 3.3); if( poLayer-CreateFeature( poFeature ) != OGRERR_NONE ) { std::cout Failed to create feature in shapefile std::endl; exit( 1 ); } OGRFeature::DestroyFeature( poFeature ); Am I missing something basic here ? Thanks, Chandra ** This communication contains information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s), disclosure, copying, distribution, or other use of, or action taken or omitted to be taken in reliance upon, this communication or the information in it is prohibited and maybe unlawful. If you have received this communication in error please notify the sender by return email, delete it from your system and destroy any copies. ** ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] OGR API for ESRI Shapefile writer
Almost perfect, but you've made a classical error : you've just forgotten to properly close the dataset with OGRDataSource::DestroyDataSource( poDS ); Quoting http://gdal.org/ogr/ogr_apitut.html: Finally we need to close down the datasource in order to ensure headers are written out in an orderly way and all resources are recovered. I'll mention it in the doc of OGRSFDriver::CreateDataSource() for the sake of completeness. Le Monday 29 June 2009 19:54:45 Chandra Shekhar Kumar, vous avez écrit : OGRRegisterAll(); OGRSFDriver *poDriver = OGRSFDriverRegistrar::GetRegistrar()-GetDriverByName(ESRI Shapefile); OGRDataSource *poDS = poDriver-CreateDataSource(point_out.shp, 0); OGRLayer *poLayer = poDS-CreateLayer(point_out, 0, wkbPoint, 0); OGRFieldDefn oField1(Longitude, OFTReal); OGRFieldDefn oField2(Latitude, OFTReal); OGRFieldDefn oField3(Speed, OFTReal); if(poLayer-CreateField(oField1) != OGRERR_NONE) { std::cout creation of Longitude failed std::endl; exit(1); } if(poLayer-CreateField(oField2) != OGRERR_NONE) { std::cout creation of Latitude failed std::endl; exit(1); } if(poLayer-CreateField(oField3) != OGRERR_NONE) { std::cout creation of Speed failed std::endl; exit(1); } OGRFeature *poFeature = OGRFeature::CreateFeature( poLayer-GetLayerDefn() ); poFeature-SetField(Longitude, 1.1); poFeature-SetField(Latitude, 2.2); poFeature-SetField(Speed, 3.3); if( poLayer-CreateFeature( poFeature ) != OGRERR_NONE ) { std::cout Failed to create feature in shapefile std::endl; exit( 1 ); } OGRFeature::DestroyFeature( poFeature ); ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
RE: [gdal-dev] OGR API for ESRI Shapefile writer
-Original Message- From: Even Rouault [mailto:even.roua...@mines-paris.org] Almost perfect, but you've made a classical error : you've just forgotten to properly close the dataset with OGRDataSource::DestroyDataSource( poDS ); Quoting http://gdal.org/ogr/ogr_apitut.html: Finally we need to close down the datasource in order to ensure headers are written out in an orderly way and all resources are recovered. [Chandra ] It worked like a magic! It was my fault that I didn't read the tutorial completely :( though it was hardly 2-3 pages and complete in all sense. Thanks a lot Even! Regards, Chandra ** This communication contains information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s), disclosure, copying, distribution, or other use of, or action taken or omitted to be taken in reliance upon, this communication or the information in it is prohibited and maybe unlawful. If you have received this communication in error please notify the sender by return email, delete it from your system and destroy any copies. ** ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev