IMAGINE Discussions

Discuss and share topics of interest using ERDAS IMAGINE the world’s leading geospatial data authoring system.
Showing results for 
Search instead for 
Do you mean 
Reply
Frequent Contributor
Posts: 134
Registered: ‎04-11-2016
Accepted Solution

Fix bad Tiffs using TFW files

Hi Team

 

I have thousand Tiff files and many of them come with bad geotiff tags. Some of them don't have projection defined, some of them have different projection units and some of them come with wrong x,y pixel centre values...

When I load these tiff in IMAGINE they are scatted all over the world.. 

I have TFW files for all of the Tiffs, my question is: is there a way to fix the Tiffs with the TFW files that I have?(let's hope these TFW are all good). 

P.s. I have heard that you can strip off the bad geotiff tags first and then reassign as per the TFW definition... Anyone had done it before?

 

Cheers

Yuan

 

Frequent Contributor
Posts: 153
Registered: ‎10-27-2015

Re: Fix bad Tiffs using TFW files

[ Edited ]

I would try two methods:

 

1) Delete map model method by tools

 

  • put TFW's to some other folder
  • Use Edit Image Metadata tool and there delete projection and delete mapmodel in batch
  • Bring TFW's back in same folder and see did we fix the issue

 

2) Second brute force method if previous will not take map models out

  • Again move TFW's to safe location
  • Export all TIF files to some non compressed format that contains for sure no geometric information at all
  • Import files to TIF again
  • And join TFW's to same folder
  • And now I am pretty sure it works - it might be that you need to still add projection in metadata but in this approach coordinate numbers should come from TFW for sure.

 

The point is that TIF TAG's tends to be bit sticky sometimes and it well might be that they will not get lost in method 1. Just converting tif's to new tif's will not help as Imagine always writes GeoTIF tags and if you write new tif's there is a big change that wrong tags will follow. Also one issue here is that Imagine always respects coordinates found inside files more than world files which means that you must somehow get rid of internal coordinates before world file is applied.

 

As a enhancement request for this it would be nice to have

1) Write TIF without geotif headers - if my solution 1 works then it is a good workaround for this

2) Option to choose in file opening do we respect internal or world file based coordinates

 

Any other ideas or solutions to this challenge?

 

timo

Frequent Contributor
Posts: 134
Registered: ‎04-11-2016

Re: Fix bad Tiffs using TFW files

Hi Timo

 

I tried both of the methods you suggested, didn't quite work for me.

However we have discovered a workflow that works, here is the workflow:

 

  1. we created a batch scripts that runs ISRU to: a. reporject the tiffs to our NZTM (oen of our local cs, for some reason we cannot set t) b. set the map unit to meter 3. fix geotif tags with TFW. See batch command below:
    @echo off
    rem Change geotif tags to input twf (world) file and proj4 string (currently hard coded to NZTM).
    rem
    rem S.Falconer
    rem 2016
    rem 
    rem Requires ISRU (Free with GeoMedia or free from Intergraph website)
    rem
    rem
    rem example:
    rem ChangeGeotiffTie.bat D:\data\images\newurban\ D:\data\images\newurban\fixed\
    
    setlocal
    set PATH=C:\Program Files (x86)\ISRU\bin;C:\Program Files (x86)\Common Files\ZI Imaging;C:\Program Files (x86)\Common Files\Intergraph;%PATH%;
    
    set in_dir=%~1
    set out_dir=%~2
    if "%out_dir%"=="" set out_dir=%in_dir%
    rem set in_dir=C:\Data\client\mcc\images\
    rem set out_dir=C:\Data\client\mcc\images\out\
    
    REM - Add geotif tie from world file via -E
    REM - Add coordiante ssytem definition with units via proj4 definition via -4. Following is setting NZTM with units in meters
    for %%a in ("%in_dir%\*.tif") do geotifcp -4 "+proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" -e "%in_dir%\%%~na.tfw" "%in_dir%\%%~nxa" "%out_dir%\%%~nxa"
    
    rem popd
    
    endlocal
  2. use IMAGINE batch command to bulk change projection from NZTM to NZMG (for some reason proj4 doesn't like NZMG, had to use NZTM in step one

Hope it helps.

 

Cheers

Yuan