|
30 | 30 | from processing.algs.gdal.GdalUtils import GdalUtils
|
31 | 31 | from processing.algs.gdal.ClipRasterByExtent import ClipRasterByExtent
|
32 | 32 | from processing.algs.gdal.ClipRasterByMask import ClipRasterByMask
|
| 33 | +from processing.algs.gdal.gdal2tiles import gdal2tiles |
33 | 34 | from processing.algs.gdal.contour import contour
|
| 35 | +from processing.algs.gdal.GridAverage import GridAverage |
| 36 | +from processing.algs.gdal.GridDataMetrics import GridDataMetrics |
| 37 | +from processing.algs.gdal.GridInverseDistance import GridInverseDistance |
| 38 | +from processing.algs.gdal.GridInverseDistanceNearestNeighbor import GridInverseDistanceNearestNeighbor |
| 39 | +from processing.algs.gdal.GridLinear import GridLinear |
| 40 | +from processing.algs.gdal.GridNearestNeighbor import GridNearestNeighbor |
| 41 | +from processing.algs.gdal.proximity import proximity |
| 42 | +from processing.algs.gdal.rasterize import rasterize |
34 | 43 | from processing.algs.gdal.translate import translate
|
| 44 | +from processing.algs.gdal.warp import warp |
| 45 | + |
35 | 46 | from qgis.core import (QgsProcessingContext,
|
36 | 47 | QgsProcessingFeedback,
|
37 | 48 | QgsApplication,
|
@@ -390,6 +401,355 @@ def testContour(self):
|
390 | 401 | source + ' ' +
|
391 | 402 | '"d:/temp/check.gpkg"'])
|
392 | 403 |
|
| 404 | + def testGdal2Tiles(self): |
| 405 | + context = QgsProcessingContext() |
| 406 | + feedback = QgsProcessingFeedback() |
| 407 | + source = os.path.join(testDataPath, 'dem.tif') |
| 408 | + alg = gdal2tiles() |
| 409 | + alg.initAlgorithm() |
| 410 | + |
| 411 | + # with no NODATA value |
| 412 | + self.assertEqual( |
| 413 | + alg.getConsoleCommands({'INPUT': source, |
| 414 | + 'OUTPUT': 'd:/temp/'}, context, feedback), |
| 415 | + ['gdal2tiles.py', |
| 416 | + '-p mercator -w all -r average ' + |
| 417 | + source + ' ' + |
| 418 | + 'd:/temp/']) |
| 419 | + # with NODATA value |
| 420 | + self.assertEqual( |
| 421 | + alg.getConsoleCommands({'INPUT': source, |
| 422 | + 'NODATA': -9999, |
| 423 | + 'OUTPUT': 'd:/temp/'}, context, feedback), |
| 424 | + ['gdal2tiles.py', |
| 425 | + '-p mercator -w all -r average -a -9999.0 ' + |
| 426 | + source + ' ' + |
| 427 | + 'd:/temp/']) |
| 428 | + # with "0" NODATA value |
| 429 | + self.assertEqual( |
| 430 | + alg.getConsoleCommands({'INPUT': source, |
| 431 | + 'NODATA': 0, |
| 432 | + 'OUTPUT': 'd:/temp/'}, context, feedback), |
| 433 | + ['gdal2tiles.py', |
| 434 | + '-p mercator -w all -r average -a 0.0 ' + |
| 435 | + source + ' ' + |
| 436 | + 'd:/temp/']) |
| 437 | + |
| 438 | + def testGridAverage(self): |
| 439 | + context = QgsProcessingContext() |
| 440 | + feedback = QgsProcessingFeedback() |
| 441 | + source = os.path.join(testDataPath, 'points.gml') |
| 442 | + alg = GridAverage() |
| 443 | + alg.initAlgorithm() |
| 444 | + |
| 445 | + # with no NODATA value |
| 446 | + self.assertEqual( |
| 447 | + alg.getConsoleCommands({'INPUT': source, |
| 448 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 449 | + ['gdal_grid', |
| 450 | + '-l points -a average:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 451 | + source + ' ' + |
| 452 | + 'd:/temp/check.jpg']) |
| 453 | + # with NODATA value |
| 454 | + self.assertEqual( |
| 455 | + alg.getConsoleCommands({'INPUT': source, |
| 456 | + 'NODATA': 9999, |
| 457 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 458 | + ['gdal_grid', |
| 459 | + '-l points -a average:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=9999.0 -ot Float32 -of JPEG ' + |
| 460 | + source + ' ' + |
| 461 | + 'd:/temp/check.jpg']) |
| 462 | + # with "0" NODATA value |
| 463 | + self.assertEqual( |
| 464 | + alg.getConsoleCommands({'INPUT': source, |
| 465 | + 'NODATA': 0, |
| 466 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 467 | + ['gdal_grid', |
| 468 | + '-l points -a average:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 469 | + source + ' ' + |
| 470 | + 'd:/temp/check.jpg']) |
| 471 | + |
| 472 | + def testGridDataMetrics(self): |
| 473 | + context = QgsProcessingContext() |
| 474 | + feedback = QgsProcessingFeedback() |
| 475 | + source = os.path.join(testDataPath, 'points.gml') |
| 476 | + alg = GridDataMetrics() |
| 477 | + alg.initAlgorithm() |
| 478 | + |
| 479 | + # with no NODATA value |
| 480 | + self.assertEqual( |
| 481 | + alg.getConsoleCommands({'INPUT': source, |
| 482 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 483 | + ['gdal_grid', |
| 484 | + '-l points -a minimum:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 485 | + source + ' ' + |
| 486 | + 'd:/temp/check.jpg']) |
| 487 | + # with NODATA value |
| 488 | + self.assertEqual( |
| 489 | + alg.getConsoleCommands({'INPUT': source, |
| 490 | + 'NODATA': 9999, |
| 491 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 492 | + ['gdal_grid', |
| 493 | + '-l points -a minimum:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=9999.0 -ot Float32 -of JPEG ' + |
| 494 | + source + ' ' + |
| 495 | + 'd:/temp/check.jpg']) |
| 496 | + # with "0" NODATA value |
| 497 | + self.assertEqual( |
| 498 | + alg.getConsoleCommands({'INPUT': source, |
| 499 | + 'NODATA': 0, |
| 500 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 501 | + ['gdal_grid', |
| 502 | + '-l points -a minimum:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 503 | + source + ' ' + |
| 504 | + 'd:/temp/check.jpg']) |
| 505 | + |
| 506 | + def testGridInverseDistance(self): |
| 507 | + context = QgsProcessingContext() |
| 508 | + feedback = QgsProcessingFeedback() |
| 509 | + source = os.path.join(testDataPath, 'points.gml') |
| 510 | + alg = GridInverseDistance() |
| 511 | + alg.initAlgorithm() |
| 512 | + |
| 513 | + # with no NODATA value |
| 514 | + self.assertEqual( |
| 515 | + alg.getConsoleCommands({'INPUT': source, |
| 516 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 517 | + ['gdal_grid', |
| 518 | + '-l points -a invdist:power=2.0:smothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 519 | + source + ' ' + |
| 520 | + 'd:/temp/check.jpg']) |
| 521 | + # with NODATA value |
| 522 | + self.assertEqual( |
| 523 | + alg.getConsoleCommands({'INPUT': source, |
| 524 | + 'NODATA': 9999, |
| 525 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 526 | + ['gdal_grid', |
| 527 | + '-l points -a invdist:power=2.0:smothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=9999.0 -ot Float32 -of JPEG ' + |
| 528 | + source + ' ' + |
| 529 | + 'd:/temp/check.jpg']) |
| 530 | + # with "0" NODATA value |
| 531 | + self.assertEqual( |
| 532 | + alg.getConsoleCommands({'INPUT': source, |
| 533 | + 'NODATA': 0, |
| 534 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 535 | + ['gdal_grid', |
| 536 | + '-l points -a invdist:power=2.0:smothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 537 | + source + ' ' + |
| 538 | + 'd:/temp/check.jpg']) |
| 539 | + |
| 540 | + def testGridInverseDistanceNearestNeighbour(self): |
| 541 | + context = QgsProcessingContext() |
| 542 | + feedback = QgsProcessingFeedback() |
| 543 | + source = os.path.join(testDataPath, 'points.gml') |
| 544 | + alg = GridInverseDistanceNearestNeighbor() |
| 545 | + alg.initAlgorithm() |
| 546 | + |
| 547 | + # with no NODATA value |
| 548 | + self.assertEqual( |
| 549 | + alg.getConsoleCommands({'INPUT': source, |
| 550 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 551 | + ['gdal_grid', |
| 552 | + '-l points -a invdistnn:power=2.0:smothing=0.0:radius=1.0:max_points=0:min_points=0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 553 | + source + ' ' + |
| 554 | + 'd:/temp/check.jpg']) |
| 555 | + # with NODATA value |
| 556 | + self.assertEqual( |
| 557 | + alg.getConsoleCommands({'INPUT': source, |
| 558 | + 'NODATA': 9999, |
| 559 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 560 | + ['gdal_grid', |
| 561 | + '-l points -a invdistnn:power=2.0:smothing=0.0:radius=1.0:max_points=0:min_points=0:nodata=9999.0 -ot Float32 -of JPEG ' + |
| 562 | + source + ' ' + |
| 563 | + 'd:/temp/check.jpg']) |
| 564 | + # with "0" NODATA value |
| 565 | + self.assertEqual( |
| 566 | + alg.getConsoleCommands({'INPUT': source, |
| 567 | + 'NODATA': 0, |
| 568 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 569 | + ['gdal_grid', |
| 570 | + '-l points -a invdistnn:power=2.0:smothing=0.0:radius=1.0:max_points=0:min_points=0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 571 | + source + ' ' + |
| 572 | + 'd:/temp/check.jpg']) |
| 573 | + |
| 574 | + def testGridLinear(self): |
| 575 | + context = QgsProcessingContext() |
| 576 | + feedback = QgsProcessingFeedback() |
| 577 | + source = os.path.join(testDataPath, 'points.gml') |
| 578 | + alg = GridLinear() |
| 579 | + alg.initAlgorithm() |
| 580 | + |
| 581 | + # with no NODATA value |
| 582 | + self.assertEqual( |
| 583 | + alg.getConsoleCommands({'INPUT': source, |
| 584 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 585 | + ['gdal_grid', |
| 586 | + '-l points -a linear:radius=-1.0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 587 | + source + ' ' + |
| 588 | + 'd:/temp/check.jpg']) |
| 589 | + # with NODATA value |
| 590 | + self.assertEqual( |
| 591 | + alg.getConsoleCommands({'INPUT': source, |
| 592 | + 'NODATA': 9999, |
| 593 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 594 | + ['gdal_grid', |
| 595 | + '-l points -a linear:radius=-1.0:nodata=9999.0 -ot Float32 -of JPEG ' + |
| 596 | + source + ' ' + |
| 597 | + 'd:/temp/check.jpg']) |
| 598 | + # with "0" NODATA value |
| 599 | + self.assertEqual( |
| 600 | + alg.getConsoleCommands({'INPUT': source, |
| 601 | + 'NODATA': 0, |
| 602 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 603 | + ['gdal_grid', |
| 604 | + '-l points -a linear:radius=-1.0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 605 | + source + ' ' + |
| 606 | + 'd:/temp/check.jpg']) |
| 607 | + |
| 608 | + def testGridNearestNeighbour(self): |
| 609 | + context = QgsProcessingContext() |
| 610 | + feedback = QgsProcessingFeedback() |
| 611 | + source = os.path.join(testDataPath, 'points.gml') |
| 612 | + alg = GridNearestNeighbor() |
| 613 | + alg.initAlgorithm() |
| 614 | + |
| 615 | + # with no NODATA value |
| 616 | + self.assertEqual( |
| 617 | + alg.getConsoleCommands({'INPUT': source, |
| 618 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 619 | + ['gdal_grid', |
| 620 | + '-l points -a nearest:radius1=0.0:radius2=0.0:angle=0.0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 621 | + source + ' ' + |
| 622 | + 'd:/temp/check.jpg']) |
| 623 | + # with NODATA value |
| 624 | + self.assertEqual( |
| 625 | + alg.getConsoleCommands({'INPUT': source, |
| 626 | + 'NODATA': 9999, |
| 627 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 628 | + ['gdal_grid', |
| 629 | + '-l points -a nearest:radius1=0.0:radius2=0.0:angle=0.0:nodata=9999.0 -ot Float32 -of JPEG ' + |
| 630 | + source + ' ' + |
| 631 | + 'd:/temp/check.jpg']) |
| 632 | + # with "0" NODATA value |
| 633 | + self.assertEqual( |
| 634 | + alg.getConsoleCommands({'INPUT': source, |
| 635 | + 'NODATA': 0, |
| 636 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 637 | + ['gdal_grid', |
| 638 | + '-l points -a nearest:radius1=0.0:radius2=0.0:angle=0.0:nodata=0.0 -ot Float32 -of JPEG ' + |
| 639 | + source + ' ' + |
| 640 | + 'd:/temp/check.jpg']) |
| 641 | + |
| 642 | + def testProximity(self): |
| 643 | + context = QgsProcessingContext() |
| 644 | + feedback = QgsProcessingFeedback() |
| 645 | + source = os.path.join(testDataPath, 'dem.tif') |
| 646 | + alg = proximity() |
| 647 | + alg.initAlgorithm() |
| 648 | + |
| 649 | + # with no NODATA value |
| 650 | + self.assertEqual( |
| 651 | + alg.getConsoleCommands({'INPUT': source, |
| 652 | + 'BAND': 1, |
| 653 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 654 | + ['gdal_proximity.py', |
| 655 | + '-srcband 1 -distunits PIXEL -ot Float32 -of JPEG ' + |
| 656 | + source + ' ' + |
| 657 | + 'd:/temp/check.jpg']) |
| 658 | + # with NODATA value |
| 659 | + self.assertEqual( |
| 660 | + alg.getConsoleCommands({'INPUT': source, |
| 661 | + 'NODATA': 9999, |
| 662 | + 'BAND': 2, |
| 663 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 664 | + ['gdal_proximity.py', |
| 665 | + '-srcband 2 -distunits PIXEL -nodata 9999.0 -ot Float32 -of JPEG ' + |
| 666 | + source + ' ' + |
| 667 | + 'd:/temp/check.jpg']) |
| 668 | + # with "0" NODATA value |
| 669 | + self.assertEqual( |
| 670 | + alg.getConsoleCommands({'INPUT': source, |
| 671 | + 'NODATA': 0, |
| 672 | + 'BAND': 1, |
| 673 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 674 | + ['gdal_proximity.py', |
| 675 | + '-srcband 1 -distunits PIXEL -nodata 0.0 -ot Float32 -of JPEG ' + |
| 676 | + source + ' ' + |
| 677 | + 'd:/temp/check.jpg']) |
| 678 | + |
| 679 | + def testRasterize(self): |
| 680 | + context = QgsProcessingContext() |
| 681 | + feedback = QgsProcessingFeedback() |
| 682 | + source = os.path.join(testDataPath, 'polys.gml') |
| 683 | + alg = rasterize() |
| 684 | + alg.initAlgorithm() |
| 685 | + |
| 686 | + # with no NODATA value |
| 687 | + self.assertEqual( |
| 688 | + alg.getConsoleCommands({'INPUT': source, |
| 689 | + 'FIELD': 'id', |
| 690 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 691 | + ['gdal_rasterize', |
| 692 | + '-l polys2 -a id -ts 0.0 0.0 -ot Float32 -of JPEG ' + |
| 693 | + source + ' ' + |
| 694 | + 'd:/temp/check.jpg']) |
| 695 | + # with NODATA value |
| 696 | + self.assertEqual( |
| 697 | + alg.getConsoleCommands({'INPUT': source, |
| 698 | + 'NODATA': 9999, |
| 699 | + 'FIELD': 'id', |
| 700 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 701 | + ['gdal_rasterize', |
| 702 | + '-l polys2 -a id -ts 0.0 0.0 -a_nodata 9999.0 -ot Float32 -of JPEG ' + |
| 703 | + source + ' ' + |
| 704 | + 'd:/temp/check.jpg']) |
| 705 | + # with "0" NODATA value |
| 706 | + self.assertEqual( |
| 707 | + alg.getConsoleCommands({'INPUT': source, |
| 708 | + 'NODATA': 0, |
| 709 | + 'FIELD': 'id', |
| 710 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 711 | + ['gdal_rasterize', |
| 712 | + '-l polys2 -a id -ts 0.0 0.0 -a_nodata 0.0 -ot Float32 -of JPEG ' + |
| 713 | + source + ' ' + |
| 714 | + 'd:/temp/check.jpg']) |
| 715 | + |
| 716 | + def testWarp(self): |
| 717 | + context = QgsProcessingContext() |
| 718 | + feedback = QgsProcessingFeedback() |
| 719 | + source = os.path.join(testDataPath, 'dem.tif') |
| 720 | + alg = warp() |
| 721 | + alg.initAlgorithm() |
| 722 | + |
| 723 | + # with no NODATA value |
| 724 | + self.assertEqual( |
| 725 | + alg.getConsoleCommands({'INPUT': source, |
| 726 | + 'CRS': 'EPSG:3111', |
| 727 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 728 | + ['gdalwarp', |
| 729 | + '-t_srs EPSG:4326 -r near -ot Float32 -of JPEG ' + |
| 730 | + source + ' ' + |
| 731 | + 'd:/temp/check.jpg']) |
| 732 | + # with NODATA value |
| 733 | + self.assertEqual( |
| 734 | + alg.getConsoleCommands({'INPUT': source, |
| 735 | + 'NODATA': 9999, |
| 736 | + 'CRS': 'EPSG:3111', |
| 737 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 738 | + ['gdalwarp', |
| 739 | + '-t_srs EPSG:4326 -dstnodata 9999.0 -r near -ot Float32 -of JPEG ' + |
| 740 | + source + ' ' + |
| 741 | + 'd:/temp/check.jpg']) |
| 742 | + # with "0" NODATA value |
| 743 | + self.assertEqual( |
| 744 | + alg.getConsoleCommands({'INPUT': source, |
| 745 | + 'NODATA': 0, |
| 746 | + 'CRS': 'EPSG:3111', |
| 747 | + 'OUTPUT': 'd:/temp/check.jpg'}, context, feedback), |
| 748 | + ['gdalwarp', |
| 749 | + '-t_srs EPSG:4326 -dstnodata 0.0 -r near -ot Float32 -of JPEG ' + |
| 750 | + source + ' ' + |
| 751 | + 'd:/temp/check.jpg']) |
| 752 | + |
393 | 753 |
|
394 | 754 | class TestGdalOgrToPostGis(unittest.TestCase):
|
395 | 755 |
|
|
0 commit comments