I set up an ubuntu 18.04 EC2 through AWS that "On Start" will run a python script in which will download a .tif
from an s3 bucket and project it from EPSG:4326
to EPSG:3857
using gdal.Warp()
. The method to execute the script on start was used from this question/solution. I am also using an anaconda3 env to host the script and desired packages. GDAL was installed with conda install -c conda-forge gdal=3.0.2
.
onStartUp.service
[Unit]
Description=Some kind of description
[Service]
Type=simple
ExecStart=/home/ubuntu/anaconda3/envs/myEnv/bin/python3.8 /home/ubuntu/run.py
[Install]
WantedBy=multi-user.target
I can successfully project with the code below both through my local machine and with the EC2 if executed with python myScript.py
, however when used in conjunction with the "On Start" method, I receive an error.
I found that this is due to the GDAL_DATA
environment variable being not properly set for a server use case. I am not entirely sure how to set this variable, weather I need to set it in the main script or in the command terminal. I found this solution, and this solution, but they were unsuccessful.
from osgeo import gdal
def reproject(output_raster, filename):
input_raster = gdal.Open(filename)
warp_options = gdal.WarpOptions(creationOptions = ['COMPRESS=DEFLATE', 'PREDICTOR=2', 'ZLEVEL=9'], srcSRS='EPSG:4326', dstSRS='EPSG:3857', resampleAlg='near', format='GTiff')
warp = gdal.Warp(output_raster, input_raster, options=warp_options)
warp = None
warp = gdal.Warp(output_raster, input_raster, options=warp_options)
File "/home/ubuntu/anaconda3/envs/myEnv/lib/python3.8/site-packages/osgeo/gdal.py", line 625, in Warp
return wrapper_GDALWarpDestName(destNameOrDestDS, srcDSTab, opts, callback, callback_data)
File "/home/ubuntu/anaconda3/envs/myEnv/lib/python3.8/site-packages/osgeo/gdal.py", line 3410, in wrapper_GDALWarpDestName
return _gdal.wrapper_GDALWarpDestName(*args)
TypeError: in method 'wrapper_GDALWarpDestName', argument 4 of type 'GDALWarpAppOptions *'
Updates
I was able to find some more information running journalctl -xe
ERROR 1: PROJ: proj_create_from_database: Open of /home/ubuntu/anaconda3/envs/myEnv/share/proj failed
ERROR 1: Translating source or target SRS failed:
EPSG:4326
PROJ_LIB=/home/ubuntu/anaconda3/envs/myEnv/share/proj
. Also try upgrading your gdal to a different (later) version