[GRASS-SVN] r44858 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 4 05:10:47 EST 2011


Author: mmetz
Date: 2011-01-04 02:10:47 -0800 (Tue, 04 Jan 2011)
New Revision: 44858

Modified:
   grass/trunk/lib/vector/Vlib/build.c
   grass/trunk/lib/vector/Vlib/close.c
   grass/trunk/lib/vector/Vlib/intersect.c
   grass/trunk/lib/vector/Vlib/open.c
   grass/trunk/lib/vector/Vlib/select.c
Log:
Vlib: new spatial index

Modified: grass/trunk/lib/vector/Vlib/build.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build.c	2011-01-04 10:09:36 UTC (rev 44857)
+++ grass/trunk/lib/vector/Vlib/build.c	2011-01-04 10:10:47 UTC (rev 44858)
@@ -523,21 +523,21 @@
 
     plus = &(Map->plus);
 
-    if (Map->plus.Spidx_built == 0) {
+    if (plus->Spidx_built == 0) {
 	G_warning("Spatial index not available, can not be saved");
 	return 0;
     }
 
     /* new or update mode ? */
-    if (Map->plus.Spidx_new == 1) {
+    if (plus->Spidx_new == 1) {
 
 	/*  write out rtrees to sidx file  */
 	sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
 	G__file_name(fname, buf, GV_SIDX_ELEMENT, Map->mapset);
 	G_debug(1, "Open sidx: %s", fname);
-	dig_file_init(&(Map->plus.spidx_fp));
-	Map->plus.spidx_fp.file = fopen(fname, "w+");
-	if (Map->plus.spidx_fp.file == NULL) {
+	dig_file_init(&(plus->spidx_fp));
+	plus->spidx_fp.file = fopen(fname, "w+");
+	if (plus->spidx_fp.file == NULL) {
 	    G_warning(_("Unable open spatial index file for write <%s>"),
 		      fname);
 	    return 0;
@@ -546,10 +546,11 @@
 	/* set portable info */
 	dig_init_portable(&(plus->spidx_port), dig__byte_order_out());
 
-	if (0 > dig_Wr_spidx(&(Map->plus.spidx_fp), plus)) {
+	if (0 > dig_Wr_spidx(&(plus->spidx_fp), plus)) {
 	    G_warning(_("Error writing out spatial index file"));
 	    return 0;
 	}
+	dig_spidx_free(plus);
 	Map->plus.Spidx_new = 0;
     }
 

Modified: grass/trunk/lib/vector/Vlib/close.c
===================================================================
--- grass/trunk/lib/vector/Vlib/close.c	2011-01-04 10:09:36 UTC (rev 44857)
+++ grass/trunk/lib/vector/Vlib/close.c	2011-01-04 10:10:47 UTC (rev 44858)
@@ -112,7 +112,7 @@
 	if (Map->format != GV_FORMAT_OGR_DIRECT &&
 	    Map->plus.Spidx_built == 1 &&
 	    Map->plus.built == GV_BUILD_ALL)
-	    Vect_save_sidx(Map);
+	    fclose(Map->plus.spidx_fp.file);
     }
 
     if (Map->level == 2 && Map->plus.release_support) {

Modified: grass/trunk/lib/vector/Vlib/intersect.c
===================================================================
--- grass/trunk/lib/vector/Vlib/intersect.c	2011-01-04 10:09:36 UTC (rev 44857)
+++ grass/trunk/lib/vector/Vlib/intersect.c	2011-01-04 10:10:47 UTC (rev 44858)
@@ -677,7 +677,7 @@
      *  in bound box */
 
     /* Create rtree for B line */
-    MyRTree = RTreeNewIndex(2);
+    MyRTree = RTreeNewIndex(-1, 0, 2);
     for (i = 0; i < BPoints->n_points - 1; i++) {
 	if (BPoints->x[i] <= BPoints->x[i + 1]) {
 	    rect.boundary[0] = BPoints->x[i];
@@ -1214,7 +1214,7 @@
      *  in bound box */
 
     /* Create rtree for B line */
-    MyRTree = RTreeNewIndex(2);
+    MyRTree = RTreeNewIndex(-1, 0, 2);
     for (i = 0; i < BPoints->n_points - 1; i++) {
 	if (BPoints->x[i] <= BPoints->x[i + 1]) {
 	    rect.boundary[0] = BPoints->x[i];

Modified: grass/trunk/lib/vector/Vlib/open.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open.c	2011-01-04 10:09:36 UTC (rev 44857)
+++ grass/trunk/lib/vector/Vlib/open.c	2011-01-04 10:10:47 UTC (rev 44858)
@@ -179,6 +179,7 @@
     /* initialize support structures for 2D, update to 3D when reading support files */
     Map->plus.spidx_with_z = Map->plus.with_z = Map->head.with_z = WITHOUT_Z;
     /* initialize Map->plus */
+    Map->plus.Spidx_file = 0;
     dig_init_plus(&(Map->plus));
 
     /* check OGR mapset */
@@ -280,6 +281,7 @@
     /* zone not set */
     if (Vect_get_zone(Map) == -1)
 	Vect_set_zone(Map, G_zone());
+    Vect_set_proj(Map, G_projection());
     
     G_debug(1, "Level request = %d", level_request);
 
@@ -790,6 +792,7 @@
     Open_level = 0;
 
     /* initialize topo */
+    Map->plus.Spidx_file = 0;
     dig_init_plus(&(Map->plus));
 
     /* open new spatial index */
@@ -1083,6 +1086,17 @@
     if (mode) {
 	/* open new spatial index */
 	Map->plus.Spidx_new = 1;
+	
+	/* file based or memory based */
+	if (getenv("GRASS_VECTOR_LOWMEM")) {
+	    /* free old indices */
+	    dig_spidx_free(Plus);
+	    /* initialize file based indices */
+	    Map->plus.Spidx_file = 1;
+	    dig_spidx_init(Plus);
+	}
+	G_debug(0, "%s based spatial index",
+	           Map->plus.Spidx_file == 0 ? "Memory" : "File");
 
 	if (mode == 1) {
 	    /* load spatial index for update */

Modified: grass/trunk/lib/vector/Vlib/select.c
===================================================================
--- grass/trunk/lib/vector/Vlib/select.c	2011-01-04 10:09:36 UTC (rev 44857)
+++ grass/trunk/lib/vector/Vlib/select.c	2011-01-04 10:10:47 UTC (rev 44858)
@@ -34,7 +34,7 @@
 {
     G_debug(1, "Vect_spatial_index_init()");
 
-    si->si_tree = RTreeNewIndex(2 + with_z);
+    si->si_tree = RTreeNewIndex(-1, 0, 2 + (with_z != 0));
 }
 
 /*!



More information about the grass-commit mailing list