1

I am reading a single row from a text file createvrt_row0.txt. The row is :

E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E2.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E3.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E4.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E5.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E6.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E7.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E8.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E9.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E10.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E11.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E12.tif;

Python code which I used in QGIS Python Console for reading this single line in the text file is :

data = open('E:/Sreeraj/Task Global Data CONVERSION/Split/output/task/createvrt_row0.txt', 'r')

Now, I deleted the last " ; " by doing :

data_str = str(data)
data_vrt = data_str[:-1]

So, now :

data_vrt = E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E2.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E3.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E4.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E5.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E6.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E7.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E8.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E9.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E10.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E11.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E12.tif

Then, I want this data_vrt string inside double quotes (" ").

TIF_files = '"' + str(data_vrt) + '"'

So, now :

TIF_files = "E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E2.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E3.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E4.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E5.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E6.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E7.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E8.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E9.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E10.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E11.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E12.tif"

This TIF_files string is used as the input file for the tif files which have to be finally converted to a single .vrt file in QGIS. For that I used the following python code in QGIS Python Console.

output_vrt = "E:/Sreeraj/Task Global Data CONVERSION/Split/output/outvrt.vrt"
from processing.tools import * 
general.runalg("gdalogr:buildvirtualraster",TIF_files,0,True,False,output_vrt)

Unfortunately, I am getting an error in Python Console as :

Unable to execute algorithm
Wrong parameter value: "E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E2.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E3.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E4.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E5.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E6.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E7.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E8.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E9.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E10.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E11.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E12.tif"  

Because of this error, I am not getting the output .vrt file.

But. I just tried copying this tif files and assigned this to a variable x as given below :

x = "E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E2.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E3.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E4.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E5.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E6.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E7.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E8.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E9.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E10.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E11.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E12.tif"

Now, when I try to run the python code, the output .vrt file is getting generated successfully.

general.runalg("gdalogr:buildvirtualraster",x,0,True,False,output_vrt)

But, when I am trying with "TIF_files" instead of "x" , I am agian getting the error. Actually, both "TIF_files" and "x" have the same string. This is really confusing and I am not able to solve the error "Wrong parameter value:".

Please help me to solve this issue.

closed as off-topic by user30184, nmtoken, BERA, Kersten, whyzar Jan 12 '18 at 13:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – user30184, nmtoken, BERA, Kersten, whyzar
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Try with data_vrt, perhaps it is known to be string already. – user30184 Jan 12 '18 at 7:18
  • 1
    @user30184 But, I want data_vrt inside double quotes (then only the syntax will be correct for general.runalg().). That's why I tried with TIF_files = '"' + str(data_vrt) + '"' . Also, when I tried doing like TIF_files = '"' + data_vrt + '"' (by considering that data_vrt is known to be a string already), still I am getting the error. – Sreeraj Jan 12 '18 at 7:36
  • What we know is that x works but TIF_files does not work so they cannot be equal. And if you test by x="test" print x vs. y='"' + str(x) + '"' print y you will see that with the syntax you used for x the double quotas are not included in the string. – user30184 Jan 12 '18 at 8:51
  • 1
    @user30184 When I tried giving data_vrt directly inside the algorithm, it worked and the issue is solved now. general.runalg("gdalogr:buildvirtualraster",data_vrt,0,True,False,output_vrt) . The algorithm automatically creates double quotes on both sides of data_vrt when we give that variable as an input inside the algorithm. – Sreeraj Jan 12 '18 at 9:28
1

No need of giving double quotes on both sides of data_vrt .

TIF_files = '"' + str(data_vrt) + '"'  // No need of this statement in my program.

It is possible to directly give data_vrt (without any double quotes) as input into the algorithm.

general.runalg("gdalogr:buildvirtualraster",data_vrt,0,True,False,output_vrt)  // This will solve the issue. 

The algorithm automatically used double quotes on both sides of data_vrt and executed the program successfully.

Remember,

data_vrt = E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E2.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E3.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E4.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E5.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E6.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E7.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E8.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E9.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E10.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E11.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E12.tif  

But, if we assign this input into a variable x, then we have to use double quotes on both sides of the list of tif files.

x = "E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E2.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E3.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E4.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E5.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E6.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E7.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E8.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E9.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E10.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E11.tif;E:/Sreeraj/Task Global Data CONVERSION/Split/1 deg tiles_Global agri_data/N31E12.tif"

So,

general.runalg("gdalogr:buildvirtualraster",x,0,True,False,output_vrt)

will also work.

The main point is data_vrt is a line which is directly taken as an input from a text file in the computer. So when we execute data_vrt inside algorithm directly without using double quotes on both sides, program will work perfectly.

But, if we copy this list of tif files and assign into a variable x as given above, then we must use double quotes on both sides of the list of tif files.

This solves the issue perfectly. Thank You.

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