[GRASS-SVN] r51595 - in grass/trunk: include/defs lib/python/ctypes lib/python/temporal lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 4 21:57:37 EDT 2012


Author: huhabla
Date: 2012-05-04 18:57:37 -0700 (Fri, 04 May 2012)
New Revision: 51595

Added:
   grass/trunk/lib/vector/Vlib/rtree_search.c
Modified:
   grass/trunk/include/defs/vector.h
   grass/trunk/lib/python/ctypes/Makefile
   grass/trunk/lib/python/temporal/spatial_extent.py
   grass/trunk/lib/python/temporal/unit_tests.py
Log:
Added the rtree library to ctypes Python wrapper and vector support functions 
to be used by the temporal GIS framework for efficient spatio-temporal topology creation. 
Added a new RTreeSearch function to use an ilist to store rectangle ids.


Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h	2012-05-04 22:53:24 UTC (rev 51594)
+++ grass/trunk/include/defs/vector.h	2012-05-05 01:57:37 UTC (rev 51595)
@@ -566,4 +566,7 @@
 int Vect_remove_colors(const char *, const char *);
 void Vect_write_colors(const char *, const char *, struct Colors *);
 
+/* Simplified RTree search using an ilist to store rectangle ids */
+int RTreeSearch2(struct RTree *, struct RTree_Rect *, struct ilist *);
+
 #endif /* GRASS_VECTORDEFS_H */

Modified: grass/trunk/lib/python/ctypes/Makefile
===================================================================
--- grass/trunk/lib/python/ctypes/Makefile	2012-05-04 22:53:24 UTC (rev 51594)
+++ grass/trunk/lib/python/ctypes/Makefile	2012-05-05 01:57:37 UTC (rev 51595)
@@ -35,7 +35,7 @@
 gmath_HDRS      = gmath.h defs/gmath.h
 proj_HDRS       = gprojects.h defs/gprojects.h
 imagery_HDRS    = imagery.h defs/imagery.h
-vector_HDRS     = vector.h defs/vector.h vect/dig_structs.h vect/dig_defines.h
+vector_HDRS     = vector.h defs/vector.h vect/dig_structs.h vect/dig_defines.h vect/dig_externs.h rtree/index.h
 display_HDRS    = display.h defs/display.h
 stats_HDRS      = stats.h defs/stats.h
 dbmi_HDRS       = dbmi.h defs/dbmi.h

Modified: grass/trunk/lib/python/temporal/spatial_extent.py
===================================================================
--- grass/trunk/lib/python/temporal/spatial_extent.py	2012-05-04 22:53:24 UTC (rev 51594)
+++ grass/trunk/lib/python/temporal/spatial_extent.py	2012-05-05 01:57:37 UTC (rev 51595)
@@ -678,7 +678,7 @@
 	return True
 
     def meet(self,extent):
-	""" Check if self and extent meet other in three dimensions"""
+	""" Check if self and extent meet each other in three dimensions"""
 	eN = extent.get_north()
         eS = extent.get_south()
         eE = extent.get_east()

Modified: grass/trunk/lib/python/temporal/unit_tests.py
===================================================================
--- grass/trunk/lib/python/temporal/unit_tests.py	2012-05-04 22:53:24 UTC (rev 51594)
+++ grass/trunk/lib/python/temporal/unit_tests.py	2012-05-05 01:57:37 UTC (rev 51595)
@@ -27,6 +27,9 @@
 from datetime_math import *
 from space_time_datasets import *
 
+import grass.lib.vector as vector
+from ctypes import *
+
 # Uncomment this to detect the error
 #core.set_raise_on_error(True)
 
@@ -1565,17 +1568,59 @@
     if new_list[2] != map_list[2]:
 	core.fatal("Sorting by end time failed")
 
+def test_rtree():
+    """Testing the rtree ctypes wrapper"""
+
+    tree = vector.RTreeNewIndex(-1, 0, 1)
+
+    for i in xrange(50):
+        rect = vector.RTree_Rect()
+        vector.RTreeInitRect(byref(rect))
+
+        rect.boundary[0] = i - 3.75
+        rect.boundary[1] = 0
+        rect.boundary[2] = 0
+        rect.boundary[3] = i + 3.75
+        rect.boundary[4] = 0
+        rect.boundary[5] = 0
+
+        # vector.RTreePrintRect(byref(rect), 0)
+
+        vector.RTreeInsertRect(byref(rect), i + 1, tree)
+
+    rect = vector.RTree_Rect()
+    vector.RTreeInitRect(byref(rect))
+
+    i = 25
+    rect.boundary[0] = i - 3.75
+    rect.boundary[1] = 0
+    rect.boundary[2] = 0
+    rect.boundary[3] = i + 3.75
+    rect.boundary[4] = 0
+    rect.boundary[5] = 0
+
+    _list = vector.ilist()
+
+    num = vector.RTreeSearch2(tree, byref(rect), byref(_list))
+
+    # print rectanlge ids
+    print "Number of overlapping rectangles", num
+    for i in xrange(_list.n_values):
+        print "id", _list.value[i]
+
+
 ###############################################################################
 
 if __name__ == "__main__":
     test_increment_datetime_by_string()
     test_adjust_datetime_to_granularity()
     test_spatial_extent_intersection()
-    ##test_compute_relative_time_granularity()
+    #test_compute_relative_time_granularity()
     test_compute_absolute_time_granularity()
     test_compute_datetime_delta()
     test_spatial_extent_intersection()
     test_spatial_relations()
     test_temporal_topology_builder()
     test_map_list_sorting()
-    
\ No newline at end of file
+    test_rtree()
+    

Added: grass/trunk/lib/vector/Vlib/rtree_search.c
===================================================================
--- grass/trunk/lib/vector/Vlib/rtree_search.c	                        (rev 0)
+++ grass/trunk/lib/vector/Vlib/rtree_search.c	2012-05-05 01:57:37 UTC (rev 51595)
@@ -0,0 +1,46 @@
+/*!
+   \file lib/vector/Vlib/rtree_search.c
+
+   \brief Vector library - simplified rtree search
+
+   Higher level functions for reading/writing/manipulating vectors.
+
+   (C) 2012 by the GRASS Development Team
+
+   This program is free software under the GNU General Public License
+   (>=v2).  Read the file COPYING that comes with GRASS for details.
+
+   \author Soeren Gebbert
+ */
+
+#include <assert.h>
+#include <grass/vector.h>
+
+/* Function to add the ids of overlapping rectangles to an ilist
+ * This function is a callback function used in RTreeSearch2()
+ * */
+static int add_id_to_list(int id, struct RTree_Rect rect, void *list)
+{
+    struct ilist *l = (struct ilist*)list;
+    dig_list_add(l, id);
+    return 1;
+}
+
+/**
+ * Search in an index tree for all data retangles that
+ * overlap the argument rectangle.
+ *
+ * \param t: The RTree 
+ * \param r: The argument rectangle
+ * \param list: The list to store the ids of overlapping rectangles
+ * \return the number of qualifying data rects.
+ */
+int RTreeSearch2(struct RTree *t, struct RTree_Rect *r, struct ilist *list)
+{
+    assert(r && t);
+
+    dig_init_list(list);
+
+    return t->search_rect(t, r, add_id_to_list, (void*)list);
+}
+



More information about the grass-commit mailing list