1

I have been using the gdal to merger a lot of *.tif files to get one big arear, I always get the blackblocks

I tried GDAL merge and GDAL warp but none of them seems working.

Does anyone know where I get wrong? I also attached one of the tiff information at end.

gdalwarp --config GDAL_CACHEMAX 4000 -wm 4000 -srcnodata 0 -dstalpha mx913.tif `mx914.tif mx915.tif mx916.tif mx917.tif mx918.tif mx919.tif mx920.tif mx921.tif mx922.tif mx923.tif mx924.tif mx925.tif mx926.tif mx927.tif mx928.tif mx929.tif mx930.tif mx930gabo.tif dev_transp_tours.tif`

or using:

gdal_merge.py -pct -o tours.tif  mx913.tif mx914.tif mx915.tif mx916.tif mx917.tif mx918.tif mx919.tif mx920.tif mx921.tif mx922.tif mx923.tif mx924.tif mx925.tif mx926.tif mx927.tif mx928.tif mx929.tif mx930.tif mx930gabo.tif

Each tif comes with four files they are: *.ers *.tfw *.TAB *.hgr

mx914.ers information:

DatasetHeader Begin
    Version     = "7.1"
    Name        = "mx914.ers"
    SourceDataset   = "mx914.tif"
    LastUpdated = Thu May 15 16:09:33 GMT 2014
    DataFile    = "mx914.tif"
    DataSetType = Translated
    DataType    = Raster
    ByteOrder   = LSBFirst
    CoordinateSpace Begin
        Datum       = "GDA94"
        Projection  = "LOCAL"
        CoordinateType  = EN
        Rotation    = 0:0:0.0
    CoordinateSpace End
    RasterInfo Begin
        CellType    = Unsigned8BitInteger
        CellInfo Begin
            Xdimension  = 42.3299565846599
            Ydimension  = 42.3306584909193
        CellInfo End
        NrOfLines   = 5341
        NrOfCellsPerLine    = 4146
        RegistrationCoord Begin
            Eastings    = 2211635.722
            Northings   = 2906028.401
        RegistrationCoord End
        NrOfBands   = 3
        BandId Begin
            Value       = "Red Layer"
        BandId End
        BandId Begin
            Value       = "Green Layer"
        BandId End
        BandId Begin
            Value       = "Blue Layer"
        BandId End
        RegionInfo Begin
            Type        = Polygon
            RegionName  = "All"
            SubRegion   = {
                0   0
                0   5341
                4146    5341
                4146    0
                }
        RegionInfo End
    RasterInfo End
DatasetHeader End

mx914.tfw

42.3299565847
0.0000000000
0.0000000000
-42.3306584909
2211656.8869782924
2906007.2356707547

mx94.TAB

  Definition Table
  File "mx914.tif"
  Type "RASTER"
  (2211635.722,2906028.401) (0,0) Label "Pt 1",
  (2387135.722,2906028.401) (4146,0) Label "Pt 2",
  (2211635.722,2679940.354) (0,5341) Label "Pt 3"
  CoordSys Earth Projection 3, 116, "m", 145, -37, -36, -38, 2500000, 2500000

mx914.hgr

[ID],,
File=HMRGeoReferenceFile,,
Version=2.2,,
,,
[GeoRefSetting],,
Origin_Lower_Left_X=2211635.722,,
Origin_Lower_Left_Y=2679940.354,,
Pixel_Size_X=42.3299565846599,,
Pixel_Size_Y=42.3306584909193,,
Image_Width=4146,,
Image_Height=5341,,
Rotation=0,,
Affinity=0,,
,,
[ImageInfo],,
Image_Owner=,,
Image_Description=Ausway Mapping Raster Dataset,,
Scanning_Res_X= 600,,
Scanning_Res_Y= 600,,

Here is the merged tif enter image description here

5
  • Which color you would like to have for the areas which do not have source data? Sea blue, white, or what?
    – user30184
    Commented Jul 6, 2016 at 9:22
  • @user30184 I would like to replace the black area to transparent.
    – Daqian
    Commented Jul 12, 2016 at 2:02
  • Are you sure that it is not transparent? You must put some other layer beneath your map before you can know. Have you tried with a world map?
    – user30184
    Commented Jul 12, 2016 at 6:13
  • @user30184 I am very certain that the tif I merged is not transparent, I opened it in the ps geoserver and windows image viewer and none of them is transparent.
    – Daqian
    Commented Jul 13, 2016 at 0:18
  • Does gdalinfo of the merged image say anything about nodata? Remember how nodata works: The pixels in your image are really black but nodata aware software know that they should be handled as transparent if there is something to show below the nodata labeled pixels. If there is nothing below you will see the actual nodata color.
    – user30184
    Commented Jul 13, 2016 at 9:10

3 Answers 3

1

After a lot of searching on the google and readings I finally workout why I have the black area.

The tifs I have are using pct color band,so I have to convert to RGB first, by using :

pct2rgb.py -b 1 m697.tif ./m697_rgb.tif

After this process, all the tifs can set the empty area as transparent by using :

gdalwarp -dstalpha 1.tif 2.tif 3.tif warp_123.tif

The magic word -dstalpha will do the trick to make it transparent.

But all of this should happen under one circumstance your tif color is at RGB channel.

Thanks everyone for you kindly help.

0

You need to assign no data value when you run the gdal_merge using -n nodata_value. First use a value of 255, if 255 didn't work, then use a value of 0. Other software use a value of 0 as no data value, but for gdal merge it uses 255. You can refer to this answer as background on this issue.

3
  • ,thanks for your speed reply but when I add the -n 255 or -n 0 none of them works but get the following information:0Traceback (most recent call last): File "C:\Program Files\GDAL\gdal_merge.py", line 242, in copy_into nodata_arg ) File "C:\Program Files\GDAL\gdal_merge.py", line 62, in raster_copy nodata ) File "C:\Program Files\GDAL\gdal_merge.py", line 87, in raster_copy_with_nodata import Numeric ImportError: No module named Numeric
    – Daqian
    Commented Jul 6, 2016 at 5:15
  • Could you try -n "255 255 255"? If it fails then try -n "0 0 0".
    – ahmadhanb
    Commented Jul 6, 2016 at 5:20
  • gdal_merge.py -pct -n 255 255 255 -o tran_tours.tif mx913.tif mx914.tif mx915.tif mx916.tif mx917.tif mx918.tif mx919.tif mx920.tif mx921.tif mx922.tif mx923.tif mx924.tif mx925.tif mx926.tif mx927.tif mx928.tif mx929.tif mx930.tif mx930gabo.tif gdal_merge.py -pct -n 0 0 0 -o tran_tours.tif mx913.tif mx914.tif mx915.tif mx916.tif mx917.tif mx918.tif mx919.tif mx920.tif mx921.tif mx922.tif mx923.tif mx924.tif mx925.tif mx926.tif mx927.tif mx928.tif mx929.tif mx930.tif mx930gabo.tif I have tried both I will keep trying on different maybe I short for package, do you think?
    – Daqian
    Commented Jul 6, 2016 at 5:29
0

Try your gdal_merge statement again this time with setting the output bands no data value using - listed here on the GDAL_Merge page

-a_nodata {output_nodata_value}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.