[GRASS-SVN] r73618 - in grass/trunk/lib/vector: diglib rtree
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Oct 29 01:29:24 PDT 2018
Author: mmetz
Date: 2018-10-29 01:29:24 -0700 (Mon, 29 Oct 2018)
New Revision: 73618
Modified:
grass/trunk/lib/vector/diglib/spindex_rw.c
grass/trunk/lib/vector/rtree/index.c
grass/trunk/lib/vector/rtree/io.c
Log:
vectorlib: fix size estimation of spatial indices
Modified: grass/trunk/lib/vector/diglib/spindex_rw.c
===================================================================
--- grass/trunk/lib/vector/diglib/spindex_rw.c 2018-10-28 21:14:54 UTC (rev 73617)
+++ grass/trunk/lib/vector/diglib/spindex_rw.c 2018-10-29 08:29:24 UTC (rev 73618)
@@ -65,7 +65,8 @@
/* use ptr->off_t_size = 4 if possible */
if (sizeof(off_t) > 4) {
- size = ptr->Node_spidx->n_nodes * ptr->Node_spidx->nodesize;
+ size = 145; /* max header size, see below */
+ size += ptr->Node_spidx->n_nodes * ptr->Node_spidx->nodesize;
size += ptr->Line_spidx->n_nodes * ptr->Line_spidx->nodesize;
size += ptr->Area_spidx->n_nodes * ptr->Area_spidx->nodesize;
size += ptr->Isle_spidx->n_nodes * ptr->Isle_spidx->nodesize;
Modified: grass/trunk/lib/vector/rtree/index.c
===================================================================
--- grass/trunk/lib/vector/rtree/index.c 2018-10-28 21:14:54 UTC (rev 73617)
+++ grass/trunk/lib/vector/rtree/index.c 2018-10-29 08:29:24 UTC (rev 73618)
@@ -84,13 +84,13 @@
new_rtree->free_nodes.pos = NULL;
new_rtree->rectsize = new_rtree->nsides_alloc * sizeof(RectReal);
+ new_rtree->branchsize = sizeof(struct RTree_Branch) -
+ sizeof(struct RTree_Rect) +
+ new_rtree->rectsize;
new_rtree->nodesize = sizeof(struct RTree_Node) -
- MAXCARD * sizeof(RectReal *) +
- MAXCARD * new_rtree->rectsize;
+ sizeof(struct RTree_Branch *) +
+ MAXCARD * new_rtree->branchsize;
- new_rtree->branchsize = sizeof(struct RTree_Branch) -
- sizeof(RectReal *) + new_rtree->rectsize;
-
/* create empty root node */
n = RTreeAllocNode(new_rtree, 0);
new_rtree->rootlevel = n->level = 0; /* leaf */
Modified: grass/trunk/lib/vector/rtree/io.c
===================================================================
--- grass/trunk/lib/vector/rtree/io.c 2018-10-28 21:14:54 UTC (rev 73617)
+++ grass/trunk/lib/vector/rtree/io.c 2018-10-29 08:29:24 UTC (rev 73618)
@@ -18,10 +18,12 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <assert.h>
-#include <grass/config.h>
+#include <errno.h>
+#include <grass/gis.h>
#include "index.h"
/* #define USAGE_SWAP */
@@ -153,8 +155,12 @@
{
size_t size = 0;
- size += write(t->fd, b->rect.boundary, t->rectsize);
- size += write(t->fd, &(b->child), sizeof(union RTree_Child));
+ if (write(t->fd, b->rect.boundary, t->rectsize) != t->rectsize)
+ G_fatal_error("RTreeWriteBranch(): Unable to write (%s)", strerror(errno));
+ size += t->rectsize;
+ if (write(t->fd, &(b->child), sizeof(union RTree_Child)) != sizeof(union RTree_Child))
+ G_fatal_error("RTreeWriteBranch(): Unable to write (%s)", strerror(errno));
+ size += sizeof(union RTree_Child);
return size;
}
@@ -166,8 +172,12 @@
size_t size = 0;
/* file position must be set first with RTreeGetFNodePos() */
- size += write(t->fd, &(n->count), sizeof(int));
- size += write(t->fd, &(n->level), sizeof(int));
+ if (write(t->fd, &(n->count), sizeof(int)) != sizeof(int))
+ G_fatal_error("RTreeWriteNode(): Unable to write (%s)", strerror(errno));
+ size += sizeof(int);
+ if (write(t->fd, &(n->level), sizeof(int)) != sizeof(int))
+ G_fatal_error("RTreeWriteNode(): Unable to write (%s)", strerror(errno));
+ size += sizeof(int);
for (i = 0; i < MAXCARD; i++) {
size += RTreeWriteBranch(&(n->branch[i]), t);
More information about the grass-commit
mailing list