Opened 16 years ago

Last modified 11 years ago

#2531 closed defect

delete feature of shape layer — at Version 2

Reported by: 27949218 Owned by: FrankW
Priority: normal Milestone:
Component: OGR_SF Version: 1.5.2
Severity: normal Keywords: OGRStyleMgr, AddStyle
Cc: Mateusz Łoskot

Description (last modified by Mateusz Łoskot)

I 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:

  • 1
    for(iFeat=0;iFeat<nFeat;iFeat++)
    {
    	int cplE = pLayer->DeleteFeature(0);
    	if(cplE==CE_None)
    	{ 
    		OGRShapeLayer* pShpLayer = (OGRShapeLayer*)pLayer;
    		cplE = pShpLayer->Repack();
    		if(cplE!=CE_None)
    		{
                printf("delete feature failed !\n");
                return false;
    		}
    	}
    }
    int nFeatRest = pLayer->GetFeatureCount();
    

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.

  • 2
    for(iFeat=nFeat-1;iFeat>=0;iFeat--)
    {
    	int cplE = pLayer->DeleteFeature(iFeat);
    	if(cplE==CE_None)
    	{ 
    		OGRShapeLayer* pShpLayer = (OGRShapeLayer*)pLayer;
    		cplE = pShpLayer->Repack();
    		if(cplE!=CE_None)
    		{
    			printf("delete feature failed !\n");
    			return false;
    		}
    	}
    }
    int nFeatRest = pLayer->GetFeatureCount();
    

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. Trace the error "Failure writing DBF record ..." into Repack():

/* -------------------------------------------------------------------- */
/*      Build a list of records to be dropped.                          */
/* -------------------------------------------------------------------- */
...
for( iShape = 0; iShape < nTotalShapeCount; iShape++ )
{
	if( DBFIsRecordDeleted( hDBF, iShape ) )//------------ERROR jumped ---------
		panRecordsToDelete[nDeleteCount++] = iShape;
}

I'm confused. Here's the minimum project example: min-projV1.4.rar

Change History (2)

comment:1 by 27949218, 16 years ago

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:

(1) for(iFeat=0;iFeat<nFeat;iFeat++)

{

int cplE = pLayer->DeleteFeature?(0); if(cplE==CE_None)

{

OGRShapeLayer* pShpLayer = (OGRShapeLayer*)pLayer; cplE = pShpLayer->Repack(); if(cplE!=CE_None) {

printf("delete feature failed !\n"); return false;

}

}

}

int nFeatRest = pLayer->GetFeatureCount?();

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.

(2) for(iFeat=nFeat-1;iFeat>=0;iFeat--)

{

int cplE = pLayer->DeleteFeature?(iFeat);

if(cplE==CE_None) {

OGRShapeLayer* pShpLayer = (OGRShapeLayer*)pLayer; cplE = pShpLayer->Repack(); if(cplE!=CE_None)

{

printf("delete feature failed !\n");

return false; }

}

}

int nFeatRest = pLayer->GetFeatureCount?();

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. Trace the error "Failure writing DBF record ..." into Repack():

/* -------------------------------------------------------------------- */ /* Build a list of records to be dropped. */ /* -------------------------------------------------------------------- */

... for( iShape = 0; iShape < nTotalShapeCount; iShape++ ) {

if( DBFIsRecordDeleted( hDBF, iShape ) )------------ERROR jumped ---------

panRecordsToDelete[nDeleteCount++] = iShape;

}

I'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

comment:2 by Mateusz Łoskot, 16 years ago

Cc: Mateusz Łoskot added
Description: modified (diff)
Keywords: deletefeature ogrshapelayer shape added; delete feature shapelayer removed
Note: See TracTickets for help on using tickets.