#2531 closed defect (fixed)
OGRStyleMgr::AddStyle() can't work in V1.5.2
Reported by: | 27949218 | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | OGR_SF | Version: | 1.5.2 |
Severity: | normal | Keywords: | OGRStyleMgr, AddStyle |
Cc: | Mateusz Łoskot |
Description (last modified by )
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 (9)
comment:1 by , 16 years ago
follow-up: 3 comment:2 by , 16 years ago
Cc: | added |
---|---|
Description: | modified (diff) |
Keywords: | deletefeature ogrshapelayer shape added; delete feature shapelayer removed |
follow-up: 4 comment:3 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Type: | defect → task |
Replying to mloskot: The URL in the updating comment stores the example project. Before download you need to input this code:74cb36d4. I'm sorry for the rough operation of my first comment. Thank you for update.
comment:4 by , 16 years ago
Keywords: | OGRStyleMgr AddStyle added |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Summary: | delete feature of shape layer → delete feature of shape layer, OGRStyleMgr |
Type: | task → defect |
Version: | 1.4.1 → 1.5.2 |
Replying to 27949218:
Replying to mloskot: The URL in the updating comment stores the example project. Before download you need to input this code:74cb36d4. I'm sorry for the rough operation of my first comment. Thank you for update.
The error still exists in version V1.4.1. I try to update my program with version from 1.4.1 to 1.5.2, and use the OGRDatasource::ExecuteSQL() running "repack layer_name" to delete features, it works well.But i get another question: OGRStyleMgr::AddStyle() can't work in V1.5.2, it saves unexpected style string instead of user provided to *.tbl. I checked the style works smoothly in Ver1.4.1. I'm afraid there's a bug of OGRStyleMgr in ver1.5.2, since the source i download couldn't been compiled in my computer, please check it. Thank you.
comment:5 by , 16 years ago
Keywords: | deletefeature ogrshapelayer shape removed |
---|---|
Summary: | delete feature of shape layer, OGRStyleMgr → OGRStyleMgr::AddStyle() can't work in V1.5.2 |
OK, I've tried your code on GDAL 1.5.2 and GDAL 1.6.0dev and it runs fine for version (1) and (2). I don't think it will be fixed in 1.4.X since 1.5.X is the stable branch now. So I consider this part of the ticket as resolved.
I can't really test for the OGRStyleMgr::AddStyle() issue so I only keep that as subject of that bug
comment:6 by , 16 years ago
Note that your (1) and (2) versions are very inefficient ! You should delete all the features and then compact just once. Like :
#include <stdio.h> #include <ogr_api.h> #include <cpl_error.h> int main(int argc, char* argv[]) { OGRRegisterAll(); OGRDataSourceH hDS = OGROpen( "uddf4322.shp", TRUE, NULL ); OGRLayerH hLayer = OGR_DS_GetLayer(hDS, 0); int nFeat = OGR_L_GetFeatureCount(hLayer, FALSE); printf("nFeat = %d\n", nFeat); int iFeat; for(iFeat=0;iFeat < nFeat;iFeat++) { int cplE = OGR_L_DeleteFeature(hLayer, iFeat); if(cplE !=CE_None) { fprintf(stderr, "error while deleting %d\n", iFeat); } } OGR_DS_ExecuteSQL(hDS, "REPACK uddf4322", NULL, NULL); nFeat = OGR_L_GetFeatureCount(hLayer, FALSE); printf("nFeat = %d\n", nFeat); OGR_DS_Destroy(hDS); return 0; }
comment:7 by , 16 years ago
Owner: | removed |
---|---|
Status: | reopened → new |
comment:8 by , 15 years ago
Milestone: | → 1.5.5 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
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