""" Servicio /GMS/raster/warp que devuelve el cambio de sistema geodesico de un raster """ import os from ...tools.gdal_python import GdalOptions, gdal_command_progress from monitorT.task import Task from django.conf import settings class TaskCustom(Task): """ clase interna itasker """ CONTROL = False def post(task, user=None, t_srs=None, input=None, output=None, parameters=None): """ Change geodesic reference system of a raster Parameters ---------- user: str User id t_srs: str Geodesic reference system input: str Path to tiff input output: str Path to tiff output parameters: str Command line string options. Go to https://gdal.org/programs/gdalwarp.html to get all the options. Excluded -t_srs. Returns ------- output: str Path to output tiff Examples -------- >>> import requests >>> import json >>> # Default values -of GTiff -co COMPRESS=LZW -co BIGTIFF=YES -co PREDICTOR=2 -co TILED=YES -srcnodata 0 >>> data = {'user':'test', ... 'grs':'WGS84', ... 'input': '/media/almacenamiento_a/almacenamiento_repositorio/Varios/vrt/prueba/S2A_MSIL2A_20181004T110911_N0208_R137_T30STG_20181004T120303.tiff', ... 'output': '/media/almacenamiento_a/almacenamiento_repositorio/Varios/vrt/prueba/S2A_MSIL2A_20181004T110911_N0208_R137_T30STG_20181004T120303_changed.tiff'} >>> response = requests.post(url='http:///GMS/raster/warp', json=data) '/media/almacenamiento_a/almacenamiento_repositorio/Varios/vrt/prueba/S2A_MSIL2A_20181004T110911_N0208_R137_T30STG_20181004T120303_changed.tiff' """ DEFAULT_PARAMS = "-of GTiff -co COMPRESS=LZW -co BIGTIFF=YES -co PREDICTOR=2 -co TILED=YES -srcnodata 0" ################################################### # Allow different users repositories # ################################################### # user_data = get_user_data(user) # # user_repo = user_data['repo'] # # if 'repo' in user_data.keys(): # # user_repo = user_data['repo'] # # data_base = StaticBase.load(user_repo) # # else: # # data_base = settings.STATIC_DATABASE[base] # ################################################### options = GdalOptions.parse_parameters(parameters, DEFAULT_PARAMS) if os.path.exists(output): os.remove(output) command = "gdalwarp {} -t_srs {} {} {}".format(options.export_params(), t_srs, input, output) popen = gdal_command_progress(command, task) if popen.returncode: if settings.DEBUG: raise Exception(os.strerror(popen.returncode)) else: output = {"error": os.strerror(popen.returncode)} return output