Shapefile Empty after OgrLayer

Description

Hi,

I was trying to create a new shapefile using OgrLayer and MW 4.9 from a Postgis connection. I was surprised to notice that the shapefile was well created, filled, recognized by Qgis after "save as" but as soon as my soft called a new postgis connection, the shapefile was emptied and not recognized anymore by qgis.

I tried with OpenFromDatabase or OpenFromQuery, same results.

The only workaround I found was to add a line :
var shpc = shp.Clone();
(I wrote that thinking I will save as and delete the clone file afterwards but it was not necessary, this line is enough to break the link with the database)

Perhaps this is not a bug and there someting I'm not used to with c#, it looks like 'shp' shapefile stays in memory even after saveAs and close and is still linked to the database, that why it looses data whan connection is closed ?

I would be very much interested if I can have a skilled explanation

Thanks,

Olivier

MapWinGIS.OgrLayer lay = new MapWinGIS.OgrLayer();
MapWinGIS.Shapefile shp = new MapWinGIS.Shapefile();

//success = lay.OpenFromDatabase(pgcnx, name, true);
success = lay.OpenFromQuery(pgcnx, "select * from " + name);
ficshp = Path.Combine(folder, ficshp);
if (success) {
success = shp.CreateNew(string.Empty, lay.ShapeType);
if (success) {
shp = lay.GetBuffer();
success = shp.SaveAs(ficshp);
var shpc = shp.Clone(); // Line added to avoid shp becoming empty
}
}
shp.Close();
lay.Close();

Environment

None

Status

Assignee

Unassigned

Reporter

Olivier LeprĂȘtre

Labels

None

Affects versions

v5.2-Planned

Priority

Medium
Configure