Changeset 63378
- Timestamp:
- Dec 5, 2014, 8:26:14 AM (10 years ago)
- File:
-
- 1 edited
-
grass/trunk/raster/r.in.gdal/main.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
grass/trunk/raster/r.in.gdal/main.c
r63019 r63378 62 62 GDALRasterBandH hBand; 63 63 double adfGeoTransform[6]; 64 int n_bands; 64 65 int force_imagery = FALSE; 65 66 char error_msg[8096]; … … 98 99 parm.band->key = "band"; 99 100 parm.band->type = TYPE_INTEGER; 101 parm.band->multiple = YES; 100 102 parm.band->required = NO; 101 parm.band->description = _("Band to select (default is all bands)");103 parm.band->description = _("Band(s) to select (default is all bands)"); 102 104 103 105 parm.memory = G_define_option(); … … 507 509 /* Do we want to generate a simple raster, or an imagery group? */ 508 510 /* -------------------------------------------------------------------- */ 509 if ((GDALGetRasterCount(hDS) > 1 && parm.band->answer == NULL) 511 n_bands = 0; 512 if (parm.band->answer != NULL) { 513 while (parm.band->answers[n_bands]) 514 n_bands++; 515 } 516 517 if ((GDALGetRasterCount(hDS) > 1 && n_bands != 1) 510 518 || GDALGetGCPCount(hDS) > 0) 511 519 force_imagery = TRUE; … … 518 526 519 527 if (parm.band->answer != NULL) 520 nBand = atoi(parm.band->answer );528 nBand = atoi(parm.band->answers[0]); 521 529 522 530 hBand = GDALGetRasterBand(hDS, nBand); … … 540 548 struct Ref ref; 541 549 char szBandName[512]; 542 int nBand ;550 int nBand = 0; 543 551 char colornamebuf[512], colornamebuf2[512]; 544 552 … … 546 554 547 555 colornamebuf2[0] = '\0'; 548 for (nBand = 1; nBand <= GDALGetRasterCount(hDS); nBand++) { 556 557 n_bands = 0; 558 while (TRUE) { 559 if (parm.band->answer != NULL) { 560 if (parm.band->answers[n_bands] == NULL) 561 break; 562 nBand = atoi(parm.band->answers[n_bands++]); 563 } 564 else { 565 if (nBand >= GDALGetRasterCount(hDS)) 566 break; 567 nBand++; 568 } 569 549 570 G_debug(3, "Import raster band %d", nBand); 550 571 hBand = GDALGetRasterBand(hDS, nBand); … … 1145 1166 struct Colors colors; 1146 1167 DCELL val1, val2; 1147 int r1, g1, b1, r2, g2, b2; 1168 double r1, g1, b1, r2, g2, b2; 1169 int cf; 1148 1170 1149 1171 Rast_init_colors(&colors); … … 1180 1202 bmaxc = indx; 1181 1203 } 1204 1205 /* guess color range 0, 1 or 0, 255 */ 1182 1206 1183 1207 if (minc >= 0 && maxc >= 0 && rminc >= 0 && rmaxc >= 0 && 1184 1208 gminc >= 0 && gmaxc >= 0 && bminc >= 0 && bmaxc >= 0) { 1209 1210 cf = 1; 1185 1211 1186 /* fetchcolor rules */1212 /* analyze color rules */ 1187 1213 for (indx = 0; indx < nrows; indx++) { 1188 1214 val1 = GDALRATGetValueAsDouble(gdal_rat, indx, minc); … … 1197 1223 b2 = GDALRATGetValueAsDouble(gdal_rat, indx, bmaxc); 1198 1224 1199 Rast_add_d_color_rule(&val1, r1, g1, b1, 1200 &val2, r2, g2, b2, 1201 &colors); 1225 if (r1 > 0.0 && r1 < 1.0) 1226 cf = 255; 1227 else if (cf == 255 && r1 > 1.0) { 1228 cf = 0; 1229 break; 1230 } 1231 1232 if (g1 > 0.0 && g1 < 1.0) 1233 cf = 255; 1234 else if (cf == 255 && g1 > 1.0) { 1235 cf = 0; 1236 break; 1237 } 1238 1239 if (b1 > 0.0 && b1 < 1.0) 1240 cf = 255; 1241 else if (cf == 255 && b1 > 1.0) { 1242 cf = 0; 1243 break; 1244 } 1245 1246 if (r2 > 0.0 && r2 < 1.0) 1247 cf = 255; 1248 else if (cf == 255 && r2 > 1.0) { 1249 cf = 0; 1250 break; 1251 } 1252 1253 if (g2 > 0.0 && g2 < 1.0) 1254 cf = 255; 1255 else if (cf == 255 && g2 > 1.0) { 1256 cf = 0; 1257 break; 1258 } 1259 1260 if (b2 > 0.0 && b2 < 1.0) 1261 cf = 255; 1262 else if (cf == 255 && b2 > 1.0) { 1263 cf = 0; 1264 break; 1265 } 1266 } 1267 1268 if (cf == 0) 1269 G_warning(_("Inconsistent color rules in RAT")); 1270 else { 1271 /* fetch color rules */ 1272 for (indx = 0; indx < nrows; indx++) { 1273 val1 = GDALRATGetValueAsDouble(gdal_rat, indx, minc); 1274 val2 = GDALRATGetValueAsDouble(gdal_rat, indx, maxc); 1275 1276 r1 = GDALRATGetValueAsDouble(gdal_rat, indx, rminc); 1277 g1 = GDALRATGetValueAsDouble(gdal_rat, indx, gminc); 1278 b1 = GDALRATGetValueAsDouble(gdal_rat, indx, bminc); 1279 1280 r2 = GDALRATGetValueAsDouble(gdal_rat, indx, rmaxc); 1281 g2 = GDALRATGetValueAsDouble(gdal_rat, indx, gmaxc); 1282 b2 = GDALRATGetValueAsDouble(gdal_rat, indx, bmaxc); 1283 1284 Rast_add_d_color_rule(&val1, r1 * cf, g1 * cf, b1 * cf, 1285 &val2, r2 * cf, g2 * cf, b2 * cf, 1286 &colors); 1287 } 1202 1288 } 1203 1289 } 1204 1290 else if (minmaxc >= 0 && rc >= 0 && gc >= 0 && bc >= 0) { 1205 1206 if (minc < 0) 1207 minc = maxc; 1208 1209 /* fetch color table */ 1291 1292 cf = 1; 1293 1294 /* analyze color table */ 1210 1295 for (indx = 0; indx < nrows; indx++) { 1211 1296 val1 = GDALRATGetValueAsDouble(gdal_rat, indx, minmaxc); … … 1214 1299 g1 = GDALRATGetValueAsDouble(gdal_rat, indx, gc); 1215 1300 b1 = GDALRATGetValueAsDouble(gdal_rat, indx, bc); 1216 1217 Rast_set_d_color(val1, r1, g1, b1, &colors); 1301 1302 1303 if (r1 > 0.0 && r1 < 1.0) 1304 cf = 255; 1305 else if (cf == 255 && r1 > 1.0) { 1306 cf = 0; 1307 break; 1308 } 1309 1310 if (g1 > 0.0 && g1 < 1.0) 1311 cf = 255; 1312 else if (cf == 255 && g1 > 1.0) { 1313 cf = 0; 1314 break; 1315 } 1316 1317 if (b1 > 0.0 && b1 < 1.0) 1318 cf = 255; 1319 else if (cf == 255 && b1 > 1.0) { 1320 cf = 0; 1321 break; 1322 } 1323 } 1324 1325 if (cf == 0) 1326 G_warning(_("Inconsistent color rules in RAT")); 1327 else { 1328 /* fetch color table */ 1329 for (indx = 0; indx < nrows; indx++) { 1330 val1 = GDALRATGetValueAsDouble(gdal_rat, indx, minmaxc); 1331 1332 r1 = GDALRATGetValueAsDouble(gdal_rat, indx, rc); 1333 g1 = GDALRATGetValueAsDouble(gdal_rat, indx, gc); 1334 b1 = GDALRATGetValueAsDouble(gdal_rat, indx, bc); 1335 1336 Rast_set_d_color(val1, r1 * cf, g1 * cf, b1 * cf, &colors); 1337 } 1218 1338 } 1219 1339 }
Note:
See TracChangeset
for help on using the changeset viewer.
