• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

How to copy projections from GeoTiff to Tiff automatically?

Messages
22
Country
finland
Hello
I have more then 100 GeoTIFF files, from it I made water/blend masks and summer/winter imagery TIFF files. Of course after editing in photoshop thay lost projection. What is the best and faster way to copy projection from original GeoTIFF to edited copies of TIFF files?
1. Easy to do it for one or two files with Global Mapper. Open original file and in Tools-Control Center get Metadata, copy it to clipboard, paste in temporary text file, then open edited file and manualy Rectify Image by "Add Point". But this method is not good, when I want to copy projections to more then 400 files.
2. I try to generate .tab files from original images with Global Mapper, then rename it to every sources and also rename file name inside .tab file. But it not work correctly and why I have no idea. By this way I have correct latitude, but longitude is not correct.

3. Via google I find script gdalcopyproj.py which waybe a usefull tool, but I have no idea how to run it.
4. When I read our forum I find good tool GeoTiffToInf.exe. With it I can capture geo information from original file and copy/paste to .inf file. In first look it work and now this is faster way.

But maybe you have some advices with better ways. Also I would like to run gdalcopyproj.py to try it and hope you know how to run it.

Thank you
 
Messages
173
Country
unitedstates
When working with a GeoTiff I export a TFW file that contains coordinates and x/yDim. A few lines of BASIC code and I have a program that turns the TFW into an INF file for Resample.
 
Messages
22
Country
finland
Finaly I want way like this.
With some instrument like in OSGeo4W run some command, which copy geoinfo from file (Name) and paste geoinfo to file (Name_blablabla), then save it to file (Name_blablabla_geo) and do it for all files in directory :rolleyes:
 
Messages
22
Country
finland
I have small progrees here. Now I can run script gdalcopyproj.py for one file. And it apply projection in few seconds. Before I just have to install Python on my PC, create this script in txt file, save it with .py and place it in the same directory with OSGeo4W.

To copy projection from one to another file I use this command gdalcopyproj.py source_file dest_file.

But can you help me to create .bat file which can run this command for all directoty?
For example I have source file K3223H.tif and edited K3223H_bm.tif, K3223H_imagery_su.tif, K3223H_imagery_hw.tif, K3223H_wm.tif
 
Last edited:
Messages
7,450
Country
us-illinois
Possibly a type of CMD Mode (aka "DOS") batch routine using a "For loop", involving a FOR... IN... DO... structure, such as utilized in:

* Arno's example ? :scratchch:

http://www.scenerydesign.org/category/nantucket/


* rhumbaflappy's example: ?

http://www.fsdeveloper.com/forum/threads/nearmap-tiles-sbx.246615/


Perhaps someone more familiar with this approach might offer a customized routine for the OP to achieve his task 'for all items in a folder' ? ;)

[EDITED]

FYI: I finally found the 'interactive tutorial' links I had once posted in a thread here years ago:

http://www.robvanderwoude.com/for.php

http://www.robvanderwoude.com/ntfortokens.php

http://www.robvanderwoude.com/forinteractive.php


Apparently one can also specify the folder (aka "directory"), or a tree of folders (aka "directories") ...in which the batch routine is intended to "loop" (aka "iterate") through recursively:

http://www.computerhope.com/forhlp.htm


And, interestingly, Python has its own internal implementation of a "ForLoop":

https://wiki.python.org/moin/ForLoop

[END_EDIT]

GaryGB
 
Last edited:
Messages
22
Country
finland
With help on another forum I get code for bat file, which made it all automatically and very fast (about 5 minutes for 120 files)! I hope it will be usefull for other who want to copy projections to edited TIFFs.

@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"
)
)
 
Last edited:
Messages
1,521
Country
unitedstates
Hey vanyuha,

I would be most interested in this but trying to wrap my arms around it on how it to make it work. Questions:

1. So from what I see you run the bat file above to run the python script?
2. Do I need to install some sort of python program? Or are you running this using OSGeo4W?
3. How do you extract the geo info from tiff's before you drop into Photoshop?
4. Can tiffs be in any folder to work to cgange back to geoTiffs? Do I need to have the .py script or bat file in the same folder as the tiffs?

Any help would be most appreciated.

Clutch
 
Messages
1,521
Country
unitedstates
Vanyuha,

Following your posts above, I installed OSgeo4W (which appears to have python included). Using the script gdalcopyproj.py as stated I tried one tiff file like you did before using the .bat file. But I get the following error message in the command line when I run it.

"ImportError: No module named gdal"

Did you come across that in your first tests?

thx,

Clutch
 
Messages
1,521
Country
unitedstates
Well, after a few days so far no luck. Looking closely at vanyuha's post above it seems pretty straightforward.

1. Install OSGeo4W (python is installed with this)
2. Place the gdalcopyproj.py script in the OSGeo4W main directory.
3. Add a couple of tiff files in the same OSGeo4W directory
4. Start up the OSGeo4W bat file to give me their command prompt.
5. Type in "C:\OSGeo4W>gdalcopyproj.py filename_with_geo.tiff filename_with_no_geo.tif" and press Enter.
6. I get no error messages but all I see as a result is "Usage: gdalcopyproj.py source_file dest_file"

and that's all she wrote! Anyone see what I am missing as I guess vanyuha is no longer around these parts.
 
Messages
1,243
Country
canada
I got it to work: (kinda)

My tif files are in C:\users\public\documents
The gdalcopyproj.py is in the same folder.

in the OSGeo4W cmd windows change to cd C:\users\public\documents

type:

python gdalcopyproj.py source_file dest_file

at the C:\Users\Public\Documents prompt.
 
Messages
1,521
Country
unitedstates
GOOD SHOW, 'OL MAN! :D

That worked for me too. I used your exact instructions. Not sure if it is because of taking the files out of OSGeo4W that made it work or that you used the text "python' at the front which I had not tried. Now onto trying some different directory locations. It took me 2 hours to manually rectify 25 images. This will do it in minutes. (Ooops... I think seconds!)

A tip of the wing for giving it a go. Now onto that batch file above.... :eek:

Clutch
 
Last edited:
Messages
22
Country
finland
Well, after a few days so far no luck. Looking closely at vanyuha's post above it seems pretty straightforward.

1. Install OSGeo4W (python is installed with this)
2. Place the gdalcopyproj.py script in the OSGeo4W main directory.
3. Add a couple of tiff files in the same OSGeo4W directory
4. Start up the OSGeo4W bat file to give me their command prompt.
5. Type in "C:\OSGeo4W>gdalcopyproj.py filename_with_geo.tiff filename_with_no_geo.tif" and press Enter.
6. I get no error messages but all I see as a result is "Usage: gdalcopyproj.py source_file dest_file"

and that's all she wrote! Anyone see what I am missing as I guess vanyuha is no longer around these parts.
Sorry for late answer!
As I understand, you can now run gdalcopyproj.py script. I can show, how I run my batch file for all directory. First I move all tiff files to the same directory and move there my batch file. It looks like in attached image. Where sources files are K3222A.tif, K3222B.tif, K3222D.tif and so on. Butch file copy projections from them and apply it to files with the same name + _bm, _wm, _imagery_su, _imagery_hw. Then I start OSGeo4W, navigate via cd command to this directory and just write name of my batch file (I named it copyproj.bat)copyproj.bat and hit Enter and process started.
One important note. Batch file was wrote for tiff files that have name with SIX symbols only. If names of your files have different numbers of symbols it will not work. You can change ??????.tif and ......\.tif parts in batch file for names of your tiff files.
I hope you understand my bad english ;)
 

Attachments

  • directory.jpg
    directory.jpg
    126.1 KB · Views: 534
Messages
1,521
Country
unitedstates
Hey vanyuha,

Thanks for dropping back in. I have followed your steps and still no luck. The error message is:

'gdalcopyproj' is not recognized as an internal or external command, operable program or batch file.

So my first question is where do you have your gdalcopyproj.py file placed? Mine is in the main directory of OSGeo4W.

OK....UPDATE>>>> WE GOT IT WORKING! (been testing as I have been typing, ha!)

Apparently, the whole problem for me was the bat file could not find the gdalcopyproj.py. I just tried it by placing it also in the directory of the files and the .bat file and it worked! Is that where you have your .py file as well?

I see how yours is customized for your filename convention. I added two more "??" and ".." as mine is eight characters. Now I just need to test with a whole directory.

Clutch

Just tried a directory with 60GB of images. Converted the whole lot in SECONDS. Using Global Mapper took an average of two hours. Just want to say a big Thank You!
 
Last edited:
Messages
22
Country
finland
I have two places where is my .py exist. First: in main directory c:\Program Files (x86)\QGIS Dufour, and second c:\Program Files (x86)\QGIS Dufour\apps\Python27\Scripts. But I dont know where from is right one work :D
 
Top