[gdal-dev] to store a shapeFile with the following code getting problem assigning goemetries in translateLayer Function

SIVA RAMA KRISHNA s.r.kriishna at gmail.com
Fri Jun 15 01:43:10 PDT 2012


#include "main.h"#include "ogrsf_frmts.h"#include "ogr_p.h"#include
"cpl_conv.h"#include "cpl_string.h"#include "ogr_api.h"#include
"gdal.h"static int TranslateLayer(OGRLayer
*poPassedLayer,OGRDataSource *ODS,char *pszNewLayerName,int
eGType);int main( ){     const char  *pszFormat = "ESRI Shapefile";
 const char  *pszDataSource ="india_ds.shp";     const char
*pszDestDataSource = "out.shp";     char *pszNewLayerName=NULL;
OGRLayer        *poLayer;     OGRDataSource       *poDS;
OGRDataSource       *poODS=NULL;      const char *pszDriverName =
"ESRI Shapefile";         OGRSFDriver *poDriver;
OGRRegisterAll();         poDriver =
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(
    pszDriverName );         if( poDriver == NULL )         {
   printf( "%s driver not available.\n", pszDriverName );
exit( 1 );         }         poODS = poDriver->*CreateDataSource*(
"out.shp", NULL );         if( poODS == NULL )         {
printf( "Creation of output file failed.\n" );             exit( 1 );
       }         poDS = poDriver->*Open*( "india_ds.shp" );
poLayer=poDS->*GetLayerByName*("india_ds");         if( poDS == NULL )
            {                 printf( "Open failed.\n" );
   exit( 1 );             }          int nLayerCount;
OGRLayer** papoLayers = NULL;           nLayerCount =
poDS->*GetLayerCount*();                printf("\n %d",nLayerCount);
             papoLayers = (OGRLayer**)CPLMalloc(sizeof(OGRLayer*) *
nLayerCount);                for( int iLayer = 0;
iLayer < nLayerCount;                     iLayer++ )                {
                    poLayer = poDS->*GetLayer*(iLayer);
      papoLayers[iLayer] = poLayer;                }
pszNewLayerName = CPLStrdup(CPLGetBasename(pszDestDataSource));
    printf("%s",pszNewLayerName);             printf("\n
%d",poLayer->*GetFeatureCount*());            int eGType=5;
for( int iLayer = 0;                iLayer < nLayerCount;
  iLayer++ )            {                 OGRLayer        *poLayer =
papoLayers[iLayer];                 if (poLayer == NULL)
     continue;                  OGRLayer* poPassedLayer = poLayer;
             if( !TranslateLayer(  poPassedLayer,
poODS,pszNewLayerName, eGType));                      {
         exit(1);                       }            }   return
0;}static int TranslateLayer(OGRLayer  *poSrcLayer,OGRDataSource
*poDstDS,char *pszNewLayerName,int  eGType)   {        OGRLayer
*poDstLayer;        OGRFeatureDefn *poSrcFDefn;        OGRFeatureDefn
*poDstFDefn = NULL;        OGRSpatialReference *poOutputSRS;
poSrcFDefn = poSrcLayer->*GetLayerDefn*();        poOutputSRS =
poSrcLayer->*GetSpatialRef*();        poDstLayer =
poDstDS->*GetLayerByName*(pszNewLayerName);         poDstLayer =
poDstDS->*CreateLayer*( pszNewLayerName, poOutputSRS,
                             (OGRwkbGeometryType) eGType);
poDstLayer->*SetStyleTable*( poSrcLayer->*GetStyleTable* () );
 int         nSrcFieldCount = poSrcFDefn->GetFieldCount();
printf("%d",nSrcFieldCount );          poDstFDefn =
poDstLayer->*GetLayerDefn*();          OGRFeature  *poFeature;
printf("\n 2 %d",poSrcLayer->*GetFeatureCount*());      OGRFeature
 *poDstFeature = NULL;        poSrcLayer->*ResetReading*();
while((poFeature = poSrcLayer->*GetNextFeature*()) != NULL)
   {                     poFeature = poSrcLayer->*GetNextFeature*();
                  OGRGeometry* poSrcGeometry =
poFeature->GetGeometryRef();                     poDstFeature =
OGRFeature::CreateFeature( poDstLayer->*GetLayerDefn*() );
        poDstFeature->*SetFID*( poFeature->GetFID() );
    OGRGeometry* poDstGeometry = poDstFeature->GetGeometryRef();
              poDstFeature->SetGeometry(poSrcGeometry);             }
return 0;}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120615/1d26b94e/attachment-0001.html>


More information about the gdal-dev mailing list