[GRASS-SVN] r64837 - grass-addons/grass7/raster/r.stream.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Mar 12 02:36:23 PDT 2015
Author: mmetz
Date: 2015-03-12 02:36:23 -0700 (Thu, 12 Mar 2015)
New Revision: 64837
Modified:
grass-addons/grass7/raster/r.stream.segment/local_vars.h
grass-addons/grass7/raster/r.stream.segment/main.c
grass-addons/grass7/raster/r.stream.segment/stream_segment.c
grass-addons/grass7/raster/r.stream.segment/stream_topology.c
grass-addons/grass7/raster/r.stream.segment/stream_vector.c
Log:
r.stream.segment: fix nodata in attribute table, fix stream ID handling, add TODOs
Modified: grass-addons/grass7/raster/r.stream.segment/local_vars.h
===================================================================
--- grass-addons/grass7/raster/r.stream.segment/local_vars.h 2015-03-12 09:10:17 UTC (rev 64836)
+++ grass-addons/grass7/raster/r.stream.segment/local_vars.h 2015-03-12 09:36:23 UTC (rev 64837)
@@ -10,6 +10,8 @@
#define SQRT2 1.414214
+/* TODO: do not use long int to store row, col
+ * long int must be 8 byte but is often 4 byte, better use int r, c */
typedef struct {
int stream;
int next_stream;
@@ -18,8 +20,8 @@
long int * points;
float * elevation;
double * distance;
- unsigned long int init;
- unsigned long int outlet; /* outlet is cell from next stream */
+ long int init;
+ long int outlet; /* outlet is cell from next stream */
int last_cell_dir; /* to add outlet to vector */
float direction;
float length;
Modified: grass-addons/grass7/raster/r.stream.segment/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream.segment/main.c 2015-03-12 09:10:17 UTC (rev 64836)
+++ grass-addons/grass7/raster/r.stream.segment/main.c 2015-03-12 09:36:23 UTC (rev 64837)
@@ -164,6 +164,9 @@
ram_number_of_streams(streams, dirs, &ordered) + 1;
ram_build_streamlines(streams, dirs, elevation, number_of_streams);
+ /* TODO: either always create unique streams
+ * or keep current mechanism of identify_next_stream,
+ * then unique streams are not needed */
if (ordered) {
ram_create_map(&map_unique_streams, CELL_TYPE);
unique_streams = (CELL **) map_unique_streams.map;
@@ -217,6 +220,9 @@
seg_number_of_streams(streams, dirs, &ordered) + 1;
seg_build_streamlines(streams, dirs, elevation, number_of_streams);
+ /* TODO: either always create unique streams
+ * or keep current mechanism of identify_next_stream,
+ * then unique streams are not needed */
if (ordered) {
seg_create_map(&map_unique_streams, SROWS, SCOLS, number_of_segs,
CELL_TYPE);
@@ -235,7 +241,7 @@
for (i = 1; i < number_of_streams; ++i)
- G_message("%d %d %d", stream_attributes[i].stream,
+ G_debug(1, "%d %d %d", stream_attributes[i].stream,
stream_attributes[i].next_stream,
stream_attributes[i].last_cell_dir);
Modified: grass-addons/grass7/raster/r.stream.segment/stream_segment.c
===================================================================
--- grass-addons/grass7/raster/r.stream.segment/stream_segment.c 2015-03-12 09:10:17 UTC (rev 64836)
+++ grass-addons/grass7/raster/r.stream.segment/stream_segment.c 2015-03-12 09:36:23 UTC (rev 64837)
@@ -80,12 +80,12 @@
cell_down = i > number_of_cells - 1 - seg_length ?
number_of_cells - 1 - i : seg_length;
- r = (int)P[i] / ncols;
- c = (int)P[i] % ncols;
- r_up = (int)P[i - cell_up] / ncols;
- c_up = (int)P[i - cell_up] % ncols;
- r_down = (int)P[i + cell_down] / ncols;
- c_down = (int)P[i + cell_down] % ncols;
+ r = (int)(P[i] / ncols);
+ c = (int)(P[i] % ncols);
+ r_up = (int)(P[i - cell_up] / ncols);
+ c_up = (int)(P[i - cell_up] % ncols);
+ r_down = (int)(P[i + cell_down] / ncols);
+ c_down = (int)(P[i + cell_down] % ncols);
dir_down = calc_dir(r, c, r_down, c_down);
dir_up = calc_dir(r, c, r_up, c_up);
@@ -99,12 +99,12 @@
cell_down = i > number_of_cells - 1 - seg_length_short ?
number_of_cells - 1 - i : seg_length_short;
- r = (int)P[i] / ncols;
- c = (int)P[i] % ncols;
- r_up = (int)P[i - cell_up] / ncols;
- c_up = (int)P[i - cell_up] % ncols;
- r_down = (int)P[i + cell_down] / ncols;
- c_down = (int)P[i + cell_down] % ncols;
+ r = (int)(P[i] / ncols);
+ c = (int)(P[i] % ncols);
+ r_up = (int)(P[i - cell_up] / ncols);
+ c_up = (int)(P[i - cell_up] % ncols);
+ r_down = (int)(P[i + cell_down] / ncols);
+ c_down = (int)(P[i + cell_down] % ncols);
dir_down = calc_dir(r, c, r_down, c_down);
dir_up = calc_dir(r, c, r_up, c_up);
@@ -175,10 +175,10 @@
for (i = 0, prev_i = 0; i < number_of_cells + 1; ++i) {
if (streamline[i].decision == 1 || i == (number_of_cells - 1)) {
- r = (int)P[i] / ncols;
- c = (int)P[i] % ncols;
- r_up = (int)P[prev_i] / ncols;
- c_up = (int)P[prev_i] % ncols;
+ r = (int)(P[i] / ncols);
+ c = (int)(P[i] % ncols);
+ r_up = (int)(P[prev_i] / ncols);
+ c_up = (int)(P[prev_i] % ncols);
cur_stream->sector_breakpoints[sector_index] = i;
@@ -231,10 +231,10 @@
G_debug(3, "calc_tangents(): number_streams=%d", number_streams);
/*before calc tangents add rest of streamline attributes */
- r_up = (int)P[1] / ncols;
- c_up = (int)P[1] % ncols;
- r_down = (int)P[last_cell] / ncols;
- c_down = (int)P[last_cell] % ncols;
+ r_up = (int)(P[1] / ncols);
+ c_up = (int)(P[1] % ncols);
+ r_down = (int)(P[last_cell] / ncols);
+ c_down = (int)(P[last_cell] % ncols);
cur_stream->direction = calc_dir(r_up, c_up, r_down, c_down);
cur_stream->length = calc_length(cur_stream->distance, 1, last_cell);
@@ -248,7 +248,7 @@
}
/* find location of outlet in next stream */
- for (i = 1; i < SA[next_stream].number_of_cells; ++i) {
+ for (i = 0; i < SA[next_stream].number_of_cells; ++i) {
if (SA[next_stream].points[i] == outlet) {
reached_end = 0;
break;
@@ -259,6 +259,7 @@
if (reached_end) {
G_warning(_("Network topology error: cannot identify stream join for stream %d"),
cur_stream->stream);
+ G_fatal_error("stream %d, outlet %u", cur_stream->stream, outlet);
cur_stream->tangent = -1;
cur_stream->continuation = -1;
return 0;
@@ -268,12 +269,12 @@
cell_down = i >= (SA[next_stream].number_of_cells - seg_length) ?
SA[next_stream].number_of_cells - seg_length - 1 : seg_length;
- r = (int)SA[next_stream].points[i] / ncols;
- c = (int)SA[next_stream].points[i] % ncols;
- r_up = (int)SA[next_stream].points[i - cell_up] / ncols;
- c_up = (int)SA[next_stream].points[i - cell_up] % ncols;
- r_down = (int)SA[next_stream].points[i + cell_down] / ncols;
- c_down = (int)SA[next_stream].points[i + cell_down] % ncols;
+ r = (int)(SA[next_stream].points[i] / ncols);
+ c = (int)(SA[next_stream].points[i] % ncols);
+ r_up = (int)(SA[next_stream].points[i - cell_up] / ncols);
+ c_up = (int)(SA[next_stream].points[i - cell_up] % ncols);
+ r_down = (int)(SA[next_stream].points[i + cell_down] / ncols);
+ c_down = (int)(SA[next_stream].points[i + cell_down] % ncols);
cur_stream->continuation = calc_dir(r, c, r_down, c_down);
cur_stream->tangent = i == 1 ? -1 :
Modified: grass-addons/grass7/raster/r.stream.segment/stream_topology.c
===================================================================
--- grass-addons/grass7/raster/r.stream.segment/stream_topology.c 2015-03-12 09:10:17 UTC (rev 64836)
+++ grass-addons/grass7/raster/r.stream.segment/stream_topology.c 2015-03-12 09:36:23 UTC (rev 64837)
@@ -21,7 +21,11 @@
int trib_num = 0;
int i, j;
int next_r, next_c;
+ int streams_cell;
+ int same_id;
+ streams_cell = streams[r][c];
+ same_id = 0;
for (i = 1; i < 9; ++i) {
if (NOT_IN_REGION(i))
continue;
@@ -30,29 +34,23 @@
next_r = NR(i);
next_c = NC(i);
- if (streams[next_r][next_c] > 0 && dirs[next_r][next_c] == j)
+ if (streams[next_r][next_c] > 0 && dirs[next_r][next_c] == j) {
trib_num++;
+ if (streams[next_r][next_c] == streams_cell)
+ same_id++;
+ }
}
- if (trib_num > 1)
- for (i = 1; i < 9; ++i) {
- if (NOT_IN_REGION(i))
- continue;
-
- j = DIAG(i);
- next_r = NR(i);
- next_c = NC(i);
-
- if (streams[next_r][next_c] == streams[r][c] &&
- dirs[next_r][next_c] == j)
- trib_num--;
- }
-
if (trib_num > 5)
G_fatal_error(_("Error finding inits. Stream and direction maps probably do not match"));
if (trib_num > 3)
G_warning(_("Stream network may be too dense"));
+ if (same_id > 1)
+ G_warning(_("Too many stream segments with the same ID %d"), streams_cell);
+ else if (same_id == 1)
+ trib_num = 1;
+
return trib_num;
} /* end trib_num */
@@ -64,8 +62,10 @@
int i, j;
int next_r, next_c;
int streams_cell, streams_next_cell, dirs_next_cell;
+ int same_id;
Segment_get(streams, &streams_cell, r, c);
+ same_id = 0;
for (i = 1; i < 9; ++i) {
if (NOT_IN_REGION(i))
continue;
@@ -77,31 +77,24 @@
Segment_get(streams, &streams_next_cell, next_r, next_c);
Segment_get(dirs, &dirs_next_cell, next_r, next_c);
- if (streams_next_cell > 0 && dirs_next_cell == j)
+ if (streams_next_cell > 0 && dirs_next_cell == j) {
trib_num++;
+ if (streams_next_cell == streams_cell)
+ same_id++;
+ }
}
- if (trib_num > 1)
- for (i = 1; i < 9; ++i) {
- if (NOT_IN_REGION(i))
- continue;
-
- j = DIAG(i);
- next_r = NR(i);
- next_c = NC(i);
-
- Segment_get(streams, &streams_next_cell, next_r, next_c);
- Segment_get(dirs, &dirs_next_cell, next_r, next_c);
-
- if (streams_next_cell == streams_cell && dirs_next_cell == j)
- trib_num--;
- }
-
if (trib_num > 5)
G_fatal_error(_("Error finding inits. Stream and direction maps probably do not match"));
if (trib_num > 3)
G_warning(_("Stream network may be too dense"));
+
+ if (same_id > 1)
+ G_warning(_("Too many stream segments with the same ID %d"), streams_cell);
+ else if (same_id == 1)
+ trib_num = 1;
+
return trib_num;
} /* end trib_num */
@@ -112,9 +105,9 @@
int stream_num = 0;
int one = 0, two = 0;
- for (r = 0; r < nrows; ++r)
- for (c = 0; c < ncols; ++c)
- if (streams[r][c] > 0)
+ for (r = 0; r < nrows; ++r) {
+ for (c = 0; c < ncols; ++c) {
+ if (streams[r][c] > 0) {
if (ram_trib_nums(r, c, streams, dirs) != 1) {
stream_num++;
if (streams[r][c] == 1)
@@ -122,6 +115,9 @@
if (streams[r][c] == 2)
two++;
}
+ }
+ }
+ }
*ordered = (one > 1 || two > 1) ? 1 : 0;
/* if there is more than 1 stream with identifier 1 or 2 network is ordered */
@@ -135,10 +131,10 @@
int one = 0, two = 0;
int streams_cell;
- for (r = 0; r < nrows; ++r)
+ for (r = 0; r < nrows; ++r) {
for (c = 0; c < ncols; ++c) {
Segment_get(streams, &streams_cell, r, c);
- if (streams_cell > 0)
+ if (streams_cell > 0) {
if (seg_trib_nums(r, c, streams, dirs) != 1) {
stream_num++;
if (streams_cell == 1)
@@ -146,7 +142,9 @@
if (streams_cell == 2)
two++;
}
+ }
}
+ }
*ordered = (one > 1 || two > 1) ? 1 : 0;
/* if there is more than 1 stream with identifier 1 or 2 network is ordered */
@@ -166,12 +164,12 @@
stream_attributes =
(STREAM *) G_malloc(number_of_streams * sizeof(STREAM));
+
G_message(_("Finding inits..."));
SA = stream_attributes;
-
- for (r = 0; r < nrows; ++r)
- for (c = 0; c < ncols; ++c)
- if (streams[r][c])
+ for (r = 0; r < nrows; ++r) {
+ for (c = 0; c < ncols; ++c) {
+ if (streams[r][c]) {
if (ram_trib_nums(r, c, streams, dirs) != 1) { /* adding inits */
if (stream_num > number_of_streams)
G_fatal_error(_("Error finding inits. Stream and direction maps probably do not match"));
@@ -180,12 +178,14 @@
SA[stream_num].init = INDEX(r, c);
stream_num++;
}
+ }
+ }
+ }
for (i = 1; i < stream_num; ++i) {
-
- r = (int)SA[i].init / ncols;
- c = (int)SA[i].init % ncols;
+ r = (int)(SA[i].init / ncols);
+ c = (int)(SA[i].init % ncols);
SA[i].order = streams[r][c];
SA[i].number_of_cells = 0;
do {
@@ -196,7 +196,7 @@
break;
r = NR(d);
c = NC(d);
- } while (streams[r][c] == SA[i].order);
+ } while (streams[r][c] == SA[i].order && ram_trib_nums(r, c, streams, dirs) == 1);
SA[i].number_of_cells += 2; /* add two extra points for init+ and outlet+ */
}
@@ -210,8 +210,8 @@
SA[i].distance = (double *)
G_malloc((SA[i].number_of_cells) * sizeof(double));
- r = (int)SA[i].init / ncols;
- c = (int)SA[i].init % ncols;
+ r = (int)(SA[i].init / ncols);
+ c = (int)(SA[i].init % ncols);
contrib_cell = ram_find_contributing_cell(r, c, dirs, elevation);
prev_r = NR(contrib_cell);
prev_c = NC(contrib_cell);
@@ -254,7 +254,7 @@
cell_num++;
if (cell_num > SA[i].number_of_cells)
G_fatal_error(_("To many points in stream line"));
- } while (streams[r][c] == SA[i].order);
+ } while (streams[r][c] == SA[i].order && ram_trib_nums(r, c, streams, dirs) == 1);
if (SA[i].elevation[0] == -99999)
SA[i].elevation[0] = 2 * SA[i].elevation[1] - SA[i].elevation[2];
@@ -280,15 +280,14 @@
stream_attributes =
(STREAM *) G_malloc(number_of_streams * sizeof(STREAM));
+
G_message(_("Finding inits..."));
SA = stream_attributes;
-
- /* finding inits */
- for (r = 0; r < nrows; ++r)
+ for (r = 0; r < nrows; ++r) {
for (c = 0; c < ncols; ++c) {
Segment_get(streams, &streams_cell, r, c);
- if (streams_cell)
+ if (streams_cell) {
if (seg_trib_nums(r, c, streams, dirs) != 1) { /* adding inits */
if (stream_num > number_of_streams)
G_fatal_error(_("Error finding inits. Stream and direction maps probably do not match"));
@@ -297,13 +296,14 @@
SA[stream_num].init = INDEX(r, c);
stream_num++;
}
+ }
}
+ }
- /* building streamline */
for (i = 1; i < stream_num; ++i) {
- r = (int)SA[i].init / ncols;
- c = (int)SA[i].init % ncols;
+ r = (int)(SA[i].init / ncols);
+ c = (int)(SA[i].init % ncols);
Segment_get(streams, &streams_cell, r, c);
SA[i].order = streams_cell;
SA[i].number_of_cells = 0;
@@ -318,7 +318,7 @@
r = NR(d);
c = NC(d);
Segment_get(streams, &streams_cell, r, c);
- } while (streams_cell == SA[i].order);
+ } while (streams_cell == SA[i].order && seg_trib_nums(r, c, streams, dirs) == 1);
SA[i].number_of_cells += 2; /* add two extra points for point before init and after outlet */
}
@@ -332,8 +332,8 @@
SA[i].distance = (double *)
G_malloc((SA[i].number_of_cells) * sizeof(double));
- r = (int)SA[i].init / ncols;
- c = (int)SA[i].init % ncols;
+ r = (int)(SA[i].init / ncols);
+ c = (int)(SA[i].init % ncols);
contrib_cell = seg_find_contributing_cell(r, c, dirs, elevation);
prev_r = NR(contrib_cell);
prev_c = NC(contrib_cell);
@@ -385,7 +385,7 @@
if (cell_num > SA[i].number_of_cells)
G_fatal_error(_("To much points in stream line"));
Segment_get(streams, &streams_cell, r, c);
- } while (streams_cell == SA[i].order);
+ } while (streams_cell == SA[i].order && seg_trib_nums(r, c, streams, dirs) == 1);
if (SA[i].elevation[0] == -99999)
SA[i].elevation[0] = 2 * SA[i].elevation[1] - SA[i].elevation[2];
@@ -450,8 +450,8 @@
for (i = 1; i < number_of_streams; ++i) {
for (j = 1; j < SA[i].number_of_cells - 1; ++j) {
- r = (int)SA[i].points[j] / ncols;
- c = (int)SA[i].points[j] % ncols;
+ r = (int)(SA[i].points[j] / ncols);
+ c = (int)(SA[i].points[j] % ncols);
unique_streams[r][c] = SA[i].stream;
}
}
@@ -468,8 +468,8 @@
for (i = 1; i < number_of_streams; ++i) {
for (j = 1; j < SA[i].number_of_cells - 1; ++j) {
- r = (int)SA[i].points[j] / ncols;
- c = (int)SA[i].points[j] % ncols;
+ r = (int)(SA[i].points[j] / ncols);
+ c = (int)(SA[i].points[j] % ncols);
Segment_put(unique_streams, &SA[i].stream, r, c);
}
}
@@ -478,47 +478,67 @@
int ram_identify_next_stream(CELL **streams, int number_of_streams)
{
- int r, c;
- int i;
+ int i, j, k, n;
STREAM *SA;
SA = stream_attributes;
for (i = 1; i < number_of_streams; ++i) {
- if (SA[i].points[SA[i].number_of_cells - 1] == -1) {
- SA[i].next_stream = -1;
- SA[i].outlet = -1;
+ SA[i].next_stream = -1;
+ SA[i].outlet = SA[i].points[SA[i].number_of_cells - 1];
+
+ if (SA[i].outlet >= 0) {
+ /* go through all streams
+ * do not use raster stream ID because it might not be unique */
+ for (j = 1; j < number_of_streams; ++j) {
+ /* skip first point = contributing cell and
+ * last point = outlet (next stream of next stream) */
+ n = SA[j].number_of_cells - 1;
+ for (k = 1; k < n; k++) {
+ if (SA[j].points[k] == SA[i].outlet) {
+ SA[i].next_stream = j;
+ break;
+ }
+ }
+ if (SA[i].next_stream > 0)
+ break;
+ }
}
- else {
- r = (int)SA[i].points[SA[i].number_of_cells - 1] / ncols;
- c = (int)SA[i].points[SA[i].number_of_cells - 1] % ncols;
- SA[i].next_stream = streams[r][c];
- SA[i].outlet = SA[i].points[SA[i].number_of_cells - 1];
- }
}
+
return 0;
}
int seg_identify_next_stream(SEGMENT *streams, int number_of_streams)
{
- int r, c;
- int i;
+ int i, j, k, n;
STREAM *SA;
SA = stream_attributes;
for (i = 1; i < number_of_streams; ++i) {
- if (SA[i].points[SA[i].number_of_cells - 1] == -1) {
- SA[i].next_stream = -1;
- SA[i].outlet = -1;
+ SA[i].next_stream = -1;
+ SA[i].outlet = SA[i].points[SA[i].number_of_cells - 1];
+
+ if (SA[i].outlet >= 0) {
+ /* go through all streams
+ * do not use raster stream ID because it might not be unique */
+ for (j = 1; j < number_of_streams; ++j) {
+ /* skip first point = contributing cell and
+ * last point = outlet (next stream of next stream) */
+ n = SA[j].number_of_cells - 1;
+ for (k = 1; k < n; k++) {
+ if (SA[j].points[k] == SA[i].outlet) {
+ SA[i].next_stream = j;
+ break;
+ }
+ }
+ if (SA[i].next_stream > 0)
+ break;
+ }
}
- else {
- r = (int)SA[i].points[SA[i].number_of_cells - 1] / ncols;
- c = (int)SA[i].points[SA[i].number_of_cells - 1] % ncols;
- Segment_get(streams, &SA[i].next_stream, r, c);
- SA[i].outlet = SA[i].points[SA[i].number_of_cells - 1];
- }
}
+
return 0;
}
Modified: grass-addons/grass7/raster/r.stream.segment/stream_vector.c
===================================================================
--- grass-addons/grass7/raster/r.stream.segment/stream_vector.c 2015-03-12 09:10:17 UTC (rev 64836)
+++ grass-addons/grass7/raster/r.stream.segment/stream_vector.c 2015-03-12 09:36:23 UTC (rev 64837)
@@ -16,7 +16,7 @@
dbDriver *driver;
dbHandle handle;
char *cat_col_name = "cat";
- char buf[1000];
+ char buf[1000], buf2[1000];
int sector_category, segment, sector, order;
double direction, azimuth, length, stright, sinusoid;
@@ -44,8 +44,8 @@
c = NC(d);
}
else {
- r = (int)SA[i].points[k] / ncols;
- c = (int)SA[i].points[k] % ncols;
+ r = (int)(SA[i].points[k] / ncols);
+ c = (int)(SA[i].points[k] % ncols);
}
easting = window.west + (c + .5) * window.ew_res;
northing = window.north - (r + .5) * window.ns_res;
@@ -127,12 +127,71 @@
azimuth = RAD2DEG(azimuth);
}
+#if 0
sprintf(buf, "insert into %s values( %d, %d, %d, %d, "
"%f, %f, %f, %f, %f, "
"%f, %f, %f, %f)", Fi->table, sector_category, segment, sector, order, /*4 */
direction, azimuth, length, stright, sinusoid, /*9 */
elev_max, elev_min, drop, gradient); /*13 */
+#endif
+
+ sprintf(buf, "insert into %s values( %d, %d, %d, %d, ",
+ Fi->table, sector_category, segment, sector, order);
+
+ if (Rast_is_d_null_value(&direction))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", direction);
+ strcat(buf, buf2);
+ if (Rast_is_d_null_value(&azimuth))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", azimuth);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&length))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", length);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&stright))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", stright);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&sinusoid))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", sinusoid);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&elev_max))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", elev_max);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&elev_min))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", elev_min);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&drop))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", drop);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&gradient))
+ sprintf(buf2, "null )");
+ else
+ sprintf(buf2, "%g )", gradient);
+ strcat(buf, buf2);
+
db_set_string(&db_sql, buf);
if (db_execute_immediate(driver, &db_sql) != DB_OK) {
@@ -171,7 +230,7 @@
dbDriver *driver;
dbHandle handle;
char *cat_col_name = "cat";
- char buf[1000];
+ char buf[1000], buf2[1000];
/* variables to store table attributes */
int last;
@@ -302,6 +361,7 @@
next_azimuth = RAD2DEG(next_azimuth);
}
+#if 0
sprintf(buf, "insert into %s values( %d, %d, %d, %d, %d, "
"%f, %f, %f, %f, %f, "
"%f, %f, %f, %f, "
@@ -311,7 +371,119 @@
elev_max, elev_min, drop, gradient, /*14 */
out_direction, out_azimuth, out_length, out_drop, out_gradient, /*19 */
tangent_dir, tangent_azimuth, next_direction, next_azimuth); /*23 */
+#endif
+ sprintf(buf, "insert into %s values( %d, %d, %d, %d, %d, ",
+ Fi->table, i, segment, next_segment, order, next_order);
+
+ if (Rast_is_d_null_value(&direction))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", direction);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&azimuth))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", azimuth);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&length))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", length);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&stright))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", stright);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&sinusoid))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", sinusoid);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&elev_max))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", elev_max);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&elev_min))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", elev_min);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&drop))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", drop);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&gradient))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", gradient);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&out_direction))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", out_direction);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&out_azimuth))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", out_azimuth);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&out_length))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", out_length);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&out_drop))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", out_drop);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&out_gradient))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", out_gradient);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&tangent_dir))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", tangent_dir);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&tangent_azimuth))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", tangent_azimuth);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&next_direction))
+ sprintf(buf2, "null, ");
+ else
+ sprintf(buf2, "%g, ", next_direction);
+ strcat(buf, buf2);
+
+ if (Rast_is_d_null_value(&next_azimuth))
+ sprintf(buf2, "null )");
+ else
+ sprintf(buf2, "%g )", next_azimuth);
+ strcat(buf, buf2);
+
db_set_string(&db_sql, buf);
if (db_execute_immediate(driver, &db_sql) != DB_OK) {
More information about the grass-commit
mailing list