[QGIS-Developer] QGIS/OGR: FeatureIds reassigned on write to data provider?

Even Rouault even.rouault at spatialys.com
Wed Jul 5 03:18:04 PDT 2017


On mercredi 5 juillet 2017 12:04:04 CEST Sandro Mani wrote:
> On 05.07.2017 11:30, Even Rouault wrote:
> > My feeling is that, for good or worse, they are definitely people
> > wanting to have QGIS and "put here the name of your favorite
> > proprietary GIS software" running at the same time, and possibly on
> > the same datasets. This is apparently important in migration scenarios
> > where people aren't ready yet to jump completely to QGIS. That said,
> > this is also tricky to do in a reliable way.
> 
> Could ogr expose oldId -> newId information which the qgsogrprovider
> would then emit as a signal when the layer is repacked? I don't mean a
> persistent mapping, but just for the single repack operation.

That could potentially be done using the current OGR API. Basically in pseudo code, to 
execute before executing REPACK

OGR_L_ResetReading(layer)
char** ignored_fields = CSLAddString(NULL,  "OGR_GEOMETRY" );
OGR_L_SetIgnoredFields( layer, ignored_fields); // for performance.
CSLDestroy(ignored_fields);
OGR_L_SetAttributeFilter( layer, NULL )
OGR_L_SetSpatialFilter( layer, NULL )
std::map<GIntBig, GIntBig> mapOldIdToNewId;
GIntBig newId = 0;
while( feature = OGR_L_GetNextFeature(layer) )
{
    mapOldIdToNewId[OGR_F_GetFID(feature)] = newId;
    newId ++;
    OGR_F_destroy(feature);
}
OGR_L_SetIgnoredFields( layer, NULL );

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170705/18d80fce/attachment-0001.html>


More information about the QGIS-Developer mailing list