I have some scan files with spatial information.
My Original Image
In the example image, the rectangular area drawn with the blue line is my area containing spatial information. In the four corners of the rectangle, there is information that gives the coordinate value of the corner it is in.
Top Left Of Raster
Top Right Of Raster
Bottom Left Of Raster
Bottom Right Of Raster
As you can see, the coordinates of the EPSG:2320 Coordinate System are written on all 4 corners.
I tried to make georeference at Python code below. But it gave me a very different result. In the program it is going to the real-world domain of the raster. However, it rotates and inverts the image even though I enter the position of the corners in the image and the coordinate information in the real world correctly.
My code:
""" PINDEX CORNER X,Y(IMAGE) AND EPSG:2320 COORDÄ°NATES
IN IMAGE | EPSG:2320
----------|----------------------
TOP LEFT: 796, 569 | 443893.7, 4420713.72
TOP RIGHT 5005, 598 | 444428.05,4420709.81
BOTTOM RIGHT 4965,6065 | 444423,4420015.85
BOTTOM LEFT 754, 6035 | 443888.6,4420019.76
"""
import rasterio as rio
from rasterio.transform import from_gcps
from rasterio.control import GroundControlPoint
file_path="ciktilar/"+i
tl = GroundControlPoint(796, 569, 443893.7, 4420713.72) #top left
bl = GroundControlPoint(5005, 598, 444428.05,4420709.81) #top right
br = GroundControlPoint(4965,6065, 444423,4420015.85) #bottom right
tr = GroundControlPoint(754, 6035, 443888.6,4420019.76) #bottom left
gcps = [tl, bl, br, tr]
transform = from_gcps(gcps)
crs = 'epsg:2320'
with rio.open(file_path, 'r+') as ds:
ds.crs = crs
ds.transform = transform
My Result GeoTIF
The result image was added to the GIS program and taken from the screen.
How do I do the correct Georeference?
Any ideas?
Best Answer
You have two alternatives:
gdal_translate -gcp 796 569 443893.7 4420713.72 -gcp 5005 598 444428.05 420709.81 -gcp 4965 6065 444423 4420015.85 -gpc 754 6035 443888.6 420019.76 input.tif with_gcp.tif
Then you can use gdalwarp
gdalwarp -t_srs epsg:2320 with_gcp.tif final.tif