0

Disclaimer: I've already found this link Convert PNG to GeoTiff using GDAL - but it was of no help.

Actually I've got a .png file of a hand-drawn map (I also got it in the .svg format in case this may help). I currently know the exact boundings of this file:

   {
     ne: { lat: 48.506161, lng: -1.714582 },
     sw: { lat: 48.477861, lng: -1.742703 }
   }

It's located in the north of France.

So here's the command I tried so far with gdal_translate:

 gdal_translate -of GTiff -a_srs '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
 -a_ullr 48.506161 -1.714582 48.477861 -1.742703 myfile.png output.tif

My final goal is to serve this file under a tiles system (x/y/z.png) for Leaflet or OpenLayers. So I used gdal2tiles to convert the output.tif file:

sudo gdal2tiles.py -p mercator output.tif  result/

But my problem is that the generated tiles are geolocated in the north of Madagascar instead of France. Any clue on this?

  • 1
    your axes are the wrong way round - try to change the -a_srs to epsg:4326 – Ian Turton Apr 5 at 14:35
  • Thank you for helping me, Ian! If the new command you proposed is : gdal_translate -of GTiff -a_srs EPSG:4326 -a_ullr 48.506161 -1.714582 48.477861 -1.742703 myfile.png output.tif, then I got exactly the same result - or is there anything else I must do? – F3L1X79 Apr 5 at 14:45
  • 1
    I'd try dal_translate -of GTiff -a_srs EPSG:4326 -a_ullr -1.714582 48.506161 -1.742703 48.477861 myfile.png output.tif – Ian Turton Apr 5 at 14:55
  • Amazing, thank you so much. Too bad, I was so close for the good result... Do you think I should delete the question? – F3L1X79 Apr 5 at 15:01
  • 1
    This time the source data is explicit and defines the meaning of coordinates ne: { lat: 48.506161, lng: -1.714582 } but user should also know that GDAL is always taking coordinates in order longitude-latitude or easting-northing. – user30184 Apr 5 at 16:57
4

The fact that your map appears at Madagascar and not France is the clue here. It means that your axes are swapped (Madagascar is about as far south as France is West). So you need to switch round the order of the coordinates in your bounding box (and I would use the shorter EPSG:4326 instead of the proj4 string).

So your command becomes

gdal_translate -of GTiff -a_srs EPSG:4326 -a_ullr -1.714582 48.506161 -1.742703 48.477861 myfile.png output.tif

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.