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 "gis.h"
00038 #include "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, size;
00207 int n_cats, do_cats;
00208 int type;
00209 char rhead, nc;
00210 short field;
00211
00212 G_debug (3, "Vect__Read_line_nat: offset = %ld", offset);
00213
00214 Map->head.last_offset = offset;
00215
00216
00217 dig_set_cur_port (&(Map->head.port));
00218
00219 dig_fseek ( &(Map->dig_fp), offset, 0);
00220
00221 if (0 >= dig__fread_port_C (&rhead, 1, &(Map->dig_fp) ))
00222 return (-2);
00223
00224 if ( !(rhead & 0x01) )
00225 dead = 1;
00226
00227 if ( rhead & 0x02 )
00228 do_cats = 1;
00229 else
00230 do_cats = 0;
00231
00232 rhead >>= 2;
00233 type = dig_type_from_store ( (int) rhead );
00234
00235 G_debug (3, " type = %d, do_cats = %d dead = %d", type, do_cats, dead);
00236
00237 if ( c != NULL )
00238 c->n_cats = 0;
00239
00240 if ( do_cats ) {
00241 if ( Map->head.Version_Minor == 1 ) {
00242 if (0 >= dig__fread_port_I ( &n_cats, 1, &(Map->dig_fp) )) return (-2);
00243 } else {
00244 if (0 >= dig__fread_port_C (&nc, 1, &(Map->dig_fp) )) return (-2);
00245 n_cats = (int) nc;
00246 }
00247 G_debug (3, " n_cats = %d", n_cats);
00248
00249 if ( c != NULL )
00250 {
00251 c->n_cats = n_cats;
00252 if (n_cats > 0)
00253 {
00254 if (0 > dig_alloc_cats (c, (int) n_cats + 1))
00255 return (-1);
00256
00257 if ( Map->head.Version_Minor == 1 ) {
00258 if (0 >= dig__fread_port_I (c->field, n_cats, &(Map->dig_fp) )) return (-2);
00259 } else {
00260 for (i = 0; i < n_cats; i++) {
00261 if (0 >= dig__fread_port_S (&field, 1, &(Map->dig_fp) )) return (-2);
00262 c->field[i] = (int) field;
00263 }
00264 }
00265 if (0 >= dig__fread_port_I (c->cat, n_cats, &(Map->dig_fp) )) return (-2);
00266
00267 }
00268 }
00269 else
00270 {
00271 if ( Map->head.Version_Minor == 1 ) {
00272 size = ( 2 * PORT_INT ) * n_cats;
00273 } else {
00274 size = ( PORT_SHORT + PORT_INT ) * n_cats;
00275 }
00276
00277 dig_fseek ( &(Map->dig_fp), size, SEEK_CUR);
00278 }
00279 }
00280
00281 if ( type & GV_POINTS ) {
00282 n_points = 1;
00283 } else {
00284 if (0 >= dig__fread_port_I (&n_points, 1, &(Map->dig_fp) )) return (-2);
00285 }
00286
00287 #ifdef GDEBUG
00288 G_debug (3, " n_points = %d", n_points);
00289 #endif
00290
00291 if ( p != NULL ) {
00292 if (0 > dig_alloc_points (p, n_points + 1))
00293 return (-1);
00294
00295 p->n_points = n_points;
00296 if (0 >= dig__fread_port_D (p->x, n_points, &(Map->dig_fp) )) return (-2);
00297 if (0 >= dig__fread_port_D (p->y, n_points, &(Map->dig_fp) )) return (-2);
00298
00299 if (Map->head.with_z) {
00300 if (0 >= dig__fread_port_D (p->z, n_points, &(Map->dig_fp) )) return (-2);
00301 } else {
00302 for ( i = 0; i < n_points; i++ )
00303 p->z[i] = 0.0;
00304 }
00305 } else {
00306 if (Map->head.with_z)
00307 size = n_points * 3 * PORT_DOUBLE;
00308 else
00309 size = n_points * 2 * PORT_DOUBLE;
00310
00311 dig_fseek ( &(Map->dig_fp), size, SEEK_CUR);
00312 }
00313
00314 G_debug (3, " off = %ld", dig_ftell( &(Map->dig_fp) ));
00315
00316 if ( dead ) return 0;
00317
00318 return (type);
00319 }
00320