' Name: DOQ.CreateHDRFile ' Purpose: Reads the header from a non-compressed DOQ image and creates ' an ArcView HDR file with ' the same name as the DOQ with an .hdr extension ' Author: Tim Loesch Minnesota Department of Natural Resources ' Date: 7-13-98 ' Modified: Phil Hurvitz, phurvitz@nwgeospatial.com ' Date: 2000.02.22 ' first define the header list contents so that we can get them in ArcView ' headerElementList = { {"BEGIN_USGS_DOQ_HEADER","*"}, {"QUADRANGLE_NAME","3.45 or 7.5-min. name*"}, {"QUADRANT","quadrant indicator if cell size = 3.75-minutes*"}, {"WEST_LONGITUDE","signed deg min sec SDDD MM SS.SSS*"}, {"EAST_LONGITUDE","signed deg min sec SDDD MM SS.SSS*"}, {"NORTH_LATITUDE","signed deg min sec SDDD MM SS.SSS*"}, {"SOUTH_LATITUDE","signed deg min sec SDDD MM SS.SSS*"}, {"PRODUCTION_DATE","yyyy mm dd*"}, {"RASTER_ORDER","video display order*"}, {"BAND_ORGANIZATION","single file or BSQ, or BIL or BIP*"}, {"BAND_CONTENT","black&white or red green blue*"}, {"BITS_PER_PIXEL","radiometric resolution*"}, {"SAMPLES_AND_LINES","number of columns and rows*"}, {"HORIZONTAL_DATUM","primary horizontal datum*"}, {"HORIZONTAL_COORDINATE_SYSTEM","*"}, {"COORDINATE_ZONE","coordinate system zone number*"}, {"HORIZONTAL_UNITS","coordinate system units*"}, {"HORIZONTAL_RESOLUTION","pixel horiz. ground sample distance*"}, {"SECONDARY_HORIZONTAL_DATUM","secondary horizontal datum*"}, {"XY_ORIGIN","coord. of upper left pixel pri. datum*"}, {"SECONDARY_XY_ORIGIN","coord upper left pixel sec datum*"}, {"NATION","nation code*"}, {"STATE","state fip code*"}, {"NW_QUAD_CORNER_XY","XY coords. of pri. NW quad corner*"}, {"NE_QUAD_CORNER_XY","XY coords. of pri. NE quad corner*"}, {"SE_QUAD_CORNER_XY","XY coords. of pri. SE quad corner*"}, {"SW_QUAD_CORNER_XY","XY coords. of pri. SW quad corner*"}, {"SECONDARY_NW_QUAD_XY","XY coords. - sec. NW quad cor.*"}, {"SECONDARY_NE_QUAD_XY","XY coords. - sec. NE quad cor.*"}, {"SECONDARY_SE_QUAD_XY","XY coords. - sec. SE quad cor.*"}, {"SECONDARY_SW_QUAD_XY","XY coords. - sec. SW quad cor.*"}, {"RMSE_XY","doq horiz. accuracy*"}, {"IMAGE_SOURCE","b&w, cir, natural color, other*"}, {"SOURCE_IMAGE_ID","source image id*"}, {"SOURCE_IMAGE_DATE","source image date as yyyy mm dd*"}, {"SOURCE_DEM_DATE","source dem date yyyy mm dd*"}, {"AGENCY","oversight agency*"}, {"PRODUCER","producer/contractor*"}, {"PRODUCTION_SYSTEM","production system*"}, {"STANDARD_VERSION","version of DOQ standard*"}, {"METADATA_DATE","date created or changed, yyyy mm dd*"}, {"DATA_FILE_SIZE","data set size in bytes*"}, {"BYTE_COUNT","header byte count*"}, } ' get the names of the images the user want's to create headers for ' imagelist = filedialog.returnfiles({"*"},{"Images"},"Select Image",0) if (imagelist.count < 1) then return nil end ' determine the system OS for the "move" command theSysOS = System.GetOS.AsString.Ucase if (theSysOS = "SYSTEM_OS_MSW") then theSysOSType = "win" theSysSupport = "supported" elseif (theSysOS = "SYSTEM_OS_UNIX") then theSysOSType = "unix" theSysSupport = "supported" mvCmd = "mv" elseif (theSysOS = "SYSTEM_OS_OS2") then theSysOSType = "os2" theSysSupport = "supported" mvCmd = "REPLACE" elseif (theSysOS = "SYSTEM_OS_VMS") then theSysOSType = "vms" theSysSupport = "supported" mvCmd = "RENAME" else theSysSupport = "unsupported" end for each img in imagelist imgString = img.AsString imgBase = img.GetBaseName imgPath = imgString.Substitute(imgBase, "") defaultNewName = imgString.Substitute(".", "_")+".bil" ' only move if the OS supports the command if (theSysSupport = "supported") then imgRename = MsgBox.YesNo("Rename the image?", "Rename", True) if (imgRename = True) then newName = msgBox.Input("Enter the new image name", "Rename", defaultNewName) theCmdName = "xxxx0000rename.bat" 'Windows if (theSysOSType = "win") then 'write a batch file?!! theBatchFile = lineFile.Make( theCmdName.AsFileName, #FILE_PERM_WRITE ) theBatchFile.WriteElt( "move"++img.AsString++newName ) theBatchFile.WriteElt( "del"++theCmdName ) theBatchFile.close System.ExecuteSynchronous(theCmdName) end 'if windows 'Other OS if ((theSysSupport = "supported") and (theSysOSType = "win").Not) then System.ExecuteSynchronous(mvCmd++img.AsString++newName) end 'if other OS img = newName.AsFileName end 'if rename end 'if rename support theimage = textfile.make(img,#File_Perm_Read) head_dict = dictionary.make(50) for each i in 1..200 theline = (theimage.read(80)).trim headerline = theline.astokens(" ").get(0) head_dict.add(headerline,theline) if (headerline = "BYTE_COUNT") then break end end ' now create the image header ' ' determine the type of image BIL, BSQ, or BIP ' tmp = head_dict.get("BAND_ORGANIZATION") if (tmp.indexof(headerelementlist.get(9).get(1)) > -1) then tmp = tmp.left(tmp.indexof(headerelementlist.get(9).get(1))) else tmp = tmp.left(tmp.indexof("*")).trim end offset = headerelementlist.get(9).get(0).count BandOrg = tmp.right(tmp.count - offset).trim.unquote if (BandOrg = "SINGLE FILE") then thelayout = nil nbands = nil elseif (BandOrg = "BSQ") then thelayout = "bsq" nbands = 3 elseif (BandOrg = "BIL") then thelayout = "bil" nbands = 3 elseif (BandOrg = "BIP") then thelayout = "bip" nbands = 3 else thelayout = nil nbands = nil end ' determine the number of bits per pixel in the image ' tmp = Head_dict.get("BITS_PER_PIXEL") if (tmp.indexof(headerelementlist.get(11).get(1)) > -1) then tmp = tmp.left(tmp.indexof(headerelementlist.get(11).get(1))) else tmp = tmp.left(tmp.indexof("*")).trim end offset = headerelementlist.get(11).get(0).count nbits = tmp.right(tmp.count - offset).trim ' get the number of rows and columns in the image ' tmp = Head_Dict.get("SAMPLES_AND_LINES") if (tmp.indexof(headerelementlist.get(12).get(1)) > -1) then tmp = tmp.left(tmp.indexof(headerelementlist.get(12).get(1))) else tmp = tmp.left(tmp.indexof("*")).trim end offset = headerelementlist.get(12).get(0).count tmp = tmp.right(tmp.count - offset).trim.astokens(" ") numcols = tmp.get(0).trim numrows = tmp.get(1).trim ' read the x and y coordinate of the upper left pixel ' tmp = Head_Dict.get("SECONDARY_XY_ORIGIN") if (tmp.indexof(headerelementlist.get(20).get(1)) > -1) then tmp = tmp.left(tmp.indexof(headerelementlist.get(20).get(1))) else tmp = tmp.left(tmp.indexof("*")).trim end offset = headerelementlist.get(20).get(0).count tmp = tmp.right(tmp.count - offset).trim.astokens(" ") ulxmap = tmp.get(0).trim ulymap = tmp.get(1).trim ' read the cell size of the image ' tmp = head_dict.get("HORIZONTAL_RESOLUTION") if (tmp.indexof(headerelementlist.get(17).get(1)) > -1) then tmp = tmp.left(tmp.indexof(headerelementlist.get(17).get(1))) else tmp = tmp.left(tmp.indexof("*")).trim end offset = headerelementlist.get(17).get(0).count tmp = tmp.right(tmp.count - offset).trim xdim = tmp ydim = tmp ' read the byte offset between the beginning of the file and the beginning of the image ' i.e., the size of the header in bytes ' tmp = Head_Dict.Get("BYTE_COUNT") if (tmp.indexof(headerelementlist.get(42).get(1)) > -1) then tmp = tmp.left(tmp.indexof(headerelementlist.get(42).get(1))) else tmp = tmp.left(tmp.indexof("*")).trim end offset = headerelementlist.get(42).get(0).count skipbytes = tmp.right(tmp.count - offset).trim ' now create the header file as a LineFile object ' theheadername = theimage.getfilename.clone theheadername.setextension("hdr") f1 = LineFile.make(theheadername,#FILE_PERM_WRITE) f1.writeElt("nrows"++numrows) f1.writeElt("ncols"++numcols) f1.WriteElt("ulxmap"++ulxmap) f1.WriteElt("ulymap"++ulymap) f1.WriteELT("xdim"++xdim) f1.WriteELT("ydim"++ydim) f1.WriteELT("nbits"++nbits) if (thelayout <> nil) then f1.WriteElt("layout"++thelayout) end if (nbands <> nil) then f1.WriteElt("nbands"++nbands.asstring) end f1.writeELT("skipbytes"++skipbytes) f1.close end