[GRASS-CVS] markus: grass6/lib/vector/Vlib break_lines.c, 1.4,
1.4.6.1 cindex.c, 1.14, 1.14.2.1 field.c, 1.41,
1.41.6.1 snap.c, 1.8, 1.8.2.1
grass at intevation.de
grass at intevation.de
Sun Nov 18 14:54:41 EST 2007
Author: markus
Update of /grassrepository/grass6/lib/vector/Vlib
In directory doto:/tmp/cvs-serv23033
Modified Files:
Tag: releasebranch_6_3
break_lines.c cindex.c field.c snap.c
Log Message:
Portability and warning fixes; Don't use C99 features
Index: break_lines.c
===================================================================
RCS file: /grassrepository/grass6/lib/vector/Vlib/break_lines.c,v
retrieving revision 1.4
retrieving revision 1.4.6.1
diff -u -d -r1.4 -r1.4.6.1
--- break_lines.c 9 Feb 2006 03:08:58 -0000 1.4
+++ break_lines.c 18 Nov 2007 19:54:38 -0000 1.4.6.1
@@ -1,46 +1,84 @@
-/***************************************************************
+/*!
+ * \file break_lines.c
*
- * MODULE: vector library
- *
- * AUTHOR(S): Radim Blazek
- *
- * PURPOSE: Clean lines
- *
- * COPYRIGHT: (C) 2001 by the GRASS Development Team
+ * \brief Vector library - Clean vector map (break lines)
*
- * This program is free software under the
- * GNU General Public License (>=v2).
- * Read the file COPYING that comes with GRASS
- * for details.
+ * \author Radim Blazek
*
- **************************************************************/
+ * (C) 2001 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.
+ */
+
#include <stdlib.h>
#include <grass/gis.h>
#include <grass/Vect.h>
/*!
- \fn void Vect_break_lines ( struct Map_info *Map, int type, struct Map_info *Err, FILE *msgout)
- \brief Break lines in vector map.
+ \brief Break lines in vector map at each intersection.
- Breaks lines specified by type in vector map. Points at intersections may be optionaly
- written to error map. Input map must be opened on level 2 for update at least on GV_BUILD_BASE.
+ For details see Vect_break_lines_list().
- The function also breaks lines forming collapsed loop, for example 0,0;1,0;0,0 is broken at 1,0.
+ \param[in] Map input vector map where lines will be broken
+ \param[in] type type of line to be broken
+ \param[out] Err vector map where points at intersections will be written or NULL
+ \param[out] msgout file pointer where messages will be written or NULL
- \param Map input map where lines will be broken
- \param type type of line to be broken
- \param Err vector map where points at intersections will be written or NULL
- \param msgout file pointer where messages will be written or NULL
\return
*/
+
void
Vect_break_lines ( struct Map_info *Map, int type, struct Map_info *Err, FILE *msgout )
{
+ int line, nlines;
+ struct ilist *List;
+
+ List = Vect_new_list();
+
+ nlines = Vect_get_num_lines(Map);
+
+ for (line = 1; line <= nlines; line++) {
+ Vect_list_append (List, line);
+ }
+
+ Vect_break_lines_list (Map, List, type, Err, msgout);
+
+ Vect_destroy_list(List);
+
+ return;
+}
+
+/*!
+ \brief Break selected lines in vector map at each intersection.
+
+ Breaks selected lines specified by type in vector map. Points at
+ intersections may be optionaly written to error map. Input vector map
+ must be opened on level 2 for update at least on GV_BUILD_BASE.
+
+ The function also breaks lines forming collapsed loop, for example
+ 0,0;1,0;0,0 is broken at 1,0.
+
+ \param[in] Map input vector map where lines will be broken
+ \param[in] List_break list of lines
+ \param[in] type type of line to be broken
+ \param[out] Err vector map where points at intersections will be written or NULL
+ \param[out] msgout file pointer where messages will be written or NULL
+
+ \return
+*/
+
+int
+Vect_break_lines_list ( struct Map_info *Map, struct ilist *List_break,
+ int type, struct Map_info *Err, FILE *msgout )
+{
struct line_pnts *APoints, *BPoints, *Points;
struct line_pnts **AXLines, **BXLines;
struct line_cats *ACats, *BCats, *Cats;
- int j, k, l, ret, atype, btype, aline, bline, found;
- int nlines, naxlines, nbxlines, nx;
+ int j, k, l, ret, atype, btype, aline, bline, found, iline;
+ int naxlines, nbxlines, nx;
double *xx=NULL, *yx=NULL, *zx=NULL;
BOUND_BOX ABox, BBox;
struct ilist *List;
@@ -60,28 +98,35 @@
Cats = Vect_new_cats_struct ();
List = Vect_new_list ();
- nlines = Vect_get_num_lines (Map);
is3d = Vect_is_3d ( Map );
- G_debug (3, "nlines = %d", nlines );
+ G_debug (3, "nlines = %d", List_break->n_values );
/* To find intersection of two lines (Vect_line_intersection) is quite slow.
* Fortunately usual lines/boundaries in GIS often forms a network where lines
* are connected by end points, and touch by MBR. This function checks and occasionaly
- * skips such cases. This is currently done for 2D only */
+ * skips such cases. This is currently done for 2D only
+ */
/* Go through all lines in vector, for each select lines which overlap MBR of
- * this line exclude those connected by one endpoint (see above)
- * and try to intersect, if lines intersect write new lines at the end of
- * the file, and process next line (remainining lines overlaping box are skipped) */
+ * this line exclude those connected by one endpoint (see above)
+ * and try to intersect, if lines intersect write new lines at the end of
+ * the file, and process next line (remainining lines overlaping box are skipped)
+ */
nbreaks = 0;
printed = 0;
- if (msgout) fprintf (msgout, "Intersections: %5d", nbreaks );
- for ( aline = 1; aline <= nlines; aline++ ){
+
+ if (msgout)
+ fprintf (msgout, "Intersections: %5d", nbreaks );
+
+ for ( iline = 0; iline < List_break->n_values; iline++ ){
+ aline = List_break->value[iline];
G_debug (3, "aline = %d", aline);
- if ( !Vect_line_alive ( Map, aline ) ) continue;
+ if ( !Vect_line_alive ( Map, aline ) )
+ continue;
atype = Vect_read_line (Map, APoints, ACats, aline);
- if ( !(atype & type) ) continue;
+ if ( !(atype & type) )
+ continue;
Vect_get_line_box ( Map, aline, &ABox );
@@ -136,7 +181,8 @@
( node == anode1 && nodex == ABox.W && !touch1_w && nodex == BBox.E ) ||
( node == anode2 && nodex == ABox.W && !touch2_w && nodex == BBox.E ) )
{
- G_debug(3, "lines %d and %d touching by end nodes only -> no intersection", aline, bline);
+ G_debug(3, "lines %d and %d touching by end nodes only -> no intersection",
+ aline, bline);
continue;
}
}
@@ -192,6 +238,7 @@
if ( (atype & GV_POINTS) || AXLines[k]->n_points > 1 ) {
ret = Vect_write_line ( Map, atype, AXLines[k], ACats );
G_debug (3, "Line %d written, npoints = %d", ret, AXLines[k]->n_points);
+ Vect_list_append(List_break, ret);
}
/* Write intersection points */
@@ -219,6 +266,7 @@
if ( (btype & GV_POINTS) || BXLines[k]->n_points > 1 ) {
ret = Vect_write_line ( Map, btype, BXLines[k], BCats );
G_debug (5, "Line %d written", ret);
+ Vect_list_append(List_break, ret);
}
/* Write intersection points */
@@ -270,10 +318,13 @@
printed++;
if ( naxlines > 0 ) break; /* first line was broken and deleted -> take the next one */
}
- nlines = Vect_get_num_lines (Map);
- G_debug (3, "nlines = %d\n", nlines );
+ G_debug (3, "nlines = %d\n", List_break->n_values);
}
- if (msgout) fprintf (msgout, "\rIntersections: %5d \n", nbreaks );
+ if (msgout)
+ fprintf (msgout, "\rIntersections: %5d \n", nbreaks );
+
Vect_destroy_list ( List );
+
+ return nbreaks;
}
Index: cindex.c
===================================================================
RCS file: /grassrepository/grass6/lib/vector/Vlib/cindex.c,v
retrieving revision 1.14
retrieving revision 1.14.2.1
diff -u -d -r1.14 -r1.14.2.1
--- cindex.c 11 Oct 2007 16:14:51 -0000 1.14
+++ cindex.c 18 Nov 2007 19:54:38 -0000 1.14.2.1
@@ -105,8 +105,9 @@
Vect_cidx_get_num_unique_cats_by_index ( struct Map_info *Map, int index )
{
check_status ( Map );
- if ( index >= Map->plus.n_cidx )
- G_fatal_error(_("Invalid layer index (index >= number of layers)"));
+
+ if ( index < 0 || index >= Map->plus.n_cidx )
+ G_fatal_error(_("Invalid layer index (index < 0 or index >= number of layers)"));
return ( Map->plus.cidx[index].n_ucats );
}
@@ -339,9 +340,10 @@
{
int type, line;
struct Cat_index *ci;
+ int field_index, idx;
Vect_reset_list ( lines );
- int field_index = Vect_cidx_get_field_index ( Map, layer );
+ field_index = Vect_cidx_get_field_index ( Map, layer );
if (field_index == -1) {
/* not found */
@@ -349,7 +351,7 @@
}
ci = &(Map->plus.cidx[field_index]);
- int idx = Vect_cidx_find_next ( Map, field_index, cat,
+ idx = Vect_cidx_find_next ( Map, field_index, cat,
type_mask, 0, &type, &line );
if ( idx == -1 )
Index: field.c
===================================================================
RCS file: /grassrepository/grass6/lib/vector/Vlib/field.c,v
retrieving revision 1.41
retrieving revision 1.41.6.1
diff -u -d -r1.41 -r1.41.6.1
--- field.c 8 Jul 2006 17:05:56 -0000 1.41
+++ field.c 18 Nov 2007 19:54:38 -0000 1.41.6.1
@@ -384,7 +384,7 @@
if ( Map->format == GV_FORMAT_OGR ) {
#if GDAL_VERSION_NUM > 1320 /* seems to be fixed after 1320 release */
- int i, layer, nLayers;
+ int layer, nLayers;
OGRDataSourceH Ogr_ds;
OGRLayerH Ogr_layer=NULL;
OGRFeatureDefnH Ogr_featuredefn;
Index: snap.c
===================================================================
RCS file: /grassrepository/grass6/lib/vector/Vlib/snap.c,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -u -d -r1.8 -r1.8.2.1
--- snap.c 18 Jul 2007 10:13:09 -0000 1.8
+++ snap.c 18 Nov 2007 19:54:38 -0000 1.8.2.1
@@ -1,31 +1,7 @@
-/**************************************************************
- *
- * MODULE: Vector library
- *
- * AUTHOR(S): Radim Blazek
- *
- * PURPOSE: Clean lines
- *
- * COPYRIGHT: (C) 2001 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.
- *
- **************************************************************/
-#include <stdlib.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/Vect.h>
-#include <grass/glocale.h>
-
/*!
* \file snap.c
*
- * \brief Vector library
- *
- * Clean lines
+ * \brief Vector library - Clean vector map (snap lines)
*
* \author Radim Blazek
*
@@ -36,6 +12,10 @@
* Read the file COPYING that comes with GRASS
* for details.
*/
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/Vect.h>
+#include <grass/glocale.h>
/* function prototypes */
static int sort_new(const void *pa, const void *pb);
@@ -56,8 +36,8 @@
/* This function is called by RTreeSearch() to add selected node/line/area/isle to thelist */
int add_item(int id, struct ilist *list)
{
- dig_list_add ( list, id );
- return 1;
+ dig_list_add ( list, id );
+ return 1;
}
@@ -98,7 +78,7 @@
{
struct line_pnts *Points, *NPoints;
struct line_cats *Cats;
- int nlines, line, ltype, line_idx;
+ int line, ltype, line_idx;
double thresh2;
int printed;
@@ -126,8 +106,6 @@
RTree = RTreeNewIndex();
thresh2 = thresh * thresh;
-
- G_debug (3, "nlines = %d", nlines );
/* Go through all lines in vector, and add each point to structure of points */
apoints = 0;
@@ -416,9 +394,9 @@
/*!
* \fn void Vect_snap_lines (struct Map_info *Map, int type, double thresh, struct Map_info *Err, FILE *msgout )
*
- * \brief Snap all lines to existing vertex in threshold.
+ * \brief Snap lines in vector map to existing vertex in threshold.
*
- * See Vect_snap_lines_list()
+ * For details see Vect_snap_lines_list()
*
* \param[in] Map input map where vertices will be snapped
* \param[in] type type of lines to snap
@@ -434,12 +412,7 @@
struct ilist* List;
- struct line_pnts *Points;
- struct line_cats *Cats;
-
List = Vect_new_list();
- Points = Vect_new_line_struct();
- Cats = Vect_new_cats_struct();
nlines = Vect_get_num_lines (Map);
@@ -449,7 +422,7 @@
if (!Vect_line_alive (Map, line))
continue;
- ltype = Vect_read_line (Map, Points, Cats, line);
+ ltype = Vect_read_line (Map, NULL, NULL, line);
if (!(ltype & type))
continue;
@@ -459,8 +432,6 @@
Vect_snap_lines_list (Map, List, thresh, Err, msgout);
- Vect_destroy_cats_struct (Cats);
- Vect_destroy_line_struct (Points);
Vect_destroy_list (List);
return;
More information about the grass-commit
mailing list