[gdal-dev] Problems with masking while create a color-relief from a DEM

Stephen Woodbridge stephenwoodbridge37 at gmail.com
Thu Oct 24 07:38:05 PDT 2019


Hi,

I have a collection of region netCDF DEM files that overlap and have a 
nodata=-nan. I have been able to convert them to color-relief using 
gdaldem but somewhere in the processing chain I seem to be loosing the 
nodata/mask/alpha info and the nodata in the color-relief is opaque, ie: 
where the DEMs overlap and there is nodata the later image blocks out 
the earlier image rather than being transparent.

Running: GDAL 2.2.2, released 2017/09/15 on Ubuntu xenial

Processing is like:

gdalwarp -s_srs EPSG:4269 -t_srs EPSG:4326 -srcnodata \-nan -dstnodata 
30000 -ot Int16 -of GTiff -co TILED=YES crm_vol1.nc crm_vol1.nc.tif

and I have tried variants like:

-srcnodata -32768 or  -- I get a lot of -32768 in the conversion to Int16
-dstnodata 30000      -- let gdal sense the nodata value
instead of -srcnodata \-nan -dstnodata 30000

gdaldem color-relief crm_vol1.nc.tif ../dem-colors.txt 
crm_vol1.nc.colored.tif -of GTiff -co TILED=YES -alpha

also run without -alpha

Anyway, I have 10 region DEMs and then I combine them in a VRT like

buildvrt color-relief.vrt *.colored.tif

Then I serve that via mapserver. I get the same image if I just do:

gdal_translate -of PNG color-relief.vrt test.png

-Steve

woodbri at u19589217:~/work/bathymetry/coastal-relief$ gdalwarp -s_srs 
EPSG:4269 -t_srs EPSG:4326 -srcnodata -32768 -ot Int16 -of GTiff -co 
TILED=YES crm_vol1.nc crm_vol1.nc.tif
Creating output file that is 19201P x 9601L.
Processing input file crm_vol1.nc.
Copying nodata values from source crm_vol1.nc to destination 
crm_vol1.nc.tif.
0...10...20...30...40...50...60...70...80...90...100 - done.

woodbri at u19589217:~/work/bathymetry/coastal-relief$ gdalinfo crm_vol1.nc.tif
Driver: GTiff/GeoTIFF
Files: crm_vol1.nc.tif
Size is 19201, 9601
Coordinate System is:
GEOGCS["WGS 84",
     DATUM["WGS_1984",
         SPHEROID["WGS 84",6378137,298.257223563,
             AUTHORITY["EPSG","7030"]],
         AUTHORITY["EPSG","6326"]],
     PRIMEM["Greenwich",0],
     UNIT["degree",0.0174532925199433],
     AUTHORITY["EPSG","4326"]]
Origin = (-80.000416666666666,48.000416666666666)
Pixel Size = (0.000833333333333,-0.000833333333333)
Metadata:
   AREA_OR_POINT=Area
   NC_GLOBAL#Conventions=CF-1.4
   NC_GLOBAL#geospatial_lat_max=48
   NC_GLOBAL#geospatial_lat_min=40
   NC_GLOBAL#geospatial_lat_resolution=0.000833
   NC_GLOBAL#geospatial_lat_units=degrees_north
   NC_GLOBAL#geospatial_lon_max=-64
   NC_GLOBAL#geospatial_lon_min=-80
   NC_GLOBAL#geospatial_lon_resolution=0.000833
   NC_GLOBAL#geospatial_lon_units=degrees_east
   NC_GLOBAL#GMT_version=4.5.1 [64-bit]
   NC_GLOBAL#history=xyz2grd -R-80/-64/40/48 -I3c -Gcrm_v1.grd
   NC_GLOBAL#title=crm_v1.grd
   x#actual_range={-80,-64}
   x#long_name=x
   x#units=degrees_east
   x#_CoordinateAxisType=Lon
   y#actual_range={40,48}
   y#long_name=y
   y#units=degrees_north
   y#_CoordinateAxisType=Lat
   z#actual_range={-2754.39990234375,1903}
   z#long_name=z
   z#positive=up
   z#units=meters
   z#_FillValue=-nan
Image Structure Metadata:
   INTERLEAVE=BAND
Corner Coordinates:
Upper Left  ( -80.0004167,  48.0004167) ( 80d 0' 1.50"W, 48d 0' 1.50"N)
Lower Left  ( -80.0004167,  39.9995833) ( 80d 0' 1.50"W, 39d59'58.50"N)
Upper Right ( -63.9995833,  48.0004167) ( 63d59'58.50"W, 48d 0' 1.50"N)
Lower Right ( -63.9995833,  39.9995833) ( 63d59'58.50"W, 39d59'58.50"N)
Center      ( -72.0000000,  44.0000000) ( 72d 0' 0.00"W, 44d 0' 0.00"N)
Band 1 Block=256x256 Type=Int16, ColorInterp=Gray
   NoData Value=-32768
   Unit Type: meters
   Metadata:
     actual_range={-2754.39990234375,1903}
     long_name=z
     NETCDF_VARNAME=z
     positive=up
     units=meters
     _FillValue=-nan
woodbri at u19589217:~/work/bathymetry/coastal-relief$ gdalinfo 
crm_vol1.nc.tif -hist
Driver: GTiff/GeoTIFF
Files: crm_vol1.nc.tif
Size is 19201, 9601
Coordinate System is:
GEOGCS["WGS 84",
     DATUM["WGS_1984",
         SPHEROID["WGS 84",6378137,298.257223563,
             AUTHORITY["EPSG","7030"]],
         AUTHORITY["EPSG","6326"]],
     PRIMEM["Greenwich",0],
     UNIT["degree",0.0174532925199433],
     AUTHORITY["EPSG","4326"]]
Origin = (-80.000416666666666,48.000416666666666)
Pixel Size = (0.000833333333333,-0.000833333333333)
Metadata:
   AREA_OR_POINT=Area
   NC_GLOBAL#Conventions=CF-1.4
   NC_GLOBAL#geospatial_lat_max=48
   NC_GLOBAL#geospatial_lat_min=40
   NC_GLOBAL#geospatial_lat_resolution=0.000833
   NC_GLOBAL#geospatial_lat_units=degrees_north
   NC_GLOBAL#geospatial_lon_max=-64
   NC_GLOBAL#geospatial_lon_min=-80
   NC_GLOBAL#geospatial_lon_resolution=0.000833
   NC_GLOBAL#geospatial_lon_units=degrees_east
   NC_GLOBAL#GMT_version=4.5.1 [64-bit]
   NC_GLOBAL#history=xyz2grd -R-80/-64/40/48 -I3c -Gcrm_v1.grd
   NC_GLOBAL#title=crm_v1.grd
   x#actual_range={-80,-64}
   x#long_name=x
   x#units=degrees_east
   x#_CoordinateAxisType=Lon
   y#actual_range={40,48}
   y#long_name=y
   y#units=degrees_north
   y#_CoordinateAxisType=Lat
   z#actual_range={-2754.39990234375,1903}
   z#long_name=z
   z#positive=up
   z#units=meters
   z#_FillValue=-nan
Image Structure Metadata:
   INTERLEAVE=BAND
Corner Coordinates:
Upper Left  ( -80.0004167,  48.0004167) ( 80d 0' 1.50"W, 48d 0' 1.50"N)
Lower Left  ( -80.0004167,  39.9995833) ( 80d 0' 1.50"W, 39d59'58.50"N)
Upper Right ( -63.9995833,  48.0004167) ( 63d59'58.50"W, 48d 0' 1.50"N)
Lower Right ( -63.9995833,  39.9995833) ( 63d59'58.50"W, 39d59'58.50"N)
Center      ( -72.0000000,  44.0000000) ( 72d 0' 0.00"W, 44d 0' 0.00"N)
Band 1 Block=256x256 Type=Int16, ColorInterp=Gray
0...10...20...30...40...50...60...70...80...90...100 - done.
   256 buckets from -1548.44 to 1236.44:
   1032801 10127 10364 9826 8535 9227 9176 9188 9233 9661 9292 9087 8590 
8923 8716 8643 8752 8632 8605 8640 8632 8115 8654 8446 8493 8250 8373 
8216 7855 7159 7887 8094 8269 8038 7691 7646 7487 6743 7396 7245 7156 
7369 7399 7333 7411 6859 7542 7438 7484 7584 7557 7523 7540 7106 7489 
7336 7393 7450 7318 7227 7256 6996 6339 6970 6984 6885 6761 6704 6749 
6854 6182 6893 7015 6997 7050 7033 7072 7146 6557 7236 7199 7306 7225 
7292 7202 7381 6799 7529 7525 7594 7626 7772 7839 8021 8247 7609 8582 
8873 9051 9084 9400 9614 9786 8956 9907 10163 10466 10868 25910 36376 
43063 62233 63701 68806 77172 95784 121102 144946 220779 318701 515996 
677511 807570 1106919 1266071 1331148 1213751 936387 838275 844343 
825124 892606 953963 1537850 1781357 2018853 2341719 2388359 2391318 
1998359 1485291 1168051 1480774 992742 734483 1554927 916946 1682915 
640711 831701 1804228 628642 689638 2080653 751301 761486 2303932 701017 
874713 1876341 611201 1753845 742827 644273 1610207 667418 643178 
1548112 738446 633336 1679225 781684 812290 1696296 752769 1770805 
804989 657425 1618410 666493 621947 1310715 575474 583199 1122012 442866 
500235 835458 395728 726215 376469 325665 598716 263472 269859 501338 
242752 233613 413525 192132 196579 276488 127191 209752 151081 101450 
164848 82122 77595 117805 60015 63534 93537 50029 45890 60427 36654 
52001 26321 27558 38248 20918 20783 27515 19528 16649 23961 14802 11928 
16105 9934 12701 7403 7403 9233 5869 5788 8036 5499 5402 7403 4318 3344 
3911 2413 2190 2400 1574 2032 1115 1219 1520 1129 1193 1670 13783
   NoData Value=-32768
   Unit Type: meters
   Metadata:
     actual_range={-2754.39990234375,1903}
     long_name=z
     NETCDF_VARNAME=z
     positive=up
     STATISTICS_MAXIMUM=1231
     STATISTICS_MEAN=109.57123697519
     STATISTICS_MINIMUM=-1543
     STATISTICS_STDDEV=306.33492576621
     units=meters
     _FillValue=-nan

### Because the MINIMUM is -1543, this seems to point to the fact that 
-32768 is NODATA and the fact that when I run gdalwarp without 
'-srcnodata -32768' I get lots of -32768 values.

woodbri at u19589217:~/work/bathymetry/coastal-relief$ gdaldem color-relief 
crm_vol1.nc.tif ../dem-colors.txt test.tif -of GTiff -co TILED=YES -alpha
0...10...20...30...40...50...60...70...80...90...100 - done.
woodbri at u19589217:~/work/bathymetry/coastal-relief$ gdalinfo test.tif -hist
Driver: GTiff/GeoTIFF
Files: test.tif
Size is 19201, 9601
Coordinate System is:
GEOGCS["WGS 84",
     DATUM["WGS_1984",
         SPHEROID["WGS 84",6378137,298.257223563,
             AUTHORITY["EPSG","7030"]],
         AUTHORITY["EPSG","6326"]],
     PRIMEM["Greenwich",0],
     UNIT["degree",0.0174532925199433],
     AUTHORITY["EPSG","4326"]]
Origin = (-80.000416666666666,48.000416666666666)
Pixel Size = (0.000833333333333,-0.000833333333333)
Metadata:
   AREA_OR_POINT=Area
Image Structure Metadata:
   INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( -80.0004167,  48.0004167) ( 80d 0' 1.50"W, 48d 0' 1.50"N)
Lower Left  ( -80.0004167,  39.9995833) ( 80d 0' 1.50"W, 39d59'58.50"N)
Upper Right ( -63.9995833,  48.0004167) ( 63d59'58.50"W, 48d 0' 1.50"N)
Lower Right ( -63.9995833,  39.9995833) ( 63d59'58.50"W, 39d59'58.50"N)
Center      ( -72.0000000,  44.0000000) ( 72d 0' 0.00"W, 44d 0' 0.00"N)
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
0...10...20...30...40...50...60...70...80...90...100 - done.
   256 buckets from -0.5 to 255.5:
   1447178 10259 11314 10054 10772 10116 10544 9874 10197 9474 10108 
9290 9192 9863 9320 10114 9503 10258 9596 10439 9769 10544 9893 9916 
10560 10083 10932 10307 11109 10578 11584 96844185 12419 12063 12287 
13541 13146 14316 13427 15026 14692 41339 54152 94778 89113 105552 
150343 189234 344217 608083 1007554 1252249 1834367 1796592 1566353 
686026 301844 319297 303284 294902 379814 297508 322741 326623 336581 
329518 456173 453383 583398 672362 603596 648066 875983 704772 796500 
873236 988435 932029 1081958 429972 0 0 209878 0 0 214570 0 0 206080 0 0 
215590 0 0 215942 0 0 1720831 3150361 3246722 3064822 3436119 3887445 
3286771 3015137 3019139 2916134 3079190 3375360 3137205 2818227 2558566 
2000431 1603370 1613223 1145531 865690 889479 503867 356019 486292 
212496 150386 324876 88236 64546 254783 39922 28669 209142 9333 10523 
188291 9848 5991 178231 3127 3533 171542 1778 2262 175583 2259 162793 
1408 871 164088 793 574 164099 727 974 169365 621 314 163860 284 221 
156479 200 363 148526 269 162 141005 102 192 132298 103 135 67 74 30 
122259 26 13 27 19 35 117867 21 7 6 1 115547 0 0 0 0 0 107718 0 0 0 0 0 
112217 0 0 0 0 0 116080 0 0 0 0 0 111385 0 0 0 0 112290 0 0 0 0 0 114605 
0 0 0 0 0 105392 0 0 0 0 0 108539 0 0 0 0 0 106181 0 0 0 0 107507 0 0 0 
0 0 102755 0 0 0 0 0 277539 876651
   Mask Flags: PER_DATASET ALPHA
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
0...10...20...30...40...50...60...70...80...90...100 - done.
   256 buckets from -0.5 to 255.5:
   96833026 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 75 140 198 287 351 463 
524 637 683 835 876 1042 1076 1262 1266 1479 1498 1734 1894 2796 3613 
4713 4577 5138 5103 5706 5922 6683 6545 7788 7180 7669 8267 8555 7904 
9326 8920 10054 10109 12815 16648 17934 19054 23674 25061 26778 26027 
26804 34992 32866 32562 43008 49196 47848 43750 44507 43656 40371 40416 
39964 44200 37127 31420 28558 28264 28802 29065 26773 28180 26803 25375 
25099 26237 24635 23969 22921 24354 22041 21337 21322 22293 21793 15775 
10959 11285 10050 10754 10768 10584 9803 10191 904269 29616405 23517792 
22170 17868 15376 12718 13571 13277 12571 12643 11803 11759 10839 11603 
11998 11691 10959 11469 11559 11952 11230 12674 12969 13392 12755 13993 
14430 14599 13888 15503 32779 54749 84164 93114 108783 132694 193903 
316919 613006 919712 1278482 1828546 1914933 1483630 688489 158311 
223793 157739 161558 231034 144417 146459 229560 152079 859370 149766 
155239 247609 162400 252425 168272 162655 253183 176214 193639 334935 
253686 448160 329813 342549 453365 301196 451433 531653 345269 515629 
361455 386660 621607 428993 731571 489340 480048 663541 426752 443646 
429972 209878 214570 206080 327481 215942 218188 219973 223583 220948 
215852 214423 218337 222402 216418 210014 198017 191032 179768 172689 
168699 173849 161326 257454 163315 168811 163531 156177 148272 140825 
132120 0 122228 0 117845 0 115547 0 107718 0 112217 89065 116080 111385 
0 112290 0 114605 0 105392 0 108539 0 106181 0 107507 0 102755 0 94252
   Mask Flags: PER_DATASET ALPHA
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
0...10...20...30...40...50...60...70...80...90...100 - done.
   256 buckets from -0.5 to 255.5:
   565598 1189840 1852045 1101516 1893780 964720 1860454 869243 1023955 
2192352 972005 2518135 906493 2242864 794478 2002472 855945 1744142 
880240 873707 1717830 907306 1865819 927191 1972323 956931 2027450 
945921 1804008 865933 760223 1414197 737480 1270138 608891 1005960 
500073 845304 401791 680128 375937 367795 531651 300975 467826 238508 
333763 178881 276561 136576 192569 106542 103761 123087 76043 96939979 
61754 74426 46899 58403 36738 45492 24866 25100 32757 22670 29581 17198 
18888 12718 13473 9939 15877 16568 15695 11355 5653 5054 3646 3353 3361 
2198 1523 1141 1143 1154 1272 785 507 387 426 514 438 287 255 174 247 
158 95 51 26 39 47 34 17 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 637177 0 
0 0 0 0 127583 0 0 0 0 0 111891 0 0 0 0 0 94222 0 0 0 0 0 89065 0 0 0 0 
0 94252 0 102755 107507 0 106208 108720 382 105982 832 115710 113619 
1681 113287 118262 2606 141130 52191 162197 171295 58364 178118 185143 
64851 197988 209270 374620 235787 242807 250349 270923 446129 288564 
299692 314081 336078 481240 229485 236272 232700 229178 452198 239022 
236573 235649 233818 438902 233923 257743 1385197 2477781 2111821 
1882477 1880794 1768442 1983066 2599410 3104590 2887397 1006087 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   Mask Flags: PER_DATASET ALPHA
Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
0...10...20...30...40...50...60...70...80...90...100 - done.
   256 buckets from -0.5 to 255.5:
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 184348801

### All pixels have alpha 255 set. Size is 19201, 9601 = 184348801

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the gdal-dev mailing list