I would like to georeference an image with GDAL. The image already has a spatial reference set (EPSG:31276). For the georeferencing, I have a list of 4 ground control points (also in EPSG:31276).
Using the QGIS Georeferencer Plugin, I can correctly georeference the image. I then select "Generate GDAL Script", which results in the following GDAL commands:
gdal_translate -of GTiff -gcp 6.55253e+06 -5.07402e+06 6.55273e+06 5.07395e+06 -gcp 6.55246e+06 -5.0711e+06 6.55263e+06 5.07106e+06 -gcp 6.55477e+06 -5.07382e+06 6.55511e+06 5.07368e+06 -gcp 6.55483e+06 -5.07197e+06 6.55525e+06 5.07197e+06 "C:/gis_sample_data/sample_image/image1.tif" "C:/Users/XYZ/AppData/Local/Temp/image1.tif"
gdalwarp -r near -order 1 -co COMPRESS=NONE "C:/Users/XYZ/AppData/Local/Temp/image1.tif" "C:/gis_sample_data/sample_image/image1_georef.tif"
Those commands run without an error, but the resulting image is not correctly projected. Here is a small part from gdalinfo "C:/gis_sample_data/sample_image/image1.tif"
(the original image):
Corner Coordinates:
Upper Left ( 6551897.000, 5074277.000) ( 18d40' 4.21"E, 45d48'39.73"N)
whereas gdalinfo "C:/gis_sample_data/sample_image/image1_georef.tif"
(result from the GDAL call) shows
Corner Coordinates:
Upper Left ( -534350.794, 156938.268) ( 34d51'24.74"W, 0d52'47.63"N)
How would I have to modify the GDAL commands to correctly georeference the image?
The sample image is part of the Baranja Hill data set, which can be downloaded from here. The ground control points are those:
mapX,mapY,pixelX,pixelY,enable
6552733.64613180514425039,5073946.04477077350020409,6552533.84482758585363626,5074021.48275862075388432,1
6552633.32449856773018837,5071059.01110315229743719,6552461.44827586226165295,5071104.32758620660752058,1
6555111.64040114637464285,5073678.52041547279804945,6554765.36206896603107452,5073821.32758620660752058,1
6555249.11819484271109104,5071965.62141833826899529,6554833.5,5071973.08620689623057842,1
When copied into a text editor and saved with the .points extension, they can be imported in the QGIS Georeference Plugin.
EDIT: Changed negative to positive values in gdal_translate
. Results of gdalinfo
:
Corner Coordinates:
Upper Left ( -591887.923, 223739.838) ( 35d 8'28.93"W, 1d14'58.74"N)
By the way, I also tried adding -t_srs EPSG:31276
, -s_srs EPSG:31276
and -a_srs EPSG:31276
and various combinations thereof to the gdal commands, but it didn't fix the problem.
Answer
The coordinates in your gdal_translate command should be all positive.
The GCP list is, so I think this could be a bug of the GDAL script creator.
EDIT
I could replicate your error, and think that your use case is not the intended use of GCP.
In "normal" georeferencing, the GCP points map pixel coordinates from an unreferenced picture to projected or geographical coordinates. The pixel coordinates are relative to the upper left corner.
In your use case, you take projected coordinates from a georeferenced tif, and compare them to "correct" coordinates. The coordinates on the left side are not relative to the upper left corner, but to the origin of the projection. If you start the reprojection process, this information will be distroyed and replaced by the GCP information. This does not seem to work.
In the GDAL batch file, you can add -of VRT
to get vrt instead of tif files. You can open those vrt in a text editor and see that the matching goes terribly wrong.
No comments:
Post a Comment