[Solved] Adding Z (elevation to image when georeferencing with gdal_translate and gdalwarp via gcps)

Hassan Asks: Adding Z (elevation to image when georeferencing with gdal_translate and gdalwarp via gcps)
I have been trying to georeference an image with given gcps (X-Y coordinates and Z (elevation) coordinates). However, when I add gcps via gdal_translate it adds elevation Z but as soon as I use gdalwarp, the elevation disappears and I only get a X-Y referenced image. But I also need elevation in the image. Here is my code and the image that I am using.

Code:
import gdal
gdal_translate -of GTiff -gcp 0 0 15329.29997 21690.27067 5412.112601 -gcp 0 724 15330.29997 21690.27067 5412.112601 -gcp 1904 0 15329.29997 21689.27067 5412.112601 -gcp 1904 724  15330.29997 21689.27067 5412.112601 test.tif out-with-gcpXYZ.tif
gdalinfo "out-with-gcpXYZ.tif"
#then
gdalwarp out-with-gcpXYZ.tif test0Z.tif
gdalinfo "test0Z.tif" #it lags the elevation (Z)

Any help would be appreciated!

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.