HOW TO

How to create a DOQ header (.hdr) file. [SCRIPT]

Last Published: April 25, 2020

Procedure

Question:

How to create a header (hdr) file for a DOQ using the information provided in the beginning portion of the DOQ.
Cause:

USGS provides the new 3-band DOQ images as uncompressed 150MB files without a header (hdr) file.
Answer:

The following script reads the information provided at the start of the DOQ to create a header file for the DOQ. This script only works with the new DOQ files that have 'BEGIN_USGS_DOQ_HEADER' in the first line.

Code:
''Begin Script
validext = {"bip","bil","bsq"}
imagelist = sourcedialog.showclass("Select DOQ file",imgsrc)
if(imagelist.isempty) then
return nil
end
imagefile = imagelist.get(0).asstring.asfilename
imgext = imagefile.getextension.lcase
if(validext.findbyvalue(imgext) = -1) then
msgbox.error("."+imgext++" is not a valid DOQ extension. (.bil, .bip or .bsq)","")
return nil
end

tf = textfile.make(imagefile,#FILE_PERM_READ)
buffer = tf.read(80)
if(buffer.contains("BEGIN_USGS_DOQ_HEADER").not) then
msgbox.error("This file does not contain a valid header.","")
return nil
end

while(tf.isatend.not)
buffer = tf.read(80)
if(buffer.extract(0) = "BAND_ORGANIZATION") then
buff = buffer.extract(1).lcase
if((buff = "bip") or (buff = "bsq")) then
nbands = "3"
else
nbands = "1"
end
elseif(buffer.extract(0) = "HORIZONTAL_DATUM") then
datum = buffer.extract(1)
elseif(buffer.extract(0) = "HORIZONTAL_COORDINATE_SYSTEM") then
projection = buffer.extract(1)
elseif(buffer.extract(0) = "COORDINATE_ZONE") then
zone = buffer.extract(1)
elseif(buffer.extract(0) = "HORIZONTAL_UNITS") then
iunits = buffer.extract(1)
elseif(buffer.extract(0) = "SAMPLES_AND_LINES") then
nrows = buffer.extract(2)
ncols = buffer.extract(1)
elseif(buffer.extract(0) = "XY_ORIGIN") then
ulxmap = buffer.extract(1)
ulymap = buffer.extract(2)
elseif(buffer.extract(0) = "BYTE_COUNT") then
skipbytes = buffer.extract(1)
tf.gotoend
end
end
tf.close

newfile = imagefile.clone
newfile.setextension("hdr")
header = linefile.make(newfile,#FILE_PERM_WRITE)
header.writeelt("nrows"++nrows)
header.writeelt("ncols"++ncols)
header.writeelt("ulxmap"++ulxmap)
header.writeelt("ulymap"++ulymap)
header.writeelt("skipbytes"++skipbytes)
header.writeelt("xdim 1")
header.writeelt("ydim 1")
header.writeelt("nbands"++nbands)
header.writeelt("projection"++projection)
header.writeelt("zone"++zone)
header.writeelt("datum"++datum)
header.writeelt("units"++iunits)
header.close
''End Script

Article ID:000001495

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic