Changes between Initial Version and Version 2 of Ticket #2531


Ignore:
Timestamp:
Aug 15, 2008, 4:17:03 AM (16 years ago)
Author:
Mateusz Łoskot
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #2531

    • Property Cc Mateusz Łoskot added
    • Property Keywords deletefeature ogrshapelayer shape added; delete feature shapelayer removed
  • Ticket #2531 – Description

    initial v2  
    1  i try to delete features from a set of shape file, sometimes get error. I use this version of ogrshapelayer.cpp: http://trac.osgeo.org/gdal/changeset/10969 . Delete feature in two ways would get different result, and both don't work smoothly:
    2 (1)  for(iFeat=0;iFeat<nFeat;iFeat++)
    3    {
    4         int cplE = pLayer->DeleteFeature(0);
    5         if(cplE==CE_None)
    6        {
    7          OGRShapeLayer* pShpLayer = (OGRShapeLayer*)pLayer;
    8          cplE = pShpLayer->Repack();
    9          if(cplE!=CE_None)
    10          {
     1I try to delete features from a set of shape file, sometimes get error. I use this version of ogrshapelayer.cpp (r10969). Delete feature in two ways would get different result, and both don't work smoothly:
     2
     3 * 1
     4{{{
     5for(iFeat=0;iFeat<nFeat;iFeat++)
     6{
     7        int cplE = pLayer->DeleteFeature(0);
     8        if(cplE==CE_None)
     9        {
     10                OGRShapeLayer* pShpLayer = (OGRShapeLayer*)pLayer;
     11                cplE = pShpLayer->Repack();
     12                if(cplE!=CE_None)
     13                {
    1114            printf("delete feature failed !\n");
    1215            return false;
    13          }
    14       }
    15   }
    16    int nFeatRest = pLayer->GetFeatureCount();
     16                }
     17        }
     18}
     19int nFeatRest = pLayer->GetFeatureCount();
     20}}}
    1721 
    18     These codes could delete each feature with returned value CE_None, and  at the end nFeatRest=0. But when ran to pShpLayer->Repack()  second, the error occurs: "Failure writing DBF record 0", it jumped untill all features were deleted.
    19  
    20 (2)  for(iFeat=nFeat-1;iFeat>=0;iFeat--)
    21  {
    22       int cplE = pLayer->DeleteFeature(iFeat);
    23      if(cplE==CE_None)
    24      {
    25            OGRShapeLayer* pShpLayer = (OGRShapeLayer*)pLayer;
    26            cplE = pShpLayer->Repack();
    27            if(cplE!=CE_None)
    28           {
    29            printf("delete feature failed !\n");
    30           return false;
    31           }
    32      }
    33  }
    34     int nFeatRest = pLayer->GetFeatureCount();
    35  
    36     These codes could delete each feature with returned value CE_None, but at the end nFeatRest>0 and nFeatRest<nFeat, some features were NOT deleted yet!   Same as (1), when ran to pShpLayer->Repack()  second, the error occurs: "Failure writing DBF record iFeat", it jumped untill all features were deleted.
    37     Trace the error  "Failure writing DBF record ..." into Repack():
    38    /* -------------------------------------------------------------------- */
    39    /*      Build a list of records to be dropped.                          */
    40    /* -------------------------------------------------------------------- */
    41     ...
    42     for( iShape = 0; iShape < nTotalShapeCount; iShape++ )
    43     {
    44         if( DBFIsRecordDeleted( hDBF, iShape ) )//------------ERROR jumped ---------
    45             panRecordsToDelete[nDeleteCount++] = iShape;
    46     }
     22These codes could delete each feature with returned value CE_None, and  at the end nFeatRest=0. But when ran to pShpLayer->Repack()  second, the error occurs: "Failure writing DBF record 0", it jumped untill all features were deleted.
    4723
    48    I'm confused...
    49    Here's the minimum project example:
    50 [file:///E:/ogr-demo/min-projV1.4.rar]
     24 * 2
     25{{{
     26for(iFeat=nFeat-1;iFeat>=0;iFeat--)
     27{
     28        int cplE = pLayer->DeleteFeature(iFeat);
     29        if(cplE==CE_None)
     30        {
     31                OGRShapeLayer* pShpLayer = (OGRShapeLayer*)pLayer;
     32                cplE = pShpLayer->Repack();
     33                if(cplE!=CE_None)
     34                {
     35                        printf("delete feature failed !\n");
     36                        return false;
     37                }
     38        }
     39}
     40int nFeatRest = pLayer->GetFeatureCount();
     41}}}
     42
     43These codes could delete each feature with returned value CE_None, but at the end nFeatRest>0 and nFeatRest<nFeat, some features were NOT deleted yet! Same as (1), when ran to pShpLayer->Repack()  second, the error occurs: "Failure writing DBF record iFeat", it jumped untill all features were deleted. Trace the error  "Failure writing DBF record ..." into Repack():
     44
     45{{{
     46/* -------------------------------------------------------------------- */
     47/*      Build a list of records to be dropped.                          */
     48/* -------------------------------------------------------------------- */
     49...
     50for( iShape = 0; iShape < nTotalShapeCount; iShape++ )
     51{
     52        if( DBFIsRecordDeleted( hDBF, iShape ) )//------------ERROR jumped ---------
     53                panRecordsToDelete[nDeleteCount++] = iShape;
     54}
     55}}}
     56
     57I'm confused. Here's the minimum project example: [http://xianexs.mail.qq.com/cgi-bin/downloadfilepart/svrid240/min-projV1.4.rar?svrid=240&fid=0005cdc7f9832359f9e4eb3efc621a7a0b6aed38b0648f15&&txf_fid=0f757a1c67e9d00af86bb29f362dca856bb234a4&&txf_sid=326af806a32d836c8f8ca536069d59f48fb8309e min-projV1.4.rar]