00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <grass/gis.h>
00038 #include <grass/Vect.h>
00039
00040 int Vect__Read_line_nat (struct Map_info *, struct line_pnts *, struct line_cats *, long);
00041
00042
00043
00044
00045
00046
00047
00048
00049 int
00050 V1_read_line_nat (
00051 struct Map_info *Map,
00052 struct line_pnts *Points,
00053 struct line_cats *Cats,
00054 long offset)
00055 {
00056 return Vect__Read_line_nat (Map, Points, Cats, offset);
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066 int
00067 V1_read_next_line_nat (
00068 struct Map_info *Map,
00069 struct line_pnts *line_p,
00070 struct line_cats *line_c)
00071 {
00072 int itype;
00073 long offset;
00074 BOUND_BOX lbox, mbox;
00075
00076 G_debug (3, "V1_read_next_line_nat()" );
00077
00078 if (Map->Constraint_region_flag)
00079 Vect_get_constraint_box ( Map, &mbox );
00080
00081 while (1)
00082 {
00083 offset = dig_ftell ( &(Map->dig_fp) );
00084 itype = Vect__Read_line_nat (Map, line_p, line_c, offset);
00085 if (itype < 0)
00086 return (itype);
00087
00088 if (itype == 0)
00089 continue;
00090
00091
00092
00093
00094 if (Map->Constraint_type_flag)
00095 {
00096 if (!(itype & Map->Constraint_type))
00097 continue;
00098 }
00099
00100
00101 if (Map->Constraint_region_flag) {
00102 Vect_line_box ( line_p, &lbox );
00103
00104 if ( !Vect_box_overlap (&lbox, &mbox) )
00105 continue;
00106 }
00107
00108 return (itype);
00109 }
00110
00111
00112 }
00113
00114
00115
00116
00117 int
00118 V2_read_line_nat (
00119 struct Map_info *Map,
00120 struct line_pnts *line_p,
00121 struct line_cats *line_c,
00122 int line)
00123 {
00124 P_LINE *Line;
00125
00126 G_debug (3, "V2_read_line_nat(): line = %d", line);
00127
00128
00129 Line = Map->plus.Line[line];
00130
00131 if ( Line == NULL )
00132 G_fatal_error ( "Attempt to read dead line %d", line );
00133
00134 return Vect__Read_line_nat (Map, line_p, line_c, Line->offset);
00135 }
00136
00137
00138
00139
00140 int
00141 V2_read_next_line_nat (
00142 struct Map_info *Map,
00143 struct line_pnts *line_p,
00144 struct line_cats *line_c)
00145 {
00146 register int line;
00147 register P_LINE *Line;
00148 BOUND_BOX lbox, mbox;
00149
00150 G_debug (3, "V2_read_next_line_nat()");
00151
00152 if (Map->Constraint_region_flag)
00153 Vect_get_constraint_box ( Map, &mbox );
00154
00155 while (1)
00156 {
00157 line = Map->next_line;
00158
00159 if (line > Map->plus.n_lines)
00160 return (-2);
00161
00162 Line = Map->plus.Line[line];
00163 if ( Line == NULL) {
00164 Map->next_line++;
00165 continue;
00166 }
00167
00168 if ((Map->Constraint_type_flag && !(Line->type & Map->Constraint_type)))
00169 {
00170 Map->next_line++;
00171 continue;
00172 }
00173
00174 if (Map->Constraint_region_flag) {
00175 Vect_get_line_box ( Map, line, &lbox );
00176 if ( !Vect_box_overlap (&lbox, &mbox) )
00177 {
00178 Map->next_line++;
00179 continue;
00180 }
00181 }
00182
00183 return V2_read_line_nat (Map, line_p, line_c, Map->next_line++);
00184 }
00185
00186
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 int
00199 Vect__Read_line_nat (
00200 struct Map_info *Map,
00201 struct line_pnts *p,
00202 struct line_cats *c,
00203 long offset)
00204 {
00205 int i, dead = 0;
00206 int n_points;
00207 long size;
00208 int n_cats, do_cats;
00209 int type;
00210 char rhead, nc;
00211 short field;
00212
00213 G_debug (3, "Vect__Read_line_nat: offset = %ld", offset);
00214
00215 Map->head.last_offset = offset;
00216
00217
00218 dig_set_cur_port (&(Map->head.port));
00219
00220 dig_fseek ( &(Map->dig_fp), offset, 0);
00221
00222 if (0 >= dig__fread_port_C (&rhead, 1, &(Map->dig_fp) ))
00223 return (-2);
00224
00225 if ( !(rhead & 0x01) )
00226 dead = 1;
00227
00228 if ( rhead & 0x02 )
00229 do_cats = 1;
00230 else
00231 do_cats = 0;
00232
00233 rhead >>= 2;
00234 type = dig_type_from_store ( (int) rhead );
00235
00236 G_debug (3, " type = %d, do_cats = %d dead = %d", type, do_cats, dead);
00237
00238 if ( c != NULL )
00239 c->n_cats = 0;
00240
00241 if ( do_cats ) {
00242 if ( Map->head.Version_Minor == 1 ) {
00243 if (0 >= dig__fread_port_I ( &n_cats, 1, &(Map->dig_fp) )) return (-2);
00244 } else {
00245 if (0 >= dig__fread_port_C (&nc, 1, &(Map->dig_fp) )) return (-2);
00246 n_cats = (int) nc;
00247 }
00248 G_debug (3, " n_cats = %d", n_cats);
00249
00250 if ( c != NULL )
00251 {
00252 c->n_cats = n_cats;
00253 if (n_cats > 0)
00254 {
00255 if (0 > dig_alloc_cats (c, (int) n_cats + 1))
00256 return (-1);
00257
00258 if ( Map->head.Version_Minor == 1 ) {
00259 if (0 >= dig__fread_port_I (c->field, n_cats, &(Map->dig_fp) )) return (-2);
00260 } else {
00261 for (i = 0; i < n_cats; i++) {
00262 if (0 >= dig__fread_port_S (&field, 1, &(Map->dig_fp) )) return (-2);
00263 c->field[i] = (int) field;
00264 }
00265 }
00266 if (0 >= dig__fread_port_I (c->cat, n_cats, &(Map->dig_fp) )) return (-2);
00267
00268 }
00269 }
00270 else
00271 {
00272 if ( Map->head.Version_Minor == 1 ) {
00273 size = ( 2 * PORT_INT ) * n_cats;
00274 } else {
00275 size = ( PORT_SHORT + PORT_INT ) * n_cats;
00276 }
00277
00278 dig_fseek ( &(Map->dig_fp), size, SEEK_CUR);
00279 }
00280 }
00281
00282 if ( type & GV_POINTS ) {
00283 n_points = 1;
00284 } else {
00285 if (0 >= dig__fread_port_I (&n_points, 1, &(Map->dig_fp) )) return (-2);
00286 }
00287
00288 #ifdef GDEBUG
00289 G_debug (3, " n_points = %d", n_points);
00290 #endif
00291
00292 if ( p != NULL ) {
00293 if (0 > dig_alloc_points (p, n_points + 1))
00294 return (-1);
00295
00296 p->n_points = n_points;
00297 if (0 >= dig__fread_port_D (p->x, n_points, &(Map->dig_fp) )) return (-2);
00298 if (0 >= dig__fread_port_D (p->y, n_points, &(Map->dig_fp) )) return (-2);
00299
00300 if (Map->head.with_z) {
00301 if (0 >= dig__fread_port_D (p->z, n_points, &(Map->dig_fp) )) return (-2);
00302 } else {
00303 for ( i = 0; i < n_points; i++ )
00304 p->z[i] = 0.0;
00305 }
00306 } else {
00307 if (Map->head.with_z)
00308 size = n_points * 3 * PORT_DOUBLE;
00309 else
00310 size = n_points * 2 * PORT_DOUBLE;
00311
00312 dig_fseek ( &(Map->dig_fp), size, SEEK_CUR);
00313 }
00314
00315 G_debug (3, " off = %ld", dig_ftell( &(Map->dig_fp) ));
00316
00317 if ( dead ) return 0;
00318
00319 return (type);
00320 }
00321