Hi there,
Yes a nube with very little experience so I am seeking help. Here's some background info:
I have a python script 'gdalcopyproj.py' (I did not write it), and it works great. Basically it takes a tiff geo-referenced image file and transfers that information into another tiff image that does not have geo-referenced data.
The script is written to apply this one file at a time "gdalcopyproj.py source_file dest_file". One uses it inside the command prompt of a program called OSGeo4W to implement the script. For example, it looks like so in the command window.
C:\OSGeo4W>python gdalcopyproj.py SOCAL_CZ62.tif SOCAL_CZ62_LM.tif
My goal is to process a whole folder of files at once. I do have a batch file that has been created for another user. Appears to be somewhat custom for his needs. Here is that batch file:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
@for /f "delims=" %%i in ('2^>nul dir/a-d/b
.tif^| findstr/i "^......\.tif$"') do @(
for /f "delims=" %%j in ('2^>nul dir/a-d/b "%%~ni_*.tif"') do @(
gdalcopyproj.py "%%i" "%%j"
)
)
What I do not understand is how to use/setup this batch file. It appears to be seeking a certain type of file which has six characters and converts similarly named files which have custom filenames after the _. Is this correct? Can I customized that to fit my needs?
Second, where does one put this batch file. I have tried in the same folder as the files. I have tried in the directory of OSGeo4W but no luck. I have tried running the batch directly or from inside a command window. Still no luck. Either I get an error message or simply nothing happens. This where I am stuck.
Can someone explain how to use this batch file somewhat step-by-step?
Clutch
P.S. not sure if you need the python script to help explain but here she is:
try:
from osgeo import gdal
except ImportError:
import gdal
import sys
if len(sys.argv) < 3:
print("Usage: gdalcopyproj.py source_file dest_file")
sys.exit(1)
input = sys.argv[1]
dataset = gdal.Open( input )
if dataset is None:
print('Unable to open', input, 'for reading')
sys.exit(1)
projection = dataset.GetProjection()
geotransform = dataset.GetGeoTransform()
if projection is None and geotransform is None:
print('No projection or geotransform found on file' + input)
sys.exit(1)
output = sys.argv[2]
dataset2 = gdal.Open( output, gdal.GA_Update )
if dataset2 is None:
print('Unable to open', output, 'for writing')
sys.exit(1)
if geotransform is not None and geotransform != (0,1,0,0,0,1):
dataset2.SetGeoTransform( geotransform )
if projection is not None and projection != '':
dataset2.SetProjection( projection )
gcp_count = dataset.GetGCPs()
if gcp_count != 0:
dataset2.SetGCPs( gcp_count, dataset.GetGCPProjection() )
dataset = None
dataset2 = None
P.S.S - Here is even another batch file for the same purpose if this helps but still no luck... sorry coding is not my best suit. Appears this one would take any file name up to the point of a "_"? am I understanding this correct?
@echo off
for /f "delims=" %%a in ('dir /b *.tif ^| findstr /v /c:"_.tif"') do gdalcopyproj.py "%%~a" "%%~na_.tif"