Quantcast

[gdal-dev] GDAL appears to ignore NoDataValue

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[gdal-dev] GDAL appears to ignore NoDataValue

Ophir Yoktan

I'm trying to build a mosaic, and I rely on the NoDataValue feature to treat some parts of the image as transparent.
However, it appears that GDAL doesn't work as expected.

I also created a very simple test case using a vrt dataset and gdal_translate - and I get the same results (that is - the 2nd image draws over the 1st image, ignoring "transparent areas")

I have to 100X100 image files with a white marking (different in each file) over black background (black being exactly equal to 0)
I built a simple vrt file:

    <VRTDataset rasterXSize="100" rasterYSize="100">
      <VRTRasterBand dataType="Byte" band="1">
        <ColorInterp>Gray</ColorInterp>
        <SimpleSource>
          <SourceFilename relativeToVRT="1">a1.tif</SourceFilename>
          <SourceBand>1</SourceBand>
          <SrcRect xOff="0" yOff="0" xSize="100" ySize="100"/>
          <DstRect xOff="0" yOff="0" xSize="100" ySize="100"/>
      <HideNoDataValue>1</HideNoDataValue>
      <NoDataValue>0</NoDataValue>
        </SimpleSource>
        <SimpleSource>
          <SourceFilename relativeToVRT="1">a2.tif</SourceFilename>
          <SourceBand>1</SourceBand>
          <SrcRect xOff="0" yOff="0" xSize="100" ySize="100"/>
          <DstRect xOff="0" yOff="0" xSize="100" ySize="100"/>
      <HideNoDataValue>1</HideNoDataValue>
      <NoDataValue>0</NoDataValue>
        </SimpleSource>
      </VRTRasterBand>
    </VRTDataset>
and I run the command:

    gdal_translate mosaic.vrt mosaic.tif

The result is identical to image `a2.tif`, instead of being a combination of `a1.tif` and `a2.tif`

I got the error using gdal 1.8 and 1.9

any ideas?


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GDAL appears to ignore NoDataValue

Even Rouault
Selon Ophir Yoktan <[hidden email]>:

Several errors :
1) The NoDataValue and HideNoDataValue elements are only valid under the
VRTRasterBand element, not SimpleSource
2) You want to change SimpleSource to ComplexSource, and add a
<NODATA>0</NODATA> element in it. (well basically rename your current
NoDataValue to NODATA.


> I'm trying to build a mosaic, and I rely on the NoDataValue feature to
> treat some parts of the image as transparent.
> However, it appears that GDAL doesn't work as expected.
>
> I also created a very simple test case using a vrt dataset and
> gdal_translate - and I get the same results (that is - the 2nd image draws
> over the 1st image, ignoring "transparent areas")
>
> I have to 100X100 image files with a white marking (different in each file)
> over black background (black being exactly equal to 0)
> I built a simple vrt file:
>
>     <VRTDataset rasterXSize="100" rasterYSize="100">
>       <VRTRasterBand dataType="Byte" band="1">
>         <ColorInterp>Gray</ColorInterp>
>         <SimpleSource>
>           <SourceFilename relativeToVRT="1">a1.tif</SourceFilename>
>           <SourceBand>1</SourceBand>
>           <SrcRect xOff="0" yOff="0" xSize="100" ySize="100"/>
>           <DstRect xOff="0" yOff="0" xSize="100" ySize="100"/>
>       <HideNoDataValue>1</HideNoDataValue>
>       <NoDataValue>0</NoDataValue>
>         </SimpleSource>
>         <SimpleSource>
>           <SourceFilename relativeToVRT="1">a2.tif</SourceFilename>
>           <SourceBand>1</SourceBand>
>           <SrcRect xOff="0" yOff="0" xSize="100" ySize="100"/>
>           <DstRect xOff="0" yOff="0" xSize="100" ySize="100"/>
>       <HideNoDataValue>1</HideNoDataValue>
>       <NoDataValue>0</NoDataValue>
>         </SimpleSource>
>       </VRTRasterBand>
>     </VRTDataset>
> and I run the command:
>
>     gdal_translate mosaic.vrt mosaic.tif
>
> The result is identical to image `a2.tif`, instead of being a combination
> of `a1.tif` and `a2.tif`
>
> I got the error using gdal 1.8 and 1.9
>
> any ideas?
>


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GDAL appears to ignore NoDataValue

Ophir Yoktan

Thanks! it works

a follow up "bonus" question
I get the same problem when trying to create a mosaic by warping to images to a new dataset.

my code is basically copied from the "GDAL Warp API Tutorial" page http://www.gdal.org/warptut.html

and adding:
psWarpOptions->padfSrcNoDataReal = new double(0);

On Feb 29, 2012 11:03 AM, "Even Rouault" <[hidden email]> wrote:
Selon Ophir Yoktan <[hidden email]>:

Several errors :
1) The NoDataValue and HideNoDataValue elements are only valid under the
VRTRasterBand element, not SimpleSource
2) You want to change SimpleSource to ComplexSource, and add a
<NODATA>0</NODATA> element in it. (well basically rename your current
NoDataValue to NODATA.


> I'm trying to build a mosaic, and I rely on the NoDataValue feature to
> treat some parts of the image as transparent.
> However, it appears that GDAL doesn't work as expected.
>
> I also created a very simple test case using a vrt dataset and
> gdal_translate - and I get the same results (that is - the 2nd image draws
> over the 1st image, ignoring "transparent areas")
>
> I have to 100X100 image files with a white marking (different in each file)
> over black background (black being exactly equal to 0)
> I built a simple vrt file:
>
>     <VRTDataset rasterXSize="100" rasterYSize="100">
>       <VRTRasterBand dataType="Byte" band="1">
>         <ColorInterp>Gray</ColorInterp>
>         <SimpleSource>
>           <SourceFilename relativeToVRT="1">a1.tif</SourceFilename>
>           <SourceBand>1</SourceBand>
>           <SrcRect xOff="0" yOff="0" xSize="100" ySize="100"/>
>           <DstRect xOff="0" yOff="0" xSize="100" ySize="100"/>
>       <HideNoDataValue>1</HideNoDataValue>
>       <NoDataValue>0</NoDataValue>
>         </SimpleSource>
>         <SimpleSource>
>           <SourceFilename relativeToVRT="1">a2.tif</SourceFilename>
>           <SourceBand>1</SourceBand>
>           <SrcRect xOff="0" yOff="0" xSize="100" ySize="100"/>
>           <DstRect xOff="0" yOff="0" xSize="100" ySize="100"/>
>       <HideNoDataValue>1</HideNoDataValue>
>       <NoDataValue>0</NoDataValue>
>         </SimpleSource>
>       </VRTRasterBand>
>     </VRTDataset>
> and I run the command:
>
>     gdal_translate mosaic.vrt mosaic.tif
>
> The result is identical to image `a2.tif`, instead of being a combination
> of `a1.tif` and `a2.tif`
>
> I got the error using gdal 1.8 and 1.9
>
> any ideas?
>



_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Loading...