Tutorial to get georeferenced images and read coordinates
The gps maps are displayed via latitutinal and longitudinal coordinates and therefore need to be very accurate. We need a way to get images with good resolution that also contain gps coordinates.
We want to obtain a .tif
image that will contain metadata representing the gps coordinates of the map
QGIS is one of the applications that you can use to get satellite images and use them to save the gps coordinates that we need.
The application is available for many operating systems, and download instructions are available at the following link.
-
Open QGIS
-
Create a new project via
Project->New
-
Install plugins from
Plugins->Manage and Install Plugins...
-
Download more maps
-
Select Google Satellite map
-
Search
Raster tools
inProcessing Toolbox
. Click here to see the documentation- Select the area of the image you want to create
-
Select the map units per pixels (the lower the value, the better quality the image will have)
- Be careful, if the image area is large and the value of map units per pixels is too small, the algorithm will take longer to return an image
-
Save to file or save a temporary file on QGIS (the output image will be a .tif file)
- If you want to save the image to a temporary file to get a preview, it will be added as a layer and then you will have to export it by right-clicking and going to
Export->Save As
- If you want to save the image to a temporary file to get a preview, it will be added as a layer and then you will have to export it by right-clicking and going to
There may be some problems with the image created:
- Area of the image different from the one selected:
- you can try creating the image again by changing the value of
Tile size
- many times this error is given because the selected area is smaller than the
Tile size
so you have to decrease that value as well
- you can try creating the image again by changing the value of
- Poor image quality:
- you can try creating the image one more time by changing the
map units per pixel
value
- you can try creating the image one more time by changing the
If you need it, you can create a .jpg
file of the image. To do this we can use any application that allows us to export images to .jpg
files
If the image quality is still not good enough, you can try increasing the image resolution using other applications such as Photoshop.
Be careful when modifying the .tif
file because it may lose metadata
Now that we have obtained both the .tif
file we can go ahead and get the gps coordinates saved in the .tif
file
The first step is to install the dependencies via the command:
pip install -r requirements.txt
Now all that remains is to execute the script via the command:
python3 read_coordinates.py <raster_file_path>
Warning
raster_file_path
must be the .tif
file created before with the georeferencing metadata.
The result of the script is something like this:
corner: (longitude, latitude)
Upper Left: (10.013347232876077, 44.684102509035036)
Lower Left: (10.013347232876077, 44.67756187921092)
Upper Right: (10.031744729894845, 44.684102509035036)
Lower Right: (10.031744729894845, 44.67756187921092)
Center: (10.022545981385461, 44.68083228642004)
Warning
The coordinates are given in a (longitude, latitude)
format