Skip to content

Commit

Permalink
lib/vector/Vlib: always write out topo files in update mode (#3459)
Browse files Browse the repository at this point in the history
* Vlib: always write out topo files in update mode
* delete support files only when closing
* fix pygrass Vect_close

---------

Co-authored-by: Huidae Cho <[email protected]>
  • Loading branch information
metzm and HuidaeCho committed Oct 15, 2024
1 parent def7a1a commit 4d2a3f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
1 change: 1 addition & 0 deletions lib/vector/Vlib/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ int Vect__open_old(struct Map_info *Map, const char *name, const char *mapset,
if (access(file_path, F_OK) == 0) /* fidx file exists? */
unlink(file_path);
}
Map->support_updated = TRUE;
}

return level;
Expand Down
21 changes: 8 additions & 13 deletions python/grass/pygrass/vector/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,14 @@ def close(self, build=False):
if hasattr(self, "table") and self.table is not None:
self.table.conn.close()
if self.is_open():
if libvect.Vect_close(self.c_mapinfo) != 0:
str_err = "Error when trying to close the map with Vect_close"
raise GrassError(str_err)
if (
self.c_mapinfo.contents.mode == libvect.GV_MODE_RW
or self.c_mapinfo.contents.mode == libvect.GV_MODE_WRITE
) and build:
self.build()
if libvect.Vect_close(self.c_mapinfo) != 0:
str_err = "Error when trying to close the map with Vect_close"
raise GrassError(str_err)

def remove(self):
"""Remove vector map"""
Expand All @@ -478,16 +478,11 @@ def remove(self):

def build(self):
"""Close the vector map and build vector Topology"""
self.close()
libvect.Vect_set_open_level(1)
if libvect.Vect_open_old2(self.c_mapinfo, self.name, self.mapset, "0") != 1:
str_err = "Error when trying to open the vector map."
raise GrassError(str_err)
# Vect_build returns 1 on success and 0 on error (bool approach)
if libvect.Vect_build(self.c_mapinfo) != 1:
str_err = "Error when trying build topology with Vect_build"
raise GrassError(str_err)
libvect.Vect_close(self.c_mapinfo)
if self.is_open():
# Vect_build returns 1 on success and 0 on error (bool approach)
if libvect.Vect_build(self.c_mapinfo) != 1:
str_err = "Error when trying build topology with Vect_build"
raise GrassError(str_err)


if __name__ == "__main__":
Expand Down

0 comments on commit 4d2a3f9

Please sign in to comment.