5

I am trying to geo-reference an image using gdal_translate in a command prompt. Currently I have the following

gdal_translate.exe -of GTiff -a_nodata 0 --config GDAL_DATA "Config location" -a_ullr -77.057275 38.872024 -77.054672 38.869986 -a_srs EPSG:3857 "Input.tif" "Output.tif"

Where the config location is the location of the gdal data files.

The issue I am having is when I open the image it has lost its aspect ratio. I believe it has something to do with the projection but I am unsure.

gdalinfo.exe gives the following info.

Driver: GTiff/GeoTIFF
Files: Output.tif
Size is 1950, 1950
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs"],
    AUTHORITY["EPSG","3857"]]
Origin = (-77.057275000000004,38.872024000000003)
Pixel Size = (0.000001334871795,-0.000001045128205)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_SOFTWARE=TwelveMonkeys ImageIO TIFF writer DEV
  TIFFTAG_XRESOLUTION=72
  TIFFTAG_YRESOLUTION=72
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( -77.0572750,  38.8720240) (  0d 0' 2.49"W,  0d 0' 1.26"N)
Lower Left  ( -77.0572750,  38.8699860) (  0d 0' 2.49"W,  0d 0' 1.26"N)
Upper Right ( -77.0546720,  38.8720240) (  0d 0' 2.49"W,  0d 0' 1.26"N)
Lower Right ( -77.0546720,  38.8699860) (  0d 0' 2.49"W,  0d 0' 1.26"N)
Center      ( -77.0559735,  38.8710050) (  0d 0' 2.49"W,  0d 0' 1.26"N)
Band 1 Block=1950x1 Type=Byte, ColorInterp=Red
  NoData Value=0
Band 2 Block=1950x1 Type=Byte, ColorInterp=Green
  NoData Value=0
Band 3 Block=1950x1 Type=Byte, ColorInterp=Blue
  NoData Value=0
  • 1
    The corner coordinates for u_llr must be in the coordinate system used by the image, not longitude/latitudes. – mdsumner Dec 23 '15 at 4:19
  • Is the Random Project GeoReferenced.tif the input or output of what you are trying to do? I assume output, in which case you should look at the Corner Coordinates part and note the difference between the first part and second part of each corner. – BradHards Dec 23 '15 at 4:45
  • @mdsumner The image is taken from google maps. I have the TL and BR coordinates from google maps and I would like to use this to get a rough coordinate system on the image to align it to an area. If I have gone about this the wrong way, is there a better option? – Ando Dec 23 '15 at 6:06
  • @BradHards I have looked at the corner coordinates as you suggested but I am unsure what it is that I am meant to be looking for. – Ando Dec 23 '15 at 6:07
  • 1
    As pointed out by mdsumner, you've mixed up projected coordinates (the first number pair in Corner Coordinates) and longitude/latitude (the second number pair in Corner Coordinates). Surely 0d 0' 2.49"W, 0d 0' 1.26"N isn't the top left you wanted... – BradHards Dec 23 '15 at 6:27
4

As already pointed out in the comments, the -a_ullr parameters have to be in Google mercator projection.

So put your two coordinate pairs into a text file named wgs84.txt, and create a batch file with this content:

cs2cs +init=epsg:4326 +to +init=epsg:3857 -f "%%.2f" <wgs.txt >merc.txt

Run that batch inside the OSGeo4W shell (or Linux terminal), and you will get:

-8577976.61 4703356.65 0.00
-8577686.85 4703065.26 0.00

The third column is the height above ellipsoid, you don't need that here. Put the first two values into your gdal_translate command line, and you should get the correct georeferencing:

gdal_translate -of GTiff -a_nodata 0 -a_ullr -8577977 4703357 -8577687 4703065 -a_srs EPSG:3857 Input.tif Output.tif

If you are running the command inside the OSGeo4W shell, no config location is needed. You might have to add the full path to your source and destination file in quotes, or move to the folder with cd. Running on Linux might need different handling on that.

  • Thanks for getting back to me, I am working through some issues with cs2cs arm but will try it as soon as that is fixed. I know it is probably frustrating but can you please give the example command for gdal_translate. I am a little confused still :/ – Ando Dec 24 '15 at 22:11
  • You guys are amazing. Seems to of done the trick. Thanks!! – Ando Dec 25 '15 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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