[GRASS-SVN] r70521 - in grass/trunk: include/defs lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Feb 10 01:18:42 PST 2017


Author: martinl
Date: 2017-02-10 01:18:42 -0800 (Fri, 10 Feb 2017)
New Revision: 70521

Modified:
   grass/trunk/include/defs/vector.h
   grass/trunk/lib/vector/Vlib/box.c
Log:
Vlib: introduce Vect_get_map_box1() working on level 1


Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h	2017-02-10 09:09:00 UTC (rev 70520)
+++ grass/trunk/include/defs/vector.h	2017-02-10 09:18:42 UTC (rev 70521)
@@ -200,9 +200,13 @@
 double Vect_get_thresh(const struct Map_info *);
 int Vect_get_constraint_box(const struct Map_info *, struct bound_box *);
 
+/* Get map information */
+int Vect_level(const struct Map_info *);
 
+/* Get map level 1 information */
+int Vect_get_map_box1(struct Map_info *, struct bound_box *);
+
 /* Get map level 2 information */
-int Vect_level(const struct Map_info *);
 int Vect_get_line_type(const struct Map_info *, int);
 plus_t Vect_get_num_nodes(const struct Map_info *);
 plus_t Vect_get_num_primitives(const struct Map_info *, int);

Modified: grass/trunk/lib/vector/Vlib/box.c
===================================================================
--- grass/trunk/lib/vector/Vlib/box.c	2017-02-10 09:09:00 UTC (rev 70520)
+++ grass/trunk/lib/vector/Vlib/box.c	2017-02-10 09:18:42 UTC (rev 70521)
@@ -383,6 +383,8 @@
 /*!
    \brief Get bounding box of map (all features in the map)
 
+   Requires level 2. On level 1 error code is returned.
+
    \param Map vector map
    \param[out] Box bounding box
 
@@ -393,15 +395,60 @@
 {
     const struct Plus_head *Plus;
 
+    if (Vect_level(Map) < 2)
+        return 0;
+    
     Plus = &(Map->plus);
+    Vect_box_copy(Box, &(Plus->box));
 
-    Box->N = Plus->box.N;
-    Box->S = Plus->box.S;
-    Box->E = Plus->box.E;
-    Box->W = Plus->box.W;
-    Box->T = Plus->box.T;
-    Box->B = Plus->box.B;
+    return 1;
+}
 
+/*!
+   \brief Get bounding box of map on level 1 (all features in the map)
+
+   This subroutine determines bounding box by reading all features
+   sequentially.
+
+   \param Map vector map
+   \param[out] Box bounding box
+
+   \return 1 on success
+   \return 0 on error
+ */
+int Vect_get_map_box1(struct Map_info *Map, struct bound_box *Box)
+{    
+    int type;
+    int first = TRUE;
+    
+    struct line_pnts *Points;
+    struct bound_box line_box;
+    
+    Points = Vect_new_line_struct();
+    Vect_rewind(Map);
+    while (TRUE) {
+        /* register line */
+        type = Vect_read_next_line(Map, Points, NULL);
+        
+        if (type == -1) {
+            G_warning(_("Unable to read vector map"));
+            return 0;
+        }
+        else if (type == -2) {
+            break;
+        }
+        
+        /* update box */
+        dig_line_box(Points, &line_box);
+        if (first == TRUE) {
+            Vect_box_copy(Box, &line_box);
+            first = FALSE;
+        }
+        else
+            Vect_box_extend(Box, &line_box);
+    }
+    Vect_destroy_line_struct(Points);
+    
     return 1;
 }
 



More information about the grass-commit mailing list