1

I have 400 PNG files all of the same area that are not gereferenced. I have gereferenced one of them and want to use the world file for all the others. I could copy it and rename the files but that will take forever. It there a way in QGIS to point the png files to a worldfile?

  • I don't think there is a way that doesn't involve writing a little program to do it, which you could do in python and run in the QGIS console. If you are on a Mac or Linux machine (or Windows with the Linux command stuff) you could also write a shell script program to do it, which is what I'd probably do. – Spacedman Jan 31 '18 at 8:03
1

Here's how I'd do it using shell script.

Here's a folder with a bunch of .png files, and a folder called world which has a single world file in it.

.
├── arg.png
├── f1.png
├── f2.png
├── f3.png
├── world
│   └── f2.pngw
└── zz.png

I've set things up like this, temporarily separating f2.png from its world file just to make things a bit cleaner for the next step. Which is to run the following command from my terminal:

for f in *.png ; do cp world/f2.pngw ${f}w ; done

and now my folder looks like this:

.
├── arg.png
├── arg.pngw
├── f1.png
├── f1.pngw
├── f2.png
├── f2.pngw
├── f3.png
├── f3.pngw
├── world
│   └── f2.pngw
├── zz.png
└── zz.pngw

Every png has a pngw copied from the one in world/f2.pngw.

This for line works by looping over all files that match *.png and executing cp world/f2.pngw ${f}w, where ${f} is the png file name being worked on. Hence it does:

cp ./world/f1.pngw ./f1.pngw
cp ./world/f1.pngw ./zz.pngw
cp ./world/f1.pngw ./arg.pngw
cp ./world/f1.pngw ./f2.pngw

and so on for all the png files, even if there's 400, in one go.

This should work from Mac and Linux terminals, and it is possible to install something that will do exactly this in Windows, although I forget what its called these days (Windows Linux Subsystem or something???)

  • Thanks Spacedman. I need to wrap my head around this and figure out the windows version. – Louwrens Jan 31 '18 at 8:23
  • Is there a way to do this in windows cmd batch file? My system does not want to install any linux subsystems? – Louwrens Jan 31 '18 at 8:45
  • I have next to no skills with Windows CMD stuff, and if I was forced to do this on a Windows box I'd use Python in QGIS. Python has a full set of file copy and rename utilities. – Spacedman Jan 31 '18 at 8:47

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.