2

I have one .PNG basemap with known North edge of Latitude = 52.48, a South edge of Latitude = 21.94, an east edge of Longitude = -61.87 and a west edge of Longitude = -129.37.

And I have another PNG image overlay with a known North edge of Latitude = 50.03, a South edge of Latitude = 22.02, an east edge of Longitude = -67.24 and a west edge of Longitude = -124.99.

Is there a way using GDAL or other simple scripting tools to process the second PNG image to be in an output that directly overlays (same x/y dimensions) the basemap?

I have no trouble generating map tiles that overlay each other beautifully - but I seem to be having no luck figuring out the syntax of the seemingly simpler case.

Help in the form of a simple example is much appreciated!

To be clear: the goal is an output .png file that has the exact same x/y dimensions as the basemap, and which can directly overlay on top of it.

radven
  • 240
  • 2
  • 9

1 Answers1

1

EDITED after feedback from question poster.

Step 1: if files are not georeferenced, try the methods described here, Georeferencing using GDAL?. Also world files could work for weither png or tif (http://en.wikipedia.org/wiki/World_file; http://www.gdal.org/gdal_translate.html).

Step 2: two methods could work for the clipping. Trying gdaltranslate with the following option -projwin ulx uly lrx lry: would work if you have the coordinates as the question seems to imply.

OR, you have the option of using gdaltindex newclip.shp basemap.png to create a clip shapefile. The shapefile can be used in the following way

gdalwarp -cutline /path/to/newclip.shp -crop-to-cutline oldimage.tif newimage.tif

remember that the path I show is for linux. Windows would be C:\something\clip.shp. Also, the example does not account for CRS. There is the option of replacing the cutline with -te xmin ymin xmax ymax

helpful link: http://www.gdal.org/gdalwarp.html

hope this helps :)

s_a
  • 951
  • 6
  • 10
  • Perhaps the part I am missing is that all I have is a plain .png file and the edge coordinates - the file is not a TIF with this information embedded, and gdalwarp doesn't know where to begin. – radven Oct 04 '12 at 23:32
  • So you need to georeference the file as well? hmmm I'll get back to you. – s_a Oct 04 '12 at 23:44
  • I think I am georeferencing the maps fine now, and turning them into GTiff's. But... I am not sure I am any closer to the goal of getting an output .png that has the same x/y dimensions as the basemap, and can directly overlay. – radven Oct 05 '12 at 01:04
  • I was using the -te option, but now that I have converted the basemap into a GTiff (and confirmed the details via gdalinfo) I have tried the -crop_to_cutline option you described, and it fails without output or error: gdalwarp -cutline ./output43264.tif -crop_to_cutline output4.tif outputN.tif – radven Oct 05 '12 at 01:35
  • Hi radven, I hope my newest edits are helpful. GOod luck. any questions? just ask :) – s_a Oct 05 '12 at 12:18
  • Your guidance got me on the right track, and everything is working now. Thanks!!! – radven Oct 06 '12 at 03:38
  • I didn't realize I was going to learn something when I first tried to answer your question :) Thanks, and I am glad it works now. – s_a Oct 08 '12 at 20:11