[Gdal-dev] Struggling with OGR writing model

Andrea Aime aaime at openplans.org
Sun Feb 18 11:16:44 EST 2007


Hi all,
as some of you may know, I'm trying to make a Geotools DataStore 
wrapping the OGR library.
I'm having troubles mapping gt2 ways of doing things with OGR ones.
In Geotools, writing model is basically a streaming update/delete that 
turns to append once you get to the end of the original file, that is:
1 open a writer against a layer
2 ask for next feature
3 update and write the returned feature, or delete it
4 (goto 2)
When stepping to the next feature returns "false" (that is, end of 
original file) the writer turns in append mode, that is, allows to add 
new features to the layer.

Now, depending on the actual storage, this is implemented by:
a) using native update/delete capabilities (think dbms or shapefiles),
b) by writing a new separate layer, and when the writer ends its work, 
by removing the original and renaming the new temporary one to the old 
layer name.

Looking at the OGR api, it seems I can use technique a) when the layer 
supports random updates and deletes.
Yet, I don't see a general way to use b). Afaics, I can  create a new 
temporary layer with a different name, write on it, but when writing 
finishes, how can I rename the temporary layer to the old name?
The only way seems to wipe out the old layer, recreate it empty,
and copy back records from the temporary one: a quite inefficient
solution for just a rename :-)

Did I overlook a simpler way?
Cheers
Andrea



More information about the Gdal-dev mailing list