1

This is a bit of a cry for help as I’m still quite new to this.

I am looking to create a thing that can validate some specific parameters for TIFF and TFW files, preferable using python, FME or something similar.

  • It is a TIFF file
  • TIFF file size – This should be equal to or greater than 46MB – Equal to or less than 47MB
  • TIFF dimensions – they should be 4000 * 4000 pixels in size
  • It has three colour bands
  • It has an associated, valid TFW file

I’ll roughly have to check 100 TIFF and 100 TFW files at a time.

The TIFF and TFW files have the corresponding 1KM grid reference as their names, for example I have TQ7926.tif and TQ7926.tfw.

What would be the best way to achieve this? I’m happy to answer any questions to assist with the answering of my question.

My python GDAL knowledge is pretty poor, so i've had ago in FME. See my fmw here

I'd really appricate any feedback on it or suggestions to make it quicker/tidier/better. It needs to be used on a directory of folders containing TIFFs

2

Since GDAL provides a well-documented python API this is reasonably easy to do in python.

from osgeo import gdal
import sys
import os
# this allows GDAL to throw Python Exceptions
gdal.UseExceptions()

file='/data/os-data/rasters/streetview/tq/tq00ne.tif'
try:
    gtif  = gdal.Open( file )
except RuntimeError, e:
    print 'Unable to open '+file
    print e
    sys.exit(1)

#print gtif.GetMetadata()
statinfo = os.stat(file)
size=statinfo.st_size/1e6

print size,"Mb"

print "bands ",gtif.RasterCount

cols = gtif.RasterXSize
rows = gtif.RasterYSize
print cols," cols x ",rows," rows"
gtif = None

If you wrap this into a function and then loop through the .tif files in your directory this should work.

0

I've refined my fmw a fair amount now and so far it does the job. Happy to receive any feedback or suggestions on how to make it quicker or simpler.

fmw

  • I've been burned in the past by geotiffs that have tfw files - how does your tool deal with that situation? – Kirk Kuykendall Nov 29 '17 at 20:20
  • 1
    I've not come across this problem myself, however I believe you could add in a new test or after the Path & Directory Reader and the first attribute filter to check if there are any tfw and geotiffs that match in name. Further to that you could use the feature merger with the geotiffs as the supplier and tfw as the requester and see the results from that. Either way you can use the path and directory reader with an attribute filter to remove unwanted tfw files. – JG_RS_GIS Dec 11 '17 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.