1

Other Tiles question

I copied the code and tried to run it, it runs the for loop the cmd says "100.. done" but there aren't any files in the set directory. Could be there any problem with the permission? If yes, how can I elevate a QGIS Python addon?

 def start_splitting_tiles(self):
    in_path = self.dlg.currently_choosen.toPlainText()
    input_filename = in_path

    while (input_filename.find("/") != -1):
        input_filename = input_filename[input_filename.find('/') + 1:]

    print "input: "+input_filename

    out_path = self.dlg.outpath.toPlainText()

    #if(out_path.find('\\') != -1):
    #   out_path = out_path.replace("\\", "/")

    out_filename = 'tile_'
    print "output: "+out_path

    tile_size_x = 1500
    tile_size_y = 1500

    ds = gdal.Open(in_path)
    band = ds.GetRasterBand(1)
    xsize = band.XSize
    ysize = band.YSize

    for i in range(0, xsize, tile_size_x):
        for j in range(0, ysize, tile_size_y):
            com_string = "gdal_translate -of GTIFF -srcwin " + str(i) + ", " + str(j) + ", " + str(
                tile_size_x) + ", " + str(tile_size_y) + " " + str(in_path) + " " + str(
                out_path) + str(out_filename) + str(i) + "_" + str(j) + ".tif"
            os.system(com_string)
            #os.system(input())
nmtoken
  • 13,355
  • 5
  • 38
  • 87
Jaspo
  • 21
  • 2
  • 1
    Can you give an example of what is printed when you use print "input: "+input_filename? – Joseph May 10 '17 at 10:00
  • @Joseph for example the path is: "C:/Users/Jaspo/Desktop/test/NL330302_01_Schum.tif" and the while loop just cuts the string until the filename is left input: NL330302_01_Schum.tif – Jaspo May 10 '17 at 10:03
  • And what is in_path? Is that the full path to the file or only to the directory? – Joseph May 10 '17 at 10:07
  • Yes it's the full path to the directory, the while loop was to separate the full path and the filename but it got useless and I didn't deleted it yet – Jaspo May 10 '17 at 10:13
  • Print the "com_string" of the first tile for us and test if it works for you from GDAL command window. – user30184 May 10 '17 at 10:14
  • I found the mistake print gdal_translate -of GTIFF -srcwin 0, 0, 1500, 1500 C:/Users/Jaspo/Desktop/test/NL330301_01_Schum.tif C:\Users\Jaspo\Desktop\Diplom\testzieldesttile_0_0.tif there was a missing "/" so he saved all the tiles into a wrong destination – Jaspo May 10 '17 at 10:23
  • I have one more Question, at the moment my program cuts the file according to a defined tilesize (in pixel), do you guys know how i can set the tilesize in km ? – Jaspo May 10 '17 at 10:30
  • You must know how to calculate how many pixels you will need for a km if pixel size is 1 m. With minor edits you can solve any tilesize with any pixel size. – user30184 May 10 '17 at 10:39

0 Answers0