Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#1633 closed enhancement (invalid)

add OGRLayer::CreateFeatures() for "bulk-insertion" of features

Reported by: Kosta Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords:
Cc:

Description

I would like to add this new method to OGRLayer:

virtual OGRErr OGRLayer::CreateFeatures(
    OGRFeature** poFeatures,
    int iFeatureCount,
    int bUseFIDs
);

with a default implementation like this:

OGRErr OGRLayer::CreateFeatures(
    OGRFeature **poFeatures,
    int iFeatureCount,
    int bUseFIDs
) {
    for(int i = 0; i < iFeatureCount; ++i) {
        OGRFeature* poFeature = poFeatures[i];
        assert(poFeature);
        long iStoreFID = poFeature->GetFID();
        if(!bUseFIDs) poFeature->SetFID(OGRNullFID);
        OGRErr error = CreateFeature( poFeature );
        if(!bUseFIDs) poFeature->SetFID(iStoreFID);
        if( error != OGRERR_NONE ) return error;
    }
    return OGRERR_NONE;
}

The flag bUseFIDs indicate, if the FIDs of the provided features should be used for insertion (bUseFIDs==true) or if they should be ignored (bUseFIDs==false), thus generating new FIDs for the features during insertion.

This enables driver specific optimizations for insertions of many features at once.

Based on this simple interface enhancement I was able to increase the insertion rate for the MySQL driver from 40 features/second to 250-700 features/second; tested with insertions of 1.000 - 80.000 features...

Change History (3)

comment:1 by warmerdam, 17 years ago

Resolution: invalid
Status: newclosed

Changes to the OGR API generally have to be proposed as an RFC. See:

http://trac.osgeo.org/gdal/wiki/RfcList

for examples, and this for the process by which they are adopted:

http://trac.osgeo.org/gdal/wiki/rfc1_pmc

Note that drivers are supposed to preserve the FID if they can, and if they can't then they don't. So I don't see a purpose in adding a preserve fid option.

comment:2 by Kosta, 17 years ago

OK, I created an RFC here: RFC #13 :-)

comment:3 by warmerdam, 17 years ago

Kosta,

Don't forget to email gdal-dev announcing that it is open for discussion, and after potentially incorporating some suggestions from feedback, announce when you want voting to start.

Note: See TracTickets for help on using tickets.