I have been trying to georeference an image I downloaded from Google API. Here is how I approached it after many unsuccessful attempts:

  1. I calculated the coordinates of the corners using this code.
  2. I added the transforms using the bounds coordinates and the CRS value. I used the CRS value suggested in this post for Google Maps images.
    def georefrence(input_path, output_path):
        dataset = rasterio.open(input_path)
        bands = [1]
        data = dataset.read(bands)
        transform = rasterio.transform.from_bounds(xmax, ymax,xmin, ymin, data.shape[1], data.shape[2])
        crs = rasterio.crs.CRS({"init": "epsg:3857"})
        with rasterio.open(output_path, 'w', driver='GTiff',
                    width=data.shape[1], height=data.shape[2],
                    count=3, dtype=data.dtype, nodata=0,
                    transform=transform, crs=crs) as dst:
      dst.write(data, indexes=bands)
  1. When I load the image in QGIS, I see pick a coordinate, copy it, and paste it in Google map. It doesn't map to the exact location but is pretty close; however, when I try to display it in OSM layer map, it appears in way off.

Is this a projection issue or something else and how can I resolve this?


So here is a sample image that I georeferenced https://drive.google.com/file/d/1GVgHrv6AJ28X8GSsF9sSaIVQcjldBsSR/view?usp=sharing

I figured that when I add the GeoTIFF version as a raster layer to QGIS on the OSM base map, it shows in the exact opposite location up (see the image below). enter image description here

How can I mirror this? Is it the projection or something else?


Another thing that I noticed is that when I paste these coordinates 30.0768254,31.6577946 in Google Maps, it points out the correct location, but when I paste it into Google Maps base map in QGIS, I go to the Atlantic Ocean.

Worth to note that I have already sat the CRS to EPSG: 3857 for the base map also (the same CRS of the image)

  • 3
    Which google API did you download the image from? Did you check whether the file already is georeferenced (using gdalinfo)?
    – nmtoken
    Commented Aug 5, 2022 at 10:40
  • @nmtoken it is not georefrenced just a png image. We are getting it from Google static API. Will include an example
    – salRad
    Commented Aug 5, 2022 at 12:49
  • @nmtoken Any ideas? Thanks
    – salRad
    Commented Aug 6, 2022 at 14:05

1 Answer 1


The answer below helped figure it out Lat/Long co-ordinates are not plotting onto EPSG:3857 OSM basemap correctly

I realized that the lat and long were mixed up, and after a few inspections, it turned out that I made a big mistake in putting the bounds in the right order in this line

transform = rasterio.transform.from_bounds(...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.