I am currently trying to generate XYZ Tiles with Python from a .tif file. I tried using the QGIS GUI and after some time the tiles were generating correctly. After that I saw on another link, that I could see the processing command in the Processing History in the GUI. My folder output in the GUI is the following:
The corresponding history command in the GUI is:
processing.run("qgis:tilesxyzdirectory", {'EXTENT':'-443.962200000,456.037800000,-4759.144700000,-3659.144700000 []','ZOOM_MIN':11,'ZOOM_MAX':11,'DPI':96,'BACKGROUND_COLOR':QColor(0, 0, 0, 0),'TILE_FORMAT':0,'QUALITY':75,'METATILESIZE':4,'TILE_WIDTH':256,'TILE_HEIGHT':256,'TMS_CONVENTION':False,'OUTPUT_DIRECTORY':'C:\\Users\\xxx\\Documents\\FP\\QGIS EPSG','OUTPUT_HTML':'TEMPORARY_OUTPUT'})
After that I tried to reproduce the same output in python. The code itself runs without errors but the folder structure is complete different and it contains many negative Y folder and the code itself doesnt really stop. The folder output generated from the python script is the following:
My python script for the tiles is:
import requests
import numpy as np
import wradlib as wrl
import sys
import matplotlib.pyplot as pl
import os
from qgis.core import *
QgsApplication.setPrefixPath('C:\\OSGeo4W\\apps\\qgis\\', True)
qgs = QgsApplication([], False)
qgs.initQgis()
import processing
from processing.core.Processing import Processing
Processing.initialize()
path_to_tif = "geotiff30101055.tiff"
rlayer = QgsRasterLayer(path_to_tif, "Standard raster layer")
QgsProject.instance().addMapLayer(rlayer, False)
processing.run("qgis:tilesxyzdirectory", {
'EXTENT': '-443.962200000,456.037800000,-4759.144700000,-3659.144700000 []',
'ZOOM_MIN': 11, 'ZOOM_MAX': 11, 'DPI': 100,
'TILE_FORMAT': 0,
'QUALITY': 75,
'METATILESIZE': 4,
'TILE_WIDTH': 256,
'TILE_HEIGHT': 256,
'TMS_CONVENTION': False,
'OUTPUT_DIRECTORY': 'C:\\Users\\xxx\\Documents\\FP\\First', 'OUTPUT_HTML': 'TEMPORARY_OUTPUT'
})
1 Answer 1
In the GUI you did not define a tiling scheme (CRS) and in your script you defined a projection.
I tried the same and what happens is the algorithm assumes that without a defined tiling scheme that your coordinates are referring to EPSG:3857 (WGS 84 / Pseudo-Mercator (web mercator)).
If you want to publish your tiles somewhere public you may want to set your project to EPSG:3857 and select the extent with the GUI first to make sure you have the correct location.
processing.run("qgis:tilesxyzdirectory",
{'EXTENT':'-443.962200000,456.037800000,
-4759.144700000,-3659.144700000 []', # No Defined tiling scheme or CRS
'ZOOM_MIN':11,
'ZOOM_MAX':11,
'DPI':96,
'BACKGROUND_COLOR':QColor(0, 0, 0, 0),
'TILE_FORMAT':0,
'QUALITY':75,
'METATILESIZE':4,
'TILE_WIDTH':256,
'TILE_HEIGHT':256,
'TMS_CONVENTION':False,
'OUTPUT_DIRECTORY':'C:\\Users\\xxx\\Documents\\FP\\QGIS EPSG',
'OUTPUT_HTML':'TEMPORARY_OUTPUT'})
processing.run("qgis:tilesxyzdirectory", {
'EXTENT': '-443.962200000,456.037800000,
-4759.144700000,-3659.144700000 [Radolan Projection]', # Defined Radolan Projection
'ZOOM_MIN': 11, 'ZOOM_MAX': 11, 'DPI': 100,
'TILE_FORMAT': 0,
'QUALITY': 75,
'METATILESIZE': 4,
'TILE_WIDTH': 256,
'TILE_HEIGHT': 256,
'TMS_CONVENTION': False,
'OUTPUT_DIRECTORY': 'C:\\Users\\xxx\\Documents\\FP\\First', 'OUTPUT_HTML': 'TEMPORARY_OUTPUT'
})
-
My code snippet was not up to date. It was a test from my side to see if [Radolan Projection] would help me, but its the same problem when using [] instead (I edited my post). What I dont understand is why the QGIS GUI uses [] so according to your respons WGS84 but renders the correct tiles but the python code doesn`t do it like that. Thanks nonethelessNicolasT– NicolasT2020年11月01日 11:47:53 +00:00Commented Nov 1, 2020 at 11:47
-
1Then the only thing i can think of is that the python code does not recognize the
TMS_CONVENTION:False
parameter and it flips your Y coordinates.Dror Bogin– Dror Bogin2020年11月01日 11:51:04 +00:00Commented Nov 1, 2020 at 11:51 -
Should not be the problem according to the documentation docs.qgis.org/3.10/en/docs/user_manual/processing_algs/qgis/… where the default is falseNicolasT– NicolasT2020年11月01日 12:17:00 +00:00Commented Nov 1, 2020 at 12:17
Explore related questions
See similar questions with these tags.