Просмотр исходного кода

Vlib: introduce Vect_get_map_box1() working on level 1

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70521 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 8 лет назад
Родитель
Сommit
46fd3ef34b
2 измененных файлов с 58 добавлено и 7 удалено
  1. 5 1
      include/defs/vector.h
  2. 53 6
      lib/vector/Vlib/box.c

+ 5 - 1
include/defs/vector.h

@@ -200,9 +200,13 @@ int Vect_set_thresh(struct Map_info *, double);
 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);

+ 53 - 6
lib/vector/Vlib/box.c

@@ -383,6 +383,8 @@ int Vect_get_isle_box(const struct Map_info *Map, int isle, struct bound_box *Bo
 /*!
    \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 @@ int Vect_get_map_box(const struct Map_info *Map, struct bound_box *Box)
 {
     const struct Plus_head *Plus;
 
+    if (Vect_level(Map) < 2)
+        return 0;
+    
     Plus = &(Map->plus);
+    Vect_box_copy(Box, &(Plus->box));
+
+    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.
 
-    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;
+   \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;
 }