@@ -75,6 +75,7 @@ struct netlink {
75
75
int32_t uslinkno1;
76
76
int32_t uslinkno2;
77
77
double doutend;
78
+ double uscontarea;
78
79
double x, y;
79
80
};
80
81
OGRLayerH hLayer, hLayerpt;
@@ -83,7 +84,7 @@ OGRGeometryH hGeometry, hGeometrypt;
83
84
84
85
netlink* allinks;
85
86
86
- void CheckPoint (int thelink, double downout, double mindist)
87
+ void CheckPoint (int thelink, double downout, double mindist, double minarea )
87
88
{
88
89
int istream=0 ;
89
90
while (linknos[istream] != thelink && istream < nstreams) {
@@ -92,33 +93,37 @@ void CheckPoint(int thelink, double downout, double mindist)
92
93
if (istream < nstreams) // Here a stream was found. This traps the passing over streams with none upstream
93
94
{
94
95
if (allinks[istream].doutend - downout > mindist) {
95
- // printf("%d, %g, %g\n", linknos[istream], allinks[istream].x, allinks[istream].y);
96
- hGeometrypt = OGR_G_CreateGeometry (wkbPoint);// create geometry
97
- OGRFeatureH hFeaturept = OGR_F_Create (OGR_L_GetLayerDefn (hLayerpt)); // create new feature with null fields and no geometry
98
- OGR_F_SetFieldInteger (hFeaturept, 0 , linknos[istream]);
99
- OGR_F_SetFieldInteger (hFeaturept, 1 , allinks[istream].dslinkno );
100
- OGR_F_SetFieldInteger (hFeaturept, 2 , allinks[istream].uslinkno1 );
101
- OGR_F_SetFieldInteger (hFeaturept, 3 , allinks[istream].uslinkno2 );
102
- OGR_F_SetFieldDouble (hFeaturept, 4 , allinks[istream].doutend );
103
- OGR_F_SetFieldInteger (hFeaturept, 5 , gwcount);
104
- gwcount = gwcount + 1 ;
105
- OGR_G_SetPoint_2D (hGeometrypt, 0 , allinks[istream].x , allinks[istream].y );
106
- OGR_F_SetGeometry (hFeaturept, hGeometrypt);
107
- OGR_G_DestroyGeometry (hGeometrypt);
108
- OGR_L_CreateFeature (hLayerpt, hFeaturept);
109
- OGR_F_Destroy (hFeaturept);
110
-
111
- downout = allinks[istream].doutend ;
96
+ if (allinks[istream].uscontarea > minarea) { // Only write if min area is exceeded
97
+ // printf("%d, %g, %g\n", linknos[istream], allinks[istream].x, allinks[istream].y);
98
+ hGeometrypt = OGR_G_CreateGeometry (wkbPoint);// create geometry
99
+ OGRFeatureH hFeaturept = OGR_F_Create (OGR_L_GetLayerDefn (hLayerpt)); // create new feature with null fields and no geometry
100
+ OGR_F_SetFieldInteger (hFeaturept, 0 , linknos[istream]);
101
+ OGR_F_SetFieldInteger (hFeaturept, 1 , allinks[istream].dslinkno );
102
+ OGR_F_SetFieldInteger (hFeaturept, 2 , allinks[istream].uslinkno1 );
103
+ OGR_F_SetFieldInteger (hFeaturept, 3 , allinks[istream].uslinkno2 );
104
+ OGR_F_SetFieldDouble (hFeaturept, 4 , allinks[istream].doutend );
105
+ OGR_F_SetFieldInteger (hFeaturept, 5 , gwcount);
106
+ gwcount = gwcount + 1 ;
107
+ OGR_G_SetPoint_2D (hGeometrypt, 0 , allinks[istream].x , allinks[istream].y );
108
+ OGR_F_SetGeometry (hFeaturept, hGeometrypt);
109
+ OGR_G_DestroyGeometry (hGeometrypt);
110
+ OGR_L_CreateFeature (hLayerpt, hFeaturept);
111
+ OGR_F_Destroy (hFeaturept);
112
+
113
+ downout = allinks[istream].doutend ;
114
+ }
115
+ }
116
+ if (allinks[istream].uscontarea > minarea) { // Only recurse up if minarea is satisified
117
+ if (allinks[istream].uslinkno1 >= 0 ) CheckPoint (allinks[istream].uslinkno1 , downout, mindist, minarea);
118
+ if (allinks[istream].uslinkno2 >= 0 ) CheckPoint (allinks[istream].uslinkno2 , downout, mindist, minarea);
112
119
}
113
- if (allinks[istream].uslinkno1 >= 0 ) CheckPoint (allinks[istream].uslinkno1 , downout, mindist);
114
- if (allinks[istream].uslinkno2 >= 0 ) CheckPoint (allinks[istream].uslinkno2 , downout, mindist);
115
120
}
116
121
}
117
122
118
123
119
124
// int catchoutlets(char *pfile, char *streamnetsrc, char *streamnetlyr, char *outletsdatasrc, char *outletslayer, int lyrno, float maxdist)
120
125
121
- int catchoutlets (char *pfile, char *streamnetsrc, char *outletsdatasrc, double mindist, int gwstartno)
126
+ int catchoutlets (char *pfile, char *streamnetsrc, char *outletsdatasrc, double mindist, int gwstartno, double minarea )
122
127
{
123
128
124
129
MPI_Init (NULL ,NULL );{
@@ -257,8 +262,9 @@ int catchoutlets(char *pfile, char *streamnetsrc, char *outletsdatasrc, double m
257
262
OGR_Fld_SetWidth (hFieldDefn, 10 ); // set field width
258
263
OGR_L_CreateField (hLayerpt, hFieldDefn, 0 );
259
264
265
+ // Fields we use but do not add to new feature class
260
266
int32_t doutstartfield = OGR_FD_GetFieldIndex (hFDefn, " DOUTSTART" );
261
- // Dont need to create new field for this
267
+ int32_t uscontareafield = OGR_FD_GetFieldIndex (hFDefn, " USContArea " );
262
268
263
269
int32_t istream = 0 ;
264
270
gwcount = gwstartno; // Initialize count
@@ -293,6 +299,7 @@ int catchoutlets(char *pfile, char *streamnetsrc, char *outletsdatasrc, double m
293
299
OGR_G_GetPoint (hGeometry, num_points-1 , &X1, &Y1, &Z1);
294
300
allinks[istream].doutend = OGR_F_GetFieldAsDouble (hFeature, doutstartfield); // Note here start field
295
301
}
302
+ allinks[istream].uscontarea = OGR_F_GetFieldAsDouble (hFeature, uscontareafield);
296
303
allinks[istream].x = X1;
297
304
allinks[istream].y = Y1;
298
305
// printf("%d, %lf, %lf,%lf\n", istream, X1, Y1, Z1);
@@ -342,8 +349,8 @@ int catchoutlets(char *pfile, char *streamnetsrc, char *outletsdatasrc, double m
342
349
OGR_F_Destroy (hFeaturept);
343
350
double downout = 0.0 ;
344
351
// Recursive calls to traverse up
345
- if (allinks[istream].uslinkno1 >= 0 ) CheckPoint (allinks[istream].uslinkno1 , downout,mindist);
346
- if (allinks[istream].uslinkno2 >= 0 ) CheckPoint (allinks[istream].uslinkno2 , downout,mindist);
352
+ if (allinks[istream].uslinkno1 >= 0 ) CheckPoint (allinks[istream].uslinkno1 , downout,mindist,minarea );
353
+ if (allinks[istream].uslinkno2 >= 0 ) CheckPoint (allinks[istream].uslinkno2 , downout,mindist,minarea );
347
354
}
348
355
}
349
356
}
0 commit comments