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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Apr 1 07:06:43 PDT 2013


Author: martinl
Date: 2013-04-01 07:06:43 -0700 (Mon, 01 Apr 2013)
New Revision: 55580

Modified:
   grass/trunk/lib/vector/Vlib/box.c
   grass/trunk/lib/vector/Vlib/break_lines.c
   grass/trunk/lib/vector/Vlib/build.c
   grass/trunk/lib/vector/Vlib/level_two.c
   grass/trunk/lib/vector/Vlib/select.c
Log:
vlib: Vect_get_line|area|isle_box() return -1 on error
      doxygen update - note requested built level
      formatting issues


Modified: grass/trunk/lib/vector/Vlib/box.c
===================================================================
--- grass/trunk/lib/vector/Vlib/box.c	2013-04-01 13:04:57 UTC (rev 55579)
+++ grass/trunk/lib/vector/Vlib/box.c	2013-04-01 14:06:43 UTC (rev 55580)
@@ -128,9 +128,7 @@
  *  \return 1 if any clipping occured
  *  \return 0 otherwise
  */
-
-int
-Vect_box_clip(double *x, double *y, double *c_x, double *c_y, const struct bound_box *Box)
+int Vect_box_clip(double *x, double *y, double *c_x, double *c_y, const struct bound_box *Box)
 {
     int mod;
 
@@ -192,12 +190,16 @@
 /*!
    \brief Get bounding box of given feature
 
+   Vector map must be open at topological level and built with level
+   >= GV_BUILD_BASE.
+
    \param Map vector map
    \param line feature id
    \param[out] Box bounding box
 
    \return 1 on success
    \return 0 line is dead
+   \return -1 on error
  */
 int Vect_get_line_box(const struct Map_info *Map, int line, struct bound_box *Box)
 {
@@ -206,9 +208,13 @@
     int type;
     static struct line_pnts *Points = NULL;
 
-    Plus = (struct Plus_head *)&(Map->plus);
+    Plus = (struct Plus_head *) &(Map->plus);
+    if (line < 1 || line > Plus->n_lines) {
+      G_warning(_("Attempt to access feature with invalid id (%d)"), line);
+      return -1;
+    }
+    
     Line = Plus->Line[line];
-
     if (Line == NULL) {		/* dead */
 	Box->N = Box->S = Box->E = Box->W = Box->T = Box->B = 0. / 0.;
 	return 0;
@@ -218,10 +224,11 @@
 
     /* GV_LINES: retrieve box from spatial index */
     if (type & GV_LINES) {
-	
-	if (dig_find_line_box(Plus, line, Box) == 0)
-	    G_fatal_error(_("Unable to find bbox for feature %d"), line);
-
+	if (dig_find_line_box(Plus, line, Box) == 0) {
+	    G_warning(_("Unable to determine bbox for feature %d"), line);
+            return -1;
+        }
+        
 	if (!Vect_is_3d(Map)) {
 	    Box->T =  PORT_DOUBLE_MAX;
 	    Box->B = -PORT_DOUBLE_MAX;
@@ -249,19 +256,28 @@
 /*!
    \brief Get bounding box of area
 
+   Vector map must be open at topological level and built with level
+   >= GV_BUILD_AREAS.
+
    \param Map vector map
    \param area area id
    \param[out] Box bounding box
 
    \return 1 on success
    \return 0 area is dead
+   \return -1 on error
  */
 int Vect_get_area_box(const struct Map_info *Map, int area, struct bound_box *Box)
 {
     struct Plus_head *Plus;
     struct P_area *Area;
 
-    Plus = (struct Plus_head *)&(Map->plus);
+    Plus = (struct Plus_head *) &(Map->plus);
+    if (area < 1 || area > Plus->n_areas) {
+        G_warning(_("Attempt to access area with invalid id (%d)"), area);
+        return -1;
+    }
+
     Area = Plus->Area[area];
 
     if (Area == NULL) {		/* dead */
@@ -269,8 +285,10 @@
 	return 0;
     }
 
-    if (dig_find_area_box(Plus, area, Box) == 0)
-	G_fatal_error(_("Unable to get bounding box for area %d"), area);
+    if (dig_find_area_box(Plus, area, Box) == 0) {
+        G_warning(_("Unable to determine bbox for area %d"), area);
+        return -1;
+    }
 
     if (!Vect_is_3d(Map)) {
 	Box->T =  PORT_DOUBLE_MAX;
@@ -283,19 +301,29 @@
 /*!
    \brief Get bounding box of isle
 
+   Vector map must be open at topological level and built with level
+   >= GV_BUILD_AREAS.
+
    \param Map vector map
    \param isle isle id
    \param[out] Box bounding box
 
    \return 1 on success
    \return 0 isle is dead / bounding box not found
+   \return -1 on error
  */
 int Vect_get_isle_box(const struct Map_info *Map, int isle, struct bound_box *Box)
 {
     struct Plus_head *Plus;
     struct P_isle *Isle;
 
-    Plus = (struct Plus_head *)&(Map->plus);
+    Plus = (struct Plus_head *) &(Map->plus);
+
+    if (isle < 1 || isle > Plus->n_isles) {
+        G_warning(_("Attempt to access area with invalid id (%d)"), isle);
+        return -1;
+    }
+
     Isle = Plus->Isle[isle];
 
     if (Isle == NULL) {		/* dead */
@@ -303,8 +331,10 @@
 	return 0;
     }
 
-    if (dig_find_isle_box(Plus, isle, Box) == 0)
-	G_fatal_error(_("Could not find isle box"));
+    if (dig_find_isle_box(Plus, isle, Box) == 0) {
+	G_warning(_("Unable to determine bbox for isle %d"), isle);
+        return -1;
+    }
 
     if (!Vect_is_3d(Map)) {
 	Box->T =  PORT_DOUBLE_MAX;

Modified: grass/trunk/lib/vector/Vlib/break_lines.c
===================================================================
--- grass/trunk/lib/vector/Vlib/break_lines.c	2013-04-01 13:04:57 UTC (rev 55579)
+++ grass/trunk/lib/vector/Vlib/break_lines.c	2013-04-01 14:06:43 UTC (rev 55580)
@@ -29,12 +29,8 @@
    \param Map input vector map 
    \param type feature type
    \param[out] Err vector map where points at intersections will be written or NULL
-
-   \return
- */
-
-void
-Vect_break_lines(struct Map_info *Map, int type, struct Map_info *Err)
+*/
+void Vect_break_lines(struct Map_info *Map, int type, struct Map_info *Err)
 {
     break_lines(Map, NULL, NULL, type, Err, 0);
 
@@ -61,12 +57,11 @@
    \param[out] Err vector map where points at intersections will be written or NULL
 
    \return number of intersections
- */
+*/
 
-int
-Vect_break_lines_list(struct Map_info *Map, struct ilist *List_break,
-		      struct ilist *List_ref, int type,
-		      struct Map_info *Err)
+int Vect_break_lines_list(struct Map_info *Map, struct ilist *List_break,
+                          struct ilist *List_ref, int type,
+                          struct Map_info *Err)
 {
     return break_lines(Map, List_break, List_ref, type, Err, 0);
 }
@@ -74,17 +69,15 @@
 /*!
    \brief Check for and count intersecting lines, do not break.
 
-   For details see Vect_break_lines_list().
+   For details see Vect_check_line_breaks_list().
 
    \param Map input vector map 
    \param type feature type
    \param[out] Err vector map where points at intersections will be written or NULL
 
-   \return
- */
-
-int
-Vect_check_line_breaks(struct Map_info *Map, int type, struct Map_info *Err)
+   \return number for intersections
+*/
+int Vect_check_line_breaks(struct Map_info *Map, int type, struct Map_info *Err)
 {
     return break_lines(Map, NULL, NULL, type, Err, 1);
 }
@@ -105,10 +98,8 @@
    \param[out] Err vector map where points at intersections will be written or NULL
 
    \return number of intersections
- */
-
-int
-Vect_check_line_breaks_list(struct Map_info *Map, struct ilist *List_break,
+*/
+int Vect_check_line_breaks_list(struct Map_info *Map, struct ilist *List_break,
 		      struct ilist *List_ref, int type,
 		      struct Map_info *Err)
 {
@@ -149,10 +140,9 @@
     }
 }
 
-int
-break_lines(struct Map_info *Map, struct ilist *List_break,
-		      struct ilist *List_ref, int type,
-		      struct Map_info *Err, int check)
+int break_lines(struct Map_info *Map, struct ilist *List_break,
+                struct ilist *List_ref, int type,
+                struct Map_info *Err, int check)
 {
     struct line_pnts *APoints, *BPoints, *Points;
     struct line_pnts **AXLines, **BXLines;

Modified: grass/trunk/lib/vector/Vlib/build.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build.c	2013-04-01 13:04:57 UTC (rev 55579)
+++ grass/trunk/lib/vector/Vlib/build.c	2013-04-01 14:06:43 UTC (rev 55580)
@@ -543,7 +543,7 @@
 		topo->area = sel_area;
 
 		if (sel_area != orig_area && plus->uplist.do_uplist)
-		    dig_line_add_updated(plus, centr);
+                  dig_line_add_updated(plus, centr);
 	    }
 	    else if (Area->centroid != centr) {	/* duplicate centroid */
 		/* Note: it cannot happen that Area->centroid == centr, because the centroid
@@ -552,7 +552,7 @@
 		topo->area = -sel_area;
 
 		if (-sel_area != orig_area && plus->uplist.do_uplist)
-		    dig_line_add_updated(plus, centr);
+                  dig_line_add_updated(plus, centr);
 	    }
 	}
     }
@@ -848,8 +848,8 @@
 
     /* If topology is already build (map on > level 2), set level to 1
      * so that lines will be read by V1_read_ (all lines) */
-    Map->level = 1; /* may be not needed, because V1_read is used
-		       directly by Vect_build_ */
+    Map->level = LEVEL_1; /* may be not needed, because V1_read is used
+                             directly by Vect_build_ */
     if (Map->format != GV_FORMAT_OGR_DIRECT)
 	Map->support_updated = TRUE;
 
@@ -870,7 +870,6 @@
     }
 
     ret = ((*Build_array[Map->format]) (Map, build));
-
     if (ret == 0) {
 	return 0;
     }

Modified: grass/trunk/lib/vector/Vlib/level_two.c
===================================================================
--- grass/trunk/lib/vector/Vlib/level_two.c	2013-04-01 13:04:57 UTC (rev 55579)
+++ grass/trunk/lib/vector/Vlib/level_two.c	2013-04-01 14:06:43 UTC (rev 55580)
@@ -231,6 +231,8 @@
    Note: Vect_set_updated() must be called to maintain list of updated
    features
 
+   Negative id indicates deleted node.
+
    \param Map pointer to Map_info struct
    \param idx index
 

Modified: grass/trunk/lib/vector/Vlib/select.c
===================================================================
--- grass/trunk/lib/vector/Vlib/select.c	2013-04-01 13:04:57 UTC (rev 55579)
+++ grass/trunk/lib/vector/Vlib/select.c	2013-04-01 14:06:43 UTC (rev 55580)
@@ -133,9 +133,8 @@
 
    \return number of selected items
  */
-int
-Vect_spatial_index_select(const struct spatial_index * si, const struct bound_box * box,
-			  struct ilist *list)
+int Vect_spatial_index_select(const struct spatial_index * si, const struct bound_box * box,
+                              struct ilist *list)
 {
     static struct RTree_Rect rect;
     static int rect_init = 0;
@@ -145,8 +144,6 @@
 	rect_init = si->si_tree->nsides_alloc;
     }
 
-    G_debug(3, "Vect_spatial_index_select()");
-
     Vect_reset_list(list);
 
     rect.boundary[0] = box->W;
@@ -157,7 +154,7 @@
     rect.boundary[5] = box->T;
     RTreeSearch(si->si_tree, &rect, (void *)_add_item, list);
 
-    G_debug(3, "  %d items selected", list->n_values);
+    G_debug(3, "Vect_spatial_index_select(): %d items selected", list->n_values);
 
-    return (list->n_values);
+    return list->n_values;
 }



More information about the grass-commit mailing list