Quantcast

gdal_merge with a specific pixel value clipped/removed

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

gdal_merge with a specific pixel value clipped/removed

Ari Simmons

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').

I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?

I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

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

Re: gdal_merge with a specific pixel value clipped/removed

Matt Wilkie-2
The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.
_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gdal_merge with a specific pixel value clipped/removed

Ari Simmons
Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,
and is not recognised as a supported dataset name.

I'm on OSGEO4W too..


On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:
The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.


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

Re: gdal_merge with a specific pixel value clipped/removed

Chaitanya kumar CH
Ari,

The vrt is an xml file that represents a single raster dataset made up of one or many rasters. So, it is already merged. You can read it using any good text editor.
You only have to run gdal_translate to convert it to a tif.

gdal_translate -of GTiff tif_index.vrt tif_index.tif

On Wed, Jun 10, 2015 at 2:40 AM Ari Simmons <[hidden email]> wrote:
Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,

and is not recognised as a supported dataset name.

I'm on OSGEO4W too..


On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:
The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/
--

Chaitanya Kumar CH


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

Re: gdal_merge with a specific pixel value clipped/removed

Ari Simmons
Ok - so gdal_translate works great! Thanks!

HOWEVER, the removal of value 230 245 255 is still no happening...when I put in:


>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif

I get a .vrt with Band 1 = 0 (instead of 230) and the full 3 Band value becoming (0 245 255)....not what I expected. I expected it to become "NoData"....


On Tue, Jun 9, 2015 at 9:17 PM, Chaitanya kumar CH <[hidden email]> wrote:
Ari,

The vrt is an xml file that represents a single raster dataset made up of one or many rasters. So, it is already merged. You can read it using any good text editor.
You only have to run gdal_translate to convert it to a tif.

gdal_translate -of GTiff tif_index.vrt tif_index.tif

On Wed, Jun 10, 2015 at 2:40 AM Ari Simmons <[hidden email]> wrote:
Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,

and is not recognised as a supported dataset name.

I'm on OSGEO4W too..


On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:
The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
<a href="tel:867-667-8133" value="+18676678133" target="_blank">867-667-8133 Tel * <a href="tel:867-393-7003" value="+18673937003" target="_blank">867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/
--

Chaitanya Kumar CH



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

Re: gdal_merge with a specific pixel value clipped/removed

Matt Wilkie-2

Perhaps try editing the .vrt file with a text editor and changing the nodata value by hand?

 

Matt

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Wednesday, June 10, 2015 10:19 AM
To: Chaitanya kumar CH
Cc: [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Ok - so gdal_translate works great! Thanks!

 

HOWEVER, the removal of value 230 245 255 is still no happening...when I put in:

 

 

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif

 

I get a .vrt with Band 1 = 0 (instead of 230) and the full 3 Band value becoming (0 245 255)....not what I expected. I expected it to become "NoData"....

 

 

On Tue, Jun 9, 2015 at 9:17 PM, Chaitanya kumar CH <[hidden email]> wrote:

Ari,

 

The vrt is an xml file that represents a single raster dataset made up of one or many rasters. So, it is already merged. You can read it using any good text editor.

You only have to run gdal_translate to convert it to a tif.

 

gdal_translate -of GTiff tif_index.vrt tif_index.tif

 

On Wed, Jun 10, 2015 at 2:40 AM Ari Simmons <[hidden email]> wrote:

Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

 

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,


and is not recognised as a supported dataset name.

I'm on OSGEO4W too..

 

 

On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:

The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
<a href="tel:867-667-8133" target="_blank">867-667-8133 Tel * <a href="tel:867-393-7003" target="_blank"> 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

 

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/

--

Chaitanya Kumar CH

 


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

Re: gdal_merge with a specific pixel value clipped/removed

Ari Simmons
Matt

Not sure I see how...

    <ComplexSource>
      <SourceFilename relativeToVRT="1">TEX_N00E006.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="1200" RasterYSize="1200" DataType="Byte" BlockXSize="1200" BlockYSize="2" />
      <SrcRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <DstRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <NODATA>230</NODATA>

Do you mean change

 <NODATA>230</NODATA>

to

 <NODATA>230 245 255</NODATA>

On Wed, Jun 10, 2015 at 10:20 AM, <[hidden email]> wrote:

Perhaps try editing the .vrt file with a text editor and changing the nodata value by hand?

 

Matt

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Wednesday, June 10, 2015 10:19 AM
To: Chaitanya kumar CH
Cc: [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Ok - so gdal_translate works great! Thanks!

 

HOWEVER, the removal of value 230 245 255 is still no happening...when I put in:

 

 

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif

 

I get a .vrt with Band 1 = 0 (instead of 230) and the full 3 Band value becoming (0 245 255)....not what I expected. I expected it to become "NoData"....

 

 

On Tue, Jun 9, 2015 at 9:17 PM, Chaitanya kumar CH <[hidden email]> wrote:

Ari,

 

The vrt is an xml file that represents a single raster dataset made up of one or many rasters. So, it is already merged. You can read it using any good text editor.

You only have to run gdal_translate to convert it to a tif.

 

gdal_translate -of GTiff tif_index.vrt tif_index.tif

 

On Wed, Jun 10, 2015 at 2:40 AM Ari Simmons <[hidden email]> wrote:

Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

 

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,


and is not recognised as a supported dataset name.

I'm on OSGEO4W too..

 

 

On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:

The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
<a href="tel:867-667-8133" target="_blank">867-667-8133 Tel * <a href="tel:867-393-7003" target="_blank"> 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

 

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/

--

Chaitanya Kumar CH

 



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

Re: gdal_merge with a specific pixel value clipped/removed

Matt Wilkie-2

That vrt snippet looks correct. Only one nodata number per band, and it has the correct value, 230.

 

In my test file 2 or so lines above <ComplexSource> there is an additional line “<NoDataValue>” with the number as a scaled float, “1.80000000000000E+001” (the +001 at end means move decimal to right 1 time. My nodata here is “18”). Full file is attached.

 

Matt

 

From: Ari Simmons [mailto:[hidden email]]
Sent: Wednesday, June 10, 2015 10:24 AM
To: Matt.Wilkie
Cc: Chaitanya kumar CH; [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Matt

Not sure I see how...

    <ComplexSource>
      <SourceFilename relativeToVRT="1">TEX_N00E006.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="1200" RasterYSize="1200" DataType="Byte" BlockXSize="1200" BlockYSize="2" />
      <SrcRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <DstRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <NODATA>230</NODATA>

Do you mean change

 <NODATA>230</NODATA>

to

 <NODATA>230 245 255</NODATA>

 

On Wed, Jun 10, 2015 at 10:20 AM, <[hidden email]> wrote:

Perhaps try editing the .vrt file with a text editor and changing the nodata value by hand?

 

Matt

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Wednesday, June 10, 2015 10:19 AM
To: Chaitanya kumar CH
Cc: [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Ok - so gdal_translate works great! Thanks!

 

HOWEVER, the removal of value 230 245 255 is still no happening...when I put in:

 

 

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif

 

I get a .vrt with Band 1 = 0 (instead of 230) and the full 3 Band value becoming (0 245 255)....not what I expected. I expected it to become "NoData"....

 

 

On Tue, Jun 9, 2015 at 9:17 PM, Chaitanya kumar CH <[hidden email]> wrote:

Ari,

 

The vrt is an xml file that represents a single raster dataset made up of one or many rasters. So, it is already merged. You can read it using any good text editor.

You only have to run gdal_translate to convert it to a tif.

 

gdal_translate -of GTiff tif_index.vrt tif_index.tif

 

On Wed, Jun 10, 2015 at 2:40 AM Ari Simmons <[hidden email]> wrote:

Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

 

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,


and is not recognised as a supported dataset name.

I'm on OSGEO4W too..

 

 

On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:

The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
<a href="tel:867-667-8133" target="_blank">867-667-8133 Tel * <a href="tel:867-393-7003" target="_blank"> 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

 

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/

--

Chaitanya Kumar CH

 

 


_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/

tree.vrt (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gdal_merge with a specific pixel value clipped/removed

Ari Simmons
Hm. Yeah. I don't think this is going to work...

I need to remove whatever pixel has the 3 values ' 230, 245, 255' ...which is different then removing from Band 1 = 230, Band 2 = 245, Band 3 = 255. If I do that, I am 'NoData'ing' values I probably want to keep (for ex: '230 246 255' would become '0 246 0'....not right.)

Ok. So to do this another way...is there an elegant way to go from a 3 Band to a 1 Band image (other then just taking 1 of the 2 bands). I know there is a way to go from a Grayscale 1-band to a 3-band RGB ...but is there an inverse of that?





On Wed, Jun 10, 2015 at 10:53 AM, <[hidden email]> wrote:

That vrt snippet looks correct. Only one nodata number per band, and it has the correct value, 230.

 

In my test file 2 or so lines above <ComplexSource> there is an additional line “<NoDataValue>” with the number as a scaled float, “1.80000000000000E+001” (the +001 at end means move decimal to right 1 time. My nodata here is “18”). Full file is attached.

 

Matt

 

From: Ari Simmons [mailto:[hidden email]]
Sent: Wednesday, June 10, 2015 10:24 AM
To: Matt.Wilkie
Cc: Chaitanya kumar CH; [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Matt

Not sure I see how...

    <ComplexSource>
      <SourceFilename relativeToVRT="1">TEX_N00E006.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="1200" RasterYSize="1200" DataType="Byte" BlockXSize="1200" BlockYSize="2" />
      <SrcRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <DstRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <NODATA>230</NODATA>

Do you mean change

 <NODATA>230</NODATA>

to

 <NODATA>230 245 255</NODATA>

 

On Wed, Jun 10, 2015 at 10:20 AM, <[hidden email]> wrote:

Perhaps try editing the .vrt file with a text editor and changing the nodata value by hand?

 

Matt

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Wednesday, June 10, 2015 10:19 AM
To: Chaitanya kumar CH
Cc: [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Ok - so gdal_translate works great! Thanks!

 

HOWEVER, the removal of value 230 245 255 is still no happening...when I put in:

 

 

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif

 

I get a .vrt with Band 1 = 0 (instead of 230) and the full 3 Band value becoming (0 245 255)....not what I expected. I expected it to become "NoData"....

 

 

On Tue, Jun 9, 2015 at 9:17 PM, Chaitanya kumar CH <[hidden email]> wrote:

Ari,

 

The vrt is an xml file that represents a single raster dataset made up of one or many rasters. So, it is already merged. You can read it using any good text editor.

You only have to run gdal_translate to convert it to a tif.

 

gdal_translate -of GTiff tif_index.vrt tif_index.tif

 

On Wed, Jun 10, 2015 at 2:40 AM Ari Simmons <[hidden email]> wrote:

Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

 

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,


and is not recognised as a supported dataset name.

I'm on OSGEO4W too..

 

 

On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:

The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
<a href="tel:867-667-8133" target="_blank">867-667-8133 Tel * <a href="tel:867-393-7003" target="_blank"> 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

 

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/

--

Chaitanya Kumar CH

 

 



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

Re: gdal_merge with a specific pixel value clipped/removed

Matt Wilkie-2

If your image has 3 values for a pixel it is 3 band (RGB: Red, Green, Blue). There are several ways to split an RGB image into distinct pieces, though I don’t recall the details. One is:

 

gdal_translate –b 1 infile.tif red.tif

gdal_translate –b 2 infile.tif green.tif

gdal_translate –b 3 infile.tif blue.tif

 

You’ll need to read through the utility pages for the others:

http://www.gdal.org/gdal_utilities.html

 

Matt

From: Ari Simmons [mailto:[hidden email]]
Sent: Wednesday, June 10, 2015 11:13 AM
To: Matt.Wilkie
Cc: Chaitanya Kumar CH; [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Hm. Yeah. I don't think this is going to work...

 

I need to remove whatever pixel has the 3 values ' 230, 245, 255' ...which is different then removing from Band 1 = 230, Band 2 = 245, Band 3 = 255. If I do that, I am 'NoData'ing' values I probably want to keep (for ex: '230 246 255' would become '0 246 0'....not right.)

 

Ok. So to do this another way...is there an elegant way to go from a 3 Band to a 1 Band image (other then just taking 1 of the 2 bands). I know there is a way to go from a Grayscale 1-band to a 3-band RGB ...but is there an inverse of that?

 

 

 

 

 

On Wed, Jun 10, 2015 at 10:53 AM, <[hidden email]> wrote:

That vrt snippet looks correct. Only one nodata number per band, and it has the correct value, 230.

 

In my test file 2 or so lines above <ComplexSource> there is an additional line “<NoDataValue>” with the number as a scaled float, “1.80000000000000E+001” (the +001 at end means move decimal to right 1 time. My nodata here is “18”). Full file is attached.

 

Matt

 

From: Ari Simmons [mailto:[hidden email]]
Sent: Wednesday, June 10, 2015 10:24 AM
To: Matt.Wilkie
Cc: Chaitanya kumar CH; [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Matt

Not sure I see how...

    <ComplexSource>
      <SourceFilename relativeToVRT="1">TEX_N00E006.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="1200" RasterYSize="1200" DataType="Byte" BlockXSize="1200" BlockYSize="2" />
      <SrcRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <DstRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <NODATA>230</NODATA>

Do you mean change

 <NODATA>230</NODATA>

to

 <NODATA>230 245 255</NODATA>

 

On Wed, Jun 10, 2015 at 10:20 AM, <[hidden email]> wrote:

Perhaps try editing the .vrt file with a text editor and changing the nodata value by hand?

 

Matt

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Wednesday, June 10, 2015 10:19 AM
To: Chaitanya kumar CH
Cc: [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Ok - so gdal_translate works great! Thanks!

 

HOWEVER, the removal of value 230 245 255 is still no happening...when I put in:

 

 

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif

 

I get a .vrt with Band 1 = 0 (instead of 230) and the full 3 Band value becoming (0 245 255)....not what I expected. I expected it to become "NoData"....

 

 

On Tue, Jun 9, 2015 at 9:17 PM, Chaitanya kumar CH <[hidden email]> wrote:

Ari,

 

The vrt is an xml file that represents a single raster dataset made up of one or many rasters. So, it is already merged. You can read it using any good text editor.

You only have to run gdal_translate to convert it to a tif.

 

gdal_translate -of GTiff tif_index.vrt tif_index.tif

 

On Wed, Jun 10, 2015 at 2:40 AM Ari Simmons <[hidden email]> wrote:

Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

 

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,


and is not recognised as a supported dataset name.

I'm on OSGEO4W too..

 

 

On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:

The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
<a href="tel:867-667-8133" target="_blank">867-667-8133 Tel * <a href="tel:867-393-7003" target="_blank"> 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

 

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/

--

Chaitanya Kumar CH

 

 

 


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

Re: gdal_merge with a specific pixel value clipped/removed

Chaitanya kumar CH
In reply to this post by Ari Simmons
Ari,

It looks like you have a raster with classified pixel values. If the number of RGB sets is not more than 256, you can convert it to 8 bit paletted image using rgb2pct.py. Then you will have a single band to represent all colors and a single value to represent the set (230,245,255) which can be set as nodata.

Also, if you look at the example in the doc page of that script, there is a way to create a color table. You can edit that vrt file to set the pixels with those values to transparent by setting c4 to 0.

http://www.gdal.org/rgb2pct.html

On Wed, Jun 10, 2015 at 11:42 PM Ari Simmons <[hidden email]> wrote:
Hm. Yeah. I don't think this is going to work...

I need to remove whatever pixel has the 3 values ' 230, 245, 255' ...which is different then removing from Band 1 = 230, Band 2 = 245, Band 3 = 255. If I do that, I am 'NoData'ing' values I probably want to keep (for ex: '230 246 255' would become '0 246 0'....not right.)

Ok. So to do this another way...is there an elegant way to go from a 3 Band to a 1 Band image (other then just taking 1 of the 2 bands). I know there is a way to go from a Grayscale 1-band to a 3-band RGB ...but is there an inverse of that?





On Wed, Jun 10, 2015 at 10:53 AM, <[hidden email]> wrote:

That vrt snippet looks correct. Only one nodata number per band, and it has the correct value, 230.

 

In my test file 2 or so lines above <ComplexSource> there is an additional line “<NoDataValue>” with the number as a scaled float, “1.80000000000000E+001” (the +001 at end means move decimal to right 1 time. My nodata here is “18”). Full file is attached.

 

Matt

 

From: Ari Simmons [mailto:[hidden email]]
Sent: Wednesday, June 10, 2015 10:24 AM
To: Matt.Wilkie
Cc: Chaitanya kumar CH; [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Matt

Not sure I see how...

    <ComplexSource>
      <SourceFilename relativeToVRT="1">TEX_N00E006.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="1200" RasterYSize="1200" DataType="Byte" BlockXSize="1200" BlockYSize="2" />
      <SrcRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <DstRect xOff="0" yOff="0" xSize="1200" ySize="1200" />
      <NODATA>230</NODATA>

Do you mean change

 <NODATA>230</NODATA>

to

 <NODATA>230 245 255</NODATA>

 

On Wed, Jun 10, 2015 at 10:20 AM, <[hidden email]> wrote:

Perhaps try editing the .vrt file with a text editor and changing the nodata value by hand?

 

Matt

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Wednesday, June 10, 2015 10:19 AM
To: Chaitanya kumar CH
Cc: [hidden email]
Subject: Re: [FWTools] gdal_merge with a specific pixel value clipped/removed

 

Ok - so gdal_translate works great! Thanks!

 

HOWEVER, the removal of value 230 245 255 is still no happening...when I put in:

 

 

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif

 

I get a .vrt with Band 1 = 0 (instead of 230) and the full 3 Band value becoming (0 245 255)....not what I expected. I expected it to become "NoData"....

 

 

On Tue, Jun 9, 2015 at 9:17 PM, Chaitanya kumar CH <[hidden email]> wrote:

Ari,

 

The vrt is an xml file that represents a single raster dataset made up of one or many rasters. So, it is already merged. You can read it using any good text editor.

You only have to run gdal_translate to convert it to a tif.

 

gdal_translate -of GTiff tif_index.vrt tif_index.tif

 

On Wed, Jun 10, 2015 at 2:40 AM Ari Simmons <[hidden email]> wrote:

Interesting...ok, so (knowing nothing about .vrt's and having a bunch of .tiff's) I ran this:

>>gdalbuildvrt -srcnodata "230 245 255" tif_index.vrt *.tif
0...10...20...30...40...50...60...70...80...90...100 - done.

then

 

>> gdal_merge -o merged_result.tif *.vrt

and got

ERROR 4: `*.vrt' does not exist in the file system,


and is not recognised as a supported dataset name.

I'm on OSGEO4W too..

 

 

On Tue, Jun 9, 2015 at 1:24 PM, <[hidden email]> wrote:

The error is because you need to quote the argument values to keep them from being interpreted as filenames:

        gdal_merge -n “230 245 255” ...

However gdal_merge can't use different nodata values for each band. You need to pre-process the files before merging. This worked for me here:

Create  VRT (virtual raster) file for the input file(s):

        gdalbuildvrt -srcnodata "230 245 255”"  infile1.vrt  infile1.tif

Then feed the .vrt's to gdal_merge:

        gdal_merge -of merged_result.tif infile1.vrt infile2.vrt ...


You may need to switch from fwtools to Osgeo4w (if on Windows) to get gdalbuildvrt.

Cheers,

--
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
<a href="tel:867-667-8133" target="_blank">867-667-8133 Tel * <a href="tel:867-393-7003" target="_blank"> 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



-----------------------------

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ari Simmons
Sent: Tuesday, June 09, 2015 12:43 PM
To: [hidden email]
Subject: [FWTools] gdal_merge with a specific pixel value clipped/removed

I have a large set of .tif files and I need to merge/mosaic them all into one .tif with the no-data value removed (i.e. value 230, 245, 255). However, when I put this in...pixel '230, 245, 255' becomes '0, 245, 255').
I am trying to get NO PIXEL returned for 230, 245, 255. Is that possible?
I:\TFS_6\trial_merge>gdal_merge.py -o test.tif -n 230 245 255 file1.tif file2.tif

ERROR 4: `245' does not exist in the file system,
and is not recognised as a supported dataset name.

ERROR 4: `255' does not exist in the file system,
and is not recognised as a supported dataset name.

0...10...20...30...40...50...60...70...80...90...100 - done.

 

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/

--

Chaitanya Kumar CH

 

 


--

Chaitanya Kumar CH


_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/
Loading...