2

I have a geo-referenced pdf that I'm transforming into .mbtiles or .tiff using

gdal_translate 00989I11.PDF 00989I11.tiff

The problem is that the result does not have a white background as I would expect. I'm a bit new to all the gdal manipulation but my question is how could I change all the transparent pixels into white pixels.

PDF looks like this. source here

enter image description here

The resulting .tiff looks like this source here: enter image description here

The gdalinfo of the .pdf is:

gdalinfo 00989I11.PDF
Driver: PDF/Geospatial PDF
Files: 00989I11.PDF
Size is 806, 1237
Coordinate System is:
PROJCRS["",
    BASEGEOGCRS["NAD83",
        DATUM["North American Datum 1983",
            ELLIPSOID["GRS 1980",6378137,298.2572221,
                LENGTHUNIT["metre",1]],
            ID["EPSG",6269]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["Degree",0.0174532925199433]]],
    CONVERSION["unnamed",
        METHOD["Lambert Conic Conformal (2SP)",
            ID["EPSG",9802]],
        PARAMETER["Latitude of false origin",35.2372777777778,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8821]],
        PARAMETER["Longitude of false origin",-120.642611111111,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8822]],
        PARAMETER["Latitude of 1st standard parallel",45,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8823]],
        PARAMETER["Latitude of 2nd standard parallel",33,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8824]],
        PARAMETER["Easting at false origin",0,
            LENGTHUNIT["Inch",0.0254000508001],
            ID["EPSG",8826]],
        PARAMETER["Northing at false origin",0,
            LENGTHUNIT["Inch",0.0254000508001],
            ID["EPSG",8827]]],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["Inch",0.0254000508001]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["Inch",0.0254000508001]]]
Data axis to CRS axis mapping: 1,2
Origin = (-1807172.000000000000000,2042985.000000000000000)
Pixel Size = (3334.000000000000000,-3335.000000000000000)
Metadata:
  AUTHOR=
  CREATION_DATE=D:20190718071421-04'00'
  CREATOR=MicroStation 8.11.9.867 by Bentley Systems, Incorporated
  NEATLINE=POLYGON ((-1487388.02470535 -1654179.3669621,563048.661741154 -1654193.12139478,563073.777508997 1615063.22966106,-1487370.34966788 1615075.17034221,-1487388.02470535 -1654179.3669621))
  PRODUCER=Adobe PDF Library 9.0
  TITLE=00989I11
Corner Coordinates:
Upper Left  (-1807172.000, 2042985.000) (121d 9' 6.29"W, 35d42'19.70"N)
Lower Left  (-1807172.000,-2082410.000) (121d 8'43.15"W, 34d45'28.56"N)
Upper Right (  880032.000, 2042985.000) (120d23'40.84"W, 35d42'22.90"N)
Lower Right (  880032.000,-2082410.000) (120d23'52.11"W, 34d45'31.72"N)
Center      ( -463570.000,  -19712.500) (120d46'20.58"W, 35d13'57.63"N)
Band 1 Block=806x1 Type=Byte, ColorInterp=Red
  Overviews: 403x619, 202x310, 101x155
  Mask Flags: PER_DATASET ALPHA 
  Overviews of mask band: 403x619, 202x310, 101x155
Band 2 Block=806x1 Type=Byte, ColorInterp=Green
  Overviews: 403x619, 202x310, 101x155
  Mask Flags: PER_DATASET ALPHA 
  Overviews of mask band: 403x619, 202x310, 101x155
Band 3 Block=806x1 Type=Byte, ColorInterp=Blue
  Overviews: 403x619, 202x310, 101x155
  Mask Flags: PER_DATASET ALPHA 
  Overviews of mask band: 403x619, 202x310, 101x155
Band 4 Block=806x1 Type=Byte, ColorInterp=Alpha
  Overviews: 403x619, 202x310, 101x155
6
  • what is the nodata value of your dataset? is it 255? if it is try unsetting the no data value Apr 23, 2020 at 17:53
  • where can I find it and how can I change it?
    – Jan
    Apr 23, 2020 at 17:57
  • if you do gdalinfo on your file- it will tell you what the no data value is if it is set. To unset the no data you can use gdal_edit command Apr 23, 2020 at 18:02
  • I've updated my original post with the gdalinfo output but I don't see any nodata
    – Jan
    Apr 23, 2020 at 18:07
  • that's odd -i've downloaded the images and run gdal_translate but I get a white background. What version of gdal are you using? I've got 2.2.3 Apr 23, 2020 at 18:20

2 Answers 2

0

I tried with the linux version of gdal and there it works as expected with the same input files. Since I'm on mac, I will use the Docker version of gdal so the command I use is

docker run -ti --rm -v $(pwd):/data osgeo/gdal  gdal_translate /data/00989I11.PDF /data/00989I11.tiff

or for .mbtiles:

docker run -ti --rm -v $(pwd):/data osgeo/gdal  gdal_translate /data/00989I11.PDF /data/00989I11.mbtiles  -of mbtiles --config GDAL_PDF_DPI 30

And the resulting tiff does have the background color

enter image description here

0

Here's a small addendum to gdal_translate:

Convert GeoPDF to GeoTIF with white background

gdal_translate --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES -co JPEG_QUALITY=90 -b 1 -b 2 -b 3 <file.pdf> <file.tif>

Convert GeoPDF to GeoTIF with transparent background

gdal_translate --config GDAL_PDF_BANDS 4 --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 -co TILED=YES <file.pdf> <file.tif>

Create overviews

gdaladdo --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR --config GDAL_TIFF_INTERNAL_MASK YES -r cubicspline <file.tif> 2 4 8 16

With JPEG compression you will loose your transparency, but I guess you can use "--config GDAL_PDF_BANDS 3" with different compressions (i.e. CCITTFAX4) as well.

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.